1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-11 05:30:38 +08:00

fix CommandRule

This commit is contained in:
源文雨
2022-06-10 20:51:04 +08:00
parent 72390b4c09
commit ace55c3f84

View File

@@ -55,12 +55,38 @@ func SuffixRule(suffixes ...string) Rule {
func CommandRule(commands ...string) Rule { func CommandRule(commands ...string) Rule {
return func(ctx *Ctx) bool { return func(ctx *Ctx) bool {
msg, ok := ctx.Value.(*tgba.Message) msg, ok := ctx.Value.(*tgba.Message)
if !ok || msg.Text == "" || !msg.IsCommand() { // 确保无空 if !ok || msg.Text == "" { // 确保无空
return false return false
} }
ctx.State["command"] = msg.CommandWithAt() if msg.IsCommand() {
ctx.State["args"] = msg.CommandArguments() ctx.State["command"] = msg.Command()
return true ctx.State["args"] = msg.CommandArguments()
return true
}
if strings.HasPrefix(msg.Text, "/") {
a := strings.Index(msg.Text, "@")
b := strings.Index(msg.Text, " ")
if b <= 1 {
ctx.State["command"] = msg.Text[1:]
ctx.State["args"] = ""
return true
}
if b == len(msg.Text) {
return false
}
if a < 0 {
ctx.State["command"] = msg.Text[1:b]
ctx.State["args"] = msg.Text[b+1:]
return true
}
if a >= b {
return false
}
ctx.State["command"] = msg.Text[1:a]
ctx.State["args"] = msg.Text[b+1:]
return true
}
return false
} }
} }
@@ -153,6 +179,9 @@ func OnlyToMe(ctx *Ctx) bool {
if !ok || msg.Text == "" { // 确保无空 if !ok || msg.Text == "" { // 确保无空
return false return false
} }
if msg.Chat.IsPrivate() {
return true
}
name := ctx.Caller.Self.String() name := ctx.Caller.Self.String()
if strings.HasPrefix(msg.Text, name) { if strings.HasPrefix(msg.Text, name) {
return true return true