Estrutura de desenvolvimento rápido do robô QQ baseada no protocolo OneBot
Documentação · Baixar · Início rápido · Contribuir
A partir da versão
v2
apenasJDK 17+
eSpringBoot 3.0.0+
são suportados.Consulte o guia de migração da documentação do projeto v2 para obter detalhes.
Ao introduzir dependências, substitua a versão
latest
pela versão mais recente doMaven Central
< dependency >
< groupId >com.mikuac</ groupId >
< artifactId >shiro</ artifactId >
< version >latest</ version >
</ dependency >
implementation( " com.mikuac:shiro:latest " )
implementation ' com.mikuac:shiro:latest '
Escreva o arquivo de configuração
application.yaml
ou consulte o arquivo de configuração avançada
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
os plug-ins subsequentes não serão executados.Escreva o arquivo de configuração
application.yaml
ou consulte o arquivo de configuração avançada
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 é desenvolvido usando o protocolo padrão OneBot-v11 e é compatível com todos os clientes de protocolo OneBot que suportam WebSocket reverso.
projeto | descrever | Observação |
---|---|---|
LOneBot | Faça com que seu NTQQ suporte o protocolo OneBot11 para desenvolvimento de robô QQ | |
Lagrange.Core | Implementação do protocolo NTQQ | |
go-cqhttp | Implementação nativa do OneBot Golang baseada em Mirai e MiraiGo | Pare a manutenção |
OpenShamrock | Implementar a estrutura de robô padrão OneBot baseada em Xposed |
Veja Contribuindo para detalhes. Obrigado a todas as pessoas que já contribuíram!
Este produto está licenciado sob a Licença Pública Geral GNU versão 3. A licença é publicada pela Free Software Foundation publicada em https://www.gnu.org/licenses/gpl-3.0.html.
Alternativamente, este produto é licenciado sob a Licença Pública Geral Menor GNU versão 3 para uso não comercial. A licença é publicada pela Free Software Foundation publicada em https://www.gnu.org/licenses/lgpl-3.0.html. .
Sinta-se à vontade para entrar em contato conosco se tiver alguma dúvida sobre licenciamento ou quiser usar a biblioteca em um produto comercial de código fechado.
JetBrains oferece licenças gratuitas para apoiar projetos de código aberto.