mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-08 20:10:30 +08:00
add plugin
This commit is contained in:
28
rules.go
Normal file
28
rules.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user