Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fumiama/nanobot

类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用
https://github.com/fumiama/nanobot

golang golang-api golang-cli golang-examples golang-library golang-package qq qq-bot qq-group qq-group-robot qq-guild qq-guild-bot qq-login qq-nt qq-protocol qq-robot qqbot qqrobot zerobot zerobot-plugin

Last synced: about 1 month ago
JSON representation

类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用

Awesome Lists containing this project

README

        


东云名乃

NanoBot


类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用


## Instructions

> Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction.

参见 QQ 官方[文档](https://bot.q.qq.com/wiki/)。

## 快速开始(基于插件)
> 查看`example`文件夹以获取更多信息







开始响应
服务列表
查看用法

![启用禁用](https://github.com/fumiama/NanoBot/assets/41315874/fc7f4774-f64b-44c5-9575-b9483bf3a455)

```go
package main

import (
_ "github.com/fumiama/NanoBot/example/echo"

nano "github.com/fumiama/NanoBot"
log "github.com/sirupsen/logrus"
)

func main() {
log.SetLevel(log.DebugLevel)
nano.OpenAPI = nano.SandboxAPI
nano.OnMessageFullMatch("help").SetBlock(true).
Handle(func(ctx *nano.Ctx) {
_, _ = ctx.SendPlainMessage(false, "echo string")
})
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
SuperUsers: []string{"用户ID1", "用户ID2"},
})
}
```

## 更多选择(传统的事件驱动)

> 如果声明了 Handler, 所有插件将被禁用

![event-based example](https://github.com/fumiama/NanoBot/assets/41315874/414ef9a6-1da2-49ff-b28e-9e3009cdb41c)

```go
package main

import (
"strings"

nano "github.com/fumiama/NanoBot"
log "github.com/sirupsen/logrus"
)

func main() {
log.SetLevel(log.DebugLevel)
nano.OpenAPI = nano.SandboxAPI
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
Handler: &nano.Handler{
OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) {
u := ""
if len(d.Attachments) > 0 {
u = d.Attachments[0].URL
if !strings.HasPrefix(u, "http") {
u = "http://" + u
}
}
_, err := bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
Content: "您发送了: " + d.Content,
Image: u,
ReplyMessageID: d.ID,
MessageReference: &nano.MessageReference{
MessageID: d.ID,
},
})
if err != nil {
bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
Content: "[ERROR]: " + err.Error(),
ReplyMessageID: d.ID,
})
}
},
},
})
}
```

## Thanks

- [ZeroBot](https://github.com/wdvxdr1123/ZeroBot)