1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-08 20:10:30 +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

28
rules.go Normal file
View File

@@ -0,0 +1,28 @@
package rei
import (
"strings"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
// PrefixRule check if the message has the prefix and trim the prefix
//
// 检查消息前缀
func PrefixRule(prefixes ...string) Rule {
return func(ctx *Ctx) bool {
msg, ok := ctx.Value.(*tgba.Message)
if !ok || msg.Text == "" { // 确保无空
return false
}
for _, prefix := range prefixes {
if strings.HasPrefix(msg.Text, prefix) {
ctx.State["prefix"] = prefix
arg := strings.TrimLeft(msg.Text[len(prefix):], " ")
ctx.State["args"] = arg
return true
}
}
return false
}
}