1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-07 01:50:24 +08:00

update deps & 优化 commandrule

This commit is contained in:
源文雨
2022-10-03 23:39:45 +08:00
parent 9e4784e553
commit 5633f01473
4 changed files with 38 additions and 43 deletions

View File

@@ -56,7 +56,11 @@ func SuffixRule(suffixes ...string) Rule {
func CommandRule(commands ...string) Rule {
return func(ctx *Ctx) bool {
msg, ok := ctx.Value.(*tgba.Message)
if !ok || msg.Text == "" { // 确保无空
if !ok || msg.Text == "" || !ctx.IsToMe { // 确保无空
return false
}
msg.Text = strings.TrimSpace(msg.Text)
if msg.Text == "" { // 确保无空
return false
}
cmdMessage := ""
@@ -69,16 +73,11 @@ func CommandRule(commands ...string) Rule {
a := strings.Index(msg.Text, "@")
b := strings.Index(msg.Text, " ")
switch {
case b <= 1:
cmdMessage = msg.Text[1:]
args = ""
case b == len(msg.Text):
case b <= 1 || b == len(msg.Text) || a >= b:
return false
case a < 0:
cmdMessage = msg.Text[1:b]
args = msg.Text[b+1:]
case a >= b:
return false
default:
cmdMessage = msg.Text[1:a]
args = msg.Text[b+1:]