├── .github
└── ISSUE_TEMPLATE
│ └── config.yml
├── .gitignore
├── .idea
└── icon.png
├── README.md
├── pom.xml
└── src
└── main
├── java
└── simbot
│ └── example
│ ├── SimbotExampleApplication.java
│ └── listener
│ ├── MyGroupListen.java
│ ├── MyNewGroupMemberListen.java
│ └── MyPrivateListen.java
└── resources
├── application.yml
└── simbot-bots
└── yourBot1.bot
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | contact_links:
2 | - name: Issue for simbot
3 | url: https://github.com/ForteScarlet/simpler-robot/issues/new/choose
4 | about: 我有疑问或需要反馈的问题
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff
7 | .idea/**/workspace.xml
8 | .idea/**/tasks.xml
9 | .idea/**/usage.statistics.xml
10 | .idea/**/dictionaries
11 | .idea/**/shelf
12 |
13 | # Generated files
14 | .idea/**/contentModel.xml
15 |
16 | # Sensitive or high-churn files
17 | .idea/**/dataSources/
18 | .idea/**/dataSources.ids
19 | .idea/**/dataSources.local.xml
20 | .idea/**/sqlDataSources.xml
21 | .idea/**/dynamic.xml
22 | .idea/**/uiDesigner.xml
23 | .idea/**/dbnavigator.xml
24 |
25 | # Gradle
26 | .idea/**/gradle.xml
27 | .idea/**/libraries
28 |
29 | # Gradle and Maven with auto-import
30 | # When using Gradle or Maven with auto-import, you should exclude module files,
31 | # since they will be recreated, and may cause churn. Uncomment if using
32 | # auto-import.
33 | # .idea/artifacts
34 | # .idea/compiler.xml
35 | # .idea/jarRepositories.xml
36 | # .idea/modules.xml
37 | # .idea/*.iml
38 | # .idea/modules
39 | # *.iml
40 | # *.ipr
41 |
42 | # CMake
43 | cmake-build-*/
44 |
45 | # Mongo Explorer plugin
46 | .idea/**/mongoSettings.xml
47 |
48 | # File-based project format
49 | *.iws
50 |
51 | # IntelliJ
52 | out/
53 |
54 | # mpeltonen/sbt-idea plugin
55 | .idea_modules/
56 |
57 | # JIRA plugin
58 | atlassian-ide-plugin.xml
59 |
60 | # Cursive Clojure plugin
61 | .idea/replstate.xml
62 |
63 | # Crashlytics plugin (for Android Studio and IntelliJ)
64 | com_crashlytics_export_strings.xml
65 | crashlytics.properties
66 | crashlytics-build.properties
67 | fabric.properties
68 |
69 | # Editor-based Rest Client
70 | .idea/httpRequests
71 |
72 | # Android studio 3.1+ serialized cache file
73 | .idea/caches/build_file_checksums.ser
74 |
75 | ### Maven template
76 | target/
77 | pom.xml.tag
78 | pom.xml.releaseBackup
79 | pom.xml.versionsBackup
80 | pom.xml.next
81 | release.properties
82 | dependency-reduced-pom.xml
83 | buildNumber.properties
84 | .mvn/timing.properties
85 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar
86 | .mvn/wrapper/maven-wrapper.jar
87 |
88 | ### Java template
89 | # Compiled class file
90 | *.class
91 |
92 | # Log file
93 | *.log
94 |
95 | # BlueJ files
96 | *.ctxt
97 |
98 | # Mobile Tools for Java (J2ME)
99 | .mtj.tmp/
100 |
101 | # Package Files #
102 | *.jar
103 | *.war
104 | *.nar
105 | *.ear
106 | *.zip
107 | *.tar.gz
108 | *.rar
109 |
110 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
111 | hs_err_pid*
112 |
113 |
--------------------------------------------------------------------------------
/.idea/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simple-robot/simbot-mirai-spring-boot-demo/b7b8fbf6e823fcdebe175e5e164a5a12dd38be10/.idea/icon.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simbot springboot starter demo - Mirai
2 |
3 | 这是[simple-robot](https://github.com/ForteScarlet/simpler-robot) 框架使用[mirai组件](https://github.com/ForteScarlet/simpler-robot/tree/dev/component/component-mirai) 对接[Mirai](https://github.com/mamoe/mirai) 并整合为 Spring Boot 的Demo项目。
4 |
5 | ## 需要做的
6 | ### fork/clone
7 | fork或者clone此项目到你的本地,并使用IDE工具打开并构建它。
8 |
9 | ### 修改配置文件
10 | 打开文件 [application.yml](src/main/resources/application.yml) 并修改其中的 `simbot.core.bots` 项为你测试用的QQ账号,例如:
11 | ```yaml
12 | simbot:
13 | core:
14 | bots: 123456789:password
15 | ```
16 |
17 | ### 保证安静
18 | 将你的bot放在一些测试用的群而不是一些大型群。
19 |
20 | ### 阅读
21 | - [listener](src/main/java/simbot/example/listener) 包下为一些监听函数示例。阅读它们的注释,并可以试着修改它们。
22 |
23 | ### 运行
24 | 执行[SimbotExampleApplication](src/main/java/simbot/example/SimbotExampleApplication.java) 中的main方法。
25 |
26 | ### 验证
27 | 如果你是第一次使用此框架,且出现了诸如需要“滑动验证”等相关错误,你可以尝试先使用一次 [simbot-mirai-login-solver-selenium-helperPack](https://github.com/simple-robot/simbot-mirai-login-solver-selenium-helperPack) 来使腾讯记住你的设备信息。
28 |
29 | 以及,记得关闭账号中与“设备锁”、“安全保护”等相关内容。
30 |
31 | ### 协助
32 | 如果你有一个好的示例点子,你可以通过[github pr](https://github.com/simple-robot/simbot-mirai-spring-boot-demo/pulls) 来协助此demo项目的更新。
33 |
34 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
51 | * {@link GroupAddRequest} 顾名思义,即 “群添加申请” 事件。 52 | *
53 | * 这个事件不仅仅代表别人加入某群,也有可能代表有人邀请当前bot入群。 54 | *
55 | * 当然了,如果是处理其他人的加群申请,那么这个bot必须是个管理员才能接收到请求事件。 56 | * 57 | * @param groupAddRequest 群添加申请/邀请事件。 58 | * @param setter 一般用来通过申请,使用的是Setter。当然,你也可以使用 {@link love.forte.simbot.api.sender.MsgSender#SETTER}, 它们所代表的是同一个对象。 59 | * @see GroupAddRequest 60 | */ 61 | @OnGroupAddRequest 62 | public void onRequest(GroupAddRequest groupAddRequest, Setter setter) { 63 | // 此事件的“申请者” 64 | AccountInfo accountInfo = groupAddRequest.getRequestAccountInfo(); 65 | // 收到此事件的bot 66 | BotInfo botInfo = groupAddRequest.getBotInfo(); 67 | 68 | // 如果上述两者的账号不相同,则说明此事件不是bot被邀请,而是别人申请入群。 69 | // 这步判断操作似乎很繁琐,未来版本可能会提供更简洁的方案 70 | // 如果你有好的点子,可以通过 github issue 或 github pr向simbot提出。 https://github.com/ForteScarlet/simpler-robot 71 | if (!accountInfo.getAccountCode().equals(botInfo.getBotCode())) { 72 | // 获取入群的时候的申请消息(如果有的话 73 | String text = groupAddRequest.getText(); 74 | if (text != null) { 75 | // 如果有,记录这一条信息。 76 | REQUEST_TEXT_MAP.put(accountInfo.getAccountCode(), text); 77 | } 78 | GroupInfo groupInfo = groupAddRequest.getGroupInfo(); 79 | 80 | LOGGER.info("{}({}) 申请加入群 {}({}), 申请备注:{}", 81 | accountInfo.getAccountNickname(), accountInfo.getAccountCode(), 82 | groupInfo.getGroupName(), groupInfo.getGroupCode(), 83 | text 84 | ); 85 | 86 | 87 | // 通过申请 88 | // 通过setter来通过加群申请有多个方法: 89 | // 方法1:acceptGroupAddRequest(flag) 90 | // flag 是请求事件的一个”标识“ 91 | setter.acceptGroupAddRequest(groupAddRequest.getFlag()); 92 | 93 | // 方法2:setGroupAddRequest(flag, agree, blockList, why) 94 | // 4个参数分别代表:标识、是否同意、是否加入黑名单(一般是只有在拒绝时生效, 但是mirai目前不支持此参数)、以及这么操作的原因(一般是在拒绝时生效, 可以为null) 95 | // setter.setGroupAddRequest(groupAddRequest.getFlag(), true, false, null); 96 | 97 | // 方法3:return Reply.accept() 98 | // 将方法返回值设置为 ReplyAble 或者 Reply, 然后直接返回 Reply.accept() 实例来快速同意申请。 99 | // 这种方法依靠的是响应值处理器。文档参考:https://www.yuque.com/simpler-robot/simpler-robot-doc/aioxhh 100 | 101 | // 方法4:鉴于目前 Flag 的设计仍然有一些风险和隐患,未来可能会提供其他更便捷的方式对相关事件进行处理。 102 | 103 | } 104 | 105 | } 106 | 107 | 108 | /** 109 | * 新人入群申请之后,便是 ”群成员增加“ 事件,如果你想要什么迎新操作,建议都在这个事件中处理。 110 | *
111 | * 通过 {@link OnGroupMemberIncrease} 监听群人数增加事件,这也是一个模板注解,其等效于 {@code @Listen(GroupMemberIncrease.class)} 112 | * 113 | * @param groupMemberIncrease 群人数增加事件实例 114 | * @param sender 既然是”迎新“示例,则当然要发消息。 115 | * @see GroupMemberIncrease 116 | */ 117 | @OnGroupMemberIncrease 118 | public void newGroupMember(GroupMemberIncrease groupMemberIncrease, Sender sender) { 119 | // 得到一个消息构建器。 120 | MessageContentBuilder builder = messageBuilderFactory.getMessageContentBuilder(); 121 | 122 | // 入群者信息 123 | AccountInfo accountInfo = groupMemberIncrease.getAccountInfo(); 124 | 125 | // 尝试从缓存中获取他入群的时候所记录的信息 126 | // 如果不希望看到null,则记得自行处理。 127 | String text = REQUEST_TEXT_MAP.remove(accountInfo.getAccountCode()); 128 | 129 | // 假设我们的迎新消息是这样的: 130 | /* 131 | @xxx 欢迎入群! 132 | 你的入群申请信息是:xxxxxx 133 | */ 134 | MessageContent msg = builder 135 | // at当事人 136 | .at(accountInfo) 137 | // tips 通过 \n 换行 138 | .text(" 欢迎入群!\n") 139 | .text("你的入群申请信息是:").text(text) 140 | .build(); 141 | 142 | // 增加了人的群信息 143 | GroupInfo groupInfo = groupMemberIncrease.getGroupInfo(); 144 | 145 | // 发送消息 146 | sender.sendGroupMsg(groupInfo, msg); 147 | } 148 | 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/simbot/example/listener/MyPrivateListen.java: -------------------------------------------------------------------------------- 1 | package simbot.example.listener; 2 | 3 | import catcode.CatCodeUtil; 4 | import love.forte.common.ioc.annotation.Beans; 5 | import love.forte.simbot.annotation.OnPrivate; 6 | import love.forte.simbot.api.message.MessageContent; 7 | import love.forte.simbot.api.message.MessageContentBuilder; 8 | import love.forte.simbot.api.message.MessageContentBuilderFactory; 9 | import love.forte.simbot.api.message.events.PrivateMsg; 10 | import love.forte.simbot.api.sender.Sender; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | /** 15 | * 私聊消息监听的示例类。 16 | * 所有需要被管理的类都需要标注 {@link Service} 注解。 17 | * 18 | * 由于当前是处于springboot环境下,因此强烈建议类上的注释使用: 19 | *