✨ 基于 OneBot 协议的 QQ机器人 快速开发框架 ✨
请访问 Maven Repo 查看最新版本,并替换 version 内的 latest version
<dependency>
<groupId>com.mikuac</groupId>
<artifactId>shiro</artifactId>
<version>latest version</version>
</dependency>
编写
application.yml
配置文件 高级自定义配置
server:
port: 5000
shiro:
# 反向 Websocket 连接地址,无需该配置字段可删除,将使用默认值 "/ws/shiro"
# ws-url: "/ws/shiro"
@Shiro
@Component
public class DemoPlugin {
// 符合 cmd 正则表达式的消息会被响应
@PrivateMessageHandler(cmd = "hi")
public void fun1(@NotNull Bot bot, @NotNull PrivateMessageEvent event, @NotNull Matcher matcher) {
// 构建消息
MsgUtils msgUtils = MsgUtils.builder().face(66).text("Hello, this is shiro demo.");
// 发送私聊消息
bot.sendPrivateMsg(event.getUserId(), msgUtils.build(), false);
}
// 如果 at 参数设定为 AtEnum.NEED 则只有 at 了机器人的消息会被响应
@GroupMessageHandler(at = AtEnum.NEED)
public void fun2(@NotNull GroupMessageEvent event) {
// 以注解方式调用可以根据自己的需要来为方法设定参数
// 例如群组消息可以传递 GroupMessageEvent event, Bot bot, Matcher matcher 多余的参数会被设定为 null
System.out.println(event.getMessage());
}
// 同时监听群组及私聊消息 并根据消息类型(私聊,群聊)回复
@MessageHandler
public void fun3(@NotNull Bot bot, @NotNull WholeMessageEvent event) {
bot.sendMsg(event, "hello", false);
}
}
编写
application.yml
配置文件 高级自定义配置
server:
port: 5000
shiro:
# 反向 Websocket 连接地址,无需该配置字段可删除,将使用默认值 "/ws/shiro"
# ws-url: "/ws/shiro"
# 注解方式无需在此定义插件
# 插件列表(顺序执行 如果前一个插件返回了 MESSAGE_BLOCK 将不会执行后续插件)
plugin-list:
- com.mikuac.example.plugins.ExamplePlugin
// 继承BotPlugin开始编写插件
@Component
public class ExamplePlugin extends BotPlugin {
@Override
public int onPrivateMessage(@NotNull Bot bot, @NotNull PrivateMessageEvent event) {
String msg = event.getMessage();
if ("hi".equals(msg)) {
// 构建消息
String sendMsg = MsgUtils.builder()
.face(66)
.text("Hello, this is shiro demo.")
.build();
// 发送私聊消息
bot.sendPrivateMsg(event.getUserId(), sendMsg, false);
}
// 返回 MESSAGE_IGNORE 插件向下执行,返回 MESSAGE_BLOCK 则不执行下一个插件
return MESSAGE_IGNORE;
}
@Override
public int onGroupMessage(@NotNull Bot bot, @NotNull GroupMessageEvent event) {
String msg = event.getMessage();
if ("hi".equals(msg)) {
// 构建消息
MsgUtils sendMsg = MsgUtils.builder()
.at(event.getUserId())
.face(66)
.text("Hello, this is shiro demo.");
// 发送群消息
bot.sendGroupMsg(event.getGroupId(), sendMsg.build(), false);
}
// 返回 MESSAGE_IGNORE 插件向下执行,返回 MESSAGE_BLOCK 则不执行下一个插件
return MESSAGE_IGNORE;
}
}
Shiro 以 OneBot-v11 标准协议进行开发,兼容所有支持反向WebSocket的OneBot协议客户端
项目地址 | 平台 | 核心作者 | 备注 |
---|---|---|---|
Yiwen-Chan/OneBot-YaYa | 先驱 | kanri | |
richardchien/coolq-http-api | CKYU | richardchien | 可在 Mirai 平台使用 mirai-native 加载 |
Mrs4s/go-cqhttp | MiraiGo | Mrs4s | |
yyuueexxiinngg/OneBot-Mirai | Mirai | yyuueexxiinngg | |
takayama-lily/onebot | OICQ | takayama |
This product is licensed under the GNU General Public License version 3. The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/gpl-3.0.html.
Alternatively, this product is licensed under the GNU Lesser General Public License version 3 for non-commercial use. The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/lgpl-3.0.html.
Feel free to contact us if you have any questions about licensing or want to use the library in a commercial closed source product.
Thanks JetBrains Provide Free License Support OpenSource Project