1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-09 20:40:27 +08:00

add plugin

This commit is contained in:
源文雨
2022-06-01 00:39:38 +08:00
parent b2d1f0c249
commit 473331b38a
10 changed files with 529 additions and 46 deletions

View File

@@ -5,9 +5,42 @@ Lightweight Telegram bot framework
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.
## Example
## Quick Start
> Here is a plugin-based example
```go
package main
See under `example` folder or below.
import (
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
}
msg := ctx.Value.(*tgba.Message)
ctx.Caller.Send(tgba.NewMessage(msg.Chat.ID, 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.
![example](https://user-images.githubusercontent.com/41315874/171180885-c888a031-7797-4b4b-a232-9ff23f031b32.png)
@@ -32,7 +65,7 @@ func main() {
Timeout: 60,
},
Debug: true,
Handler: rei.Handler{
Handler: &rei.Handler{
OnMessage: func(updateid int, bot *rei.TelegramClient, msg *tgba.Message) {
if len(msg.Text) <= len("测试") {
return
@@ -60,4 +93,4 @@ func main() {
},
})
}
```
```