基於OneBot 協議的QQ機器人快速開發框架
文檔· 下載· 快速開始· 參與貢獻
從
v2
版本開始僅支持JDK 17+
與SpringBoot 3.0.0+
詳見項目文檔v2遷移指南
引入依賴時請替換版本
latest
為Maven Central
實際的最新版本
< dependency >
< groupId >com.mikuac groupId >
< artifactId >shiro artifactId >
< version >latest version >
dependency >
implementation( " com.mikuac:shiro:latest " )
implementation ' com.mikuac:shiro:latest '
編寫
application.yaml
配置文件或參考進階配置文件
server :
port : 5000
@ Shiro
@ Component
public class ExamplePlugin {
// 更多用法详见 @MessageHandlerFilter 注解源码
// 当机器人收到的私聊消息消息符合 cmd 值 "hi" 时,这个方法会被调用。
@ PrivateMessageHandler
@ MessageHandlerFilter ( cmd = "hi" )
public void fun1 ( Bot bot , PrivateMessageEvent event , Matcher matcher ) {
// 构建消息
String sendMsg = MsgUtils . builder (). face ( 66 ). text ( "Hello, this is shiro demo." ). build ();
// 发送私聊消息
bot . sendPrivateMsg ( event . getUserId (), sendMsg , false );
}
// 如果 at 参数设定为 AtEnum.NEED 则只有 at 了机器人的消息会被响应
@ GroupMessageHandler
@ MessageHandlerFilter ( at = AtEnum . NEED )
public void fun2 ( GroupMessageEvent event ) {
// 以注解方式调用可以根据自己的需要来为方法设定参数
// 例如群组消息可以传递 GroupMessageEvent, Bot, Matcher 多余的参数会被设定为 null
System . out . println ( event . getMessage ());
}
// 同时监听群组及私聊消息 并根据消息类型(私聊,群聊)回复
@ AnyMessageHandler
@ MessageHandlerFilter ( cmd = "say hello" )
public void fun3 ( Bot bot , AnyMessageEvent event ) {
bot . sendMsg ( event , "hello" , false );
}
}
plugin-list
定義resources/application.yaml
追加如下內容MESSAGE_BLOCK
將不會執行後續插件編寫
application.yaml
配置文件或參考進階配置文件
server :
port : 5000
shiro :
plugin-list :
- com.example.bot.plugins.ExamplePlugin
@ Component
public class ExamplePlugin extends BotPlugin {
@ Override
public int onPrivateMessage ( Bot bot , PrivateMessageEvent event ) {
if ( "hi" . equals ( event . getMessage ())) {
// 构建消息
String sendMsg = MsgUtils . builder ()
. face ( 66 )
. text ( "hello, this is shiro example plugin." )
. build ();
// 发送私聊消息
bot . sendPrivateMsg ( event . getUserId (), sendMsg , false );
}
// 返回 MESSAGE_IGNORE 执行 plugin-list 下一个插件,返回 MESSAGE_BLOCK 则不执行下一个插件
return MESSAGE_IGNORE ;
}
@ Override
public int onGroupMessage ( Bot bot , GroupMessageEvent event ) {
if ( "hi" . equals ( event . getMessage ())) {
// 构建消息
String sendMsg = MsgUtils . builder ()
. at ( event . getUserId ())
. face ( 66 )
. text ( "hello, this is shiro example plugin." )
. build ();
// 发送群消息
bot . sendGroupMsg ( event . getGroupId (), sendMsg , false );
}
// 返回 MESSAGE_IGNORE 执行 plugin-list 下一个插件,返回 MESSAGE_BLOCK 则不执行下一个插件
return MESSAGE_IGNORE ;
}
}
Shiro 以OneBot-v11 標準協議進行開發,兼容所有支持反向WebSocket的OneBot協議客戶端
專案 | 描述 | 備註 |
---|---|---|
LLOneBot | 使你的NTQQ 支持OneBot11 協議進行QQ 機器人開發 | |
Lagrange.Core | NTQQ 的協議實現 | |
go-cqhttp | 基於Mirai 以及MiraiGo 的OneBot Golang 原生實現 | 停止維護 |
OpenShamrock | 基於Xposed 實現OneBot 標準的機器人框架 |
See Contributing for details. Thanks to all the people who already contributed!
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.
JetBrains offers free licenses to support open source projects.