Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumiama/reibot
Lightweight Telegram bot framework
https://github.com/fumiama/reibot
Last synced: 2 months ago
JSON representation
Lightweight Telegram bot framework
- Host: GitHub
- URL: https://github.com/fumiama/reibot
- Owner: fumiama
- License: gpl-3.0
- Created: 2022-05-31T10:40:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-10T14:32:42.000Z (almost 2 years ago)
- Last Synced: 2024-06-19T19:48:39.836Z (7 months ago)
- Language: Go
- Size: 495 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Instructions
> Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction.
This framework is a simple wrapper for [go-telegram-bot-api](https://github.com/go-telegram-bot-api/telegram-bot-api), aiming to make the event processing easier.
## Quick Start
> Here is a plugin-based example, see more in the `example` folder![plugin-based example](https://user-images.githubusercontent.com/41315874/171567343-f61eba4e-2bc9-49b3-af05-6446f0a73c54.png)
```go
package mainimport (
rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)func main() {
rei.OnMessagePrefix("echo").SetBlock(true).SecondPriority().
Handle(func(ctx *rei.Ctx) {
args := ctx.State["args"].(string)
if args == "" {
return
}
ctx.SendPlainMessage(false, args)
})
rei.Run(rei.Bot{
Token: "",
Buffer: 256,
UpdateConfig: tgba.UpdateConfig{
Offset: 0,
Limit: 0,
Timeout: 60,
},
Debug: true,
})
}
```## Event-Based
> If Handler in Bot is implemented, the plugin function will be disabled.
![event-based example](https://user-images.githubusercontent.com/41315874/171567349-5ff59cfa-cc3a-44a8-8158-6c76c8d433b7.png)
```go
package mainimport (
"strings"rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
log "github.com/sirupsen/logrus"
)func main() {
rei.Run(rei.Bot{
Token: "",
Buffer: 256,
UpdateConfig: tgba.UpdateConfig{
Offset: 0,
Limit: 0,
Timeout: 60,
},
Debug: true,
Handler: &rei.Handler{
OnMessage: func(updateid int, bot *rei.TelegramClient, msg *tgba.Message) {
if len(msg.Text) <= len("测试") {
return
}
if !strings.HasPrefix(msg.Text, "测试") {
return
}
_, err := bot.Send(tgba.NewMessage(msg.Chat.ID, msg.Text[len("测试"):]))
if err != nil {
log.Errorln(err)
}
},
OnEditedMessage: func(updateid int, bot *rei.TelegramClient, msg *tgba.Message) {
if len(msg.Text) <= len("测试") {
return
}
if !strings.HasPrefix(msg.Text, "测试") {
return
}
_, err := bot.Send(tgba.NewMessage(msg.Chat.ID, "已编辑:"+msg.Text[len("测试"):]))
if err != nil {
log.Errorln(err)
}
},
},
})
}
```## Thanks
- [ZeroBot](https://github.com/wdvxdr1123/ZeroBot)