github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/README.md (about) 1 <div align="center"> 2 <img src=".github/nano.jpeg" alt="东云名乃" width = "256"> 3 <br> 4 5 <h1>NanoBot</h1> 6 类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用<br><br> 7 8 <img src="https://counter.seku.su/cmoe?name=NanoBot&theme=r34" /><br> 9 10 </div> 11 12 ## Instructions 13 14 > Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction. 15 16 参见 QQ 官方[文档](https://bot.q.qq.com/wiki/)。 17 18 ## 快速开始(基于插件) 19 > 查看`example`文件夹以获取更多信息 20 21 <table> 22 <tr> 23 <td align="center"><img src="https://github.com/fumiama/NanoBot/assets/41315874/6ef9fd95-ae99-449e-85e1-25797271e088"></td> 24 <td align="center"><img src="https://github.com/fumiama/NanoBot/assets/41315874/edd374e4-b8a5-4cff-a463-8c3b30e537c4"></td> 25 <td align="center"><img src="https://github.com/fumiama/NanoBot/assets/41315874/ed1b063f-44b0-4950-ac35-1e72745cf3f4"></td> 26 </tr> 27 <tr> 28 <td align="center">开始响应</td> 29 <td align="center">服务列表</td> 30 <td align="center">查看用法</td> 31 </tr> 32 </table> 33 34 ![启用禁用](https://github.com/fumiama/NanoBot/assets/41315874/fc7f4774-f64b-44c5-9575-b9483bf3a455) 35 36 37 ```go 38 package main 39 40 import ( 41 _ "github.com/fumiama/NanoBot/example/echo" 42 43 nano "github.com/fumiama/NanoBot" 44 log "github.com/sirupsen/logrus" 45 ) 46 47 func main() { 48 log.SetLevel(log.DebugLevel) 49 nano.OpenAPI = nano.SandboxAPI 50 nano.OnMessageFullMatch("help").SetBlock(true). 51 Handle(func(ctx *nano.Ctx) { 52 _, _ = ctx.SendPlainMessage(false, "echo string") 53 }) 54 nano.Run(nil, &nano.Bot{ 55 AppID: "你的AppID", 56 Token: "你的Token", 57 Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)", 58 Intents: nano.IntentPublic, 59 SuperUsers: []string{"用户ID1", "用户ID2"}, 60 }) 61 } 62 ``` 63 64 ## 更多选择(传统的事件驱动) 65 66 > 如果声明了 Handler, 所有插件将被禁用 67 68 ![event-based example](https://github.com/fumiama/NanoBot/assets/41315874/414ef9a6-1da2-49ff-b28e-9e3009cdb41c) 69 70 ```go 71 package main 72 73 import ( 74 "strings" 75 76 nano "github.com/fumiama/NanoBot" 77 log "github.com/sirupsen/logrus" 78 ) 79 80 func main() { 81 log.SetLevel(log.DebugLevel) 82 nano.OpenAPI = nano.SandboxAPI 83 nano.Run(nil, &nano.Bot{ 84 AppID: "你的AppID", 85 Token: "你的Token", 86 Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)", 87 Intents: nano.IntentPublic, 88 Handler: &nano.Handler{ 89 OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) { 90 u := "" 91 if len(d.Attachments) > 0 { 92 u = d.Attachments[0].URL 93 if !strings.HasPrefix(u, "http") { 94 u = "http://" + u 95 } 96 } 97 _, err := bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{ 98 Content: "您发送了: " + d.Content, 99 Image: u, 100 ReplyMessageID: d.ID, 101 MessageReference: &nano.MessageReference{ 102 MessageID: d.ID, 103 }, 104 }) 105 if err != nil { 106 bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{ 107 Content: "[ERROR]: " + err.Error(), 108 ReplyMessageID: d.ID, 109 }) 110 } 111 }, 112 }, 113 }) 114 } 115 ``` 116 117 ## Thanks 118 119 - [ZeroBot](https://github.com/wdvxdr1123/ZeroBot)