mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-12 22:40:30 +08:00
fix CommandRule
This commit is contained in:
52
rules.go
52
rules.go
@@ -58,33 +58,39 @@ func CommandRule(commands ...string) Rule {
|
|||||||
if !ok || msg.Text == "" { // 确保无空
|
if !ok || msg.Text == "" { // 确保无空
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if msg.IsCommand() {
|
cmdMessage := ""
|
||||||
ctx.State["command"] = msg.Command()
|
args := ""
|
||||||
ctx.State["args"] = msg.CommandArguments()
|
switch {
|
||||||
return true
|
case msg.IsCommand():
|
||||||
}
|
cmdMessage = msg.Command()
|
||||||
if strings.HasPrefix(msg.Text, "/") {
|
args = msg.CommandArguments()
|
||||||
|
case strings.HasPrefix(msg.Text, "/"):
|
||||||
a := strings.Index(msg.Text, "@")
|
a := strings.Index(msg.Text, "@")
|
||||||
b := strings.Index(msg.Text, " ")
|
b := strings.Index(msg.Text, " ")
|
||||||
if b <= 1 {
|
switch {
|
||||||
ctx.State["command"] = msg.Text[1:]
|
case b <= 1:
|
||||||
ctx.State["args"] = ""
|
cmdMessage = msg.Text[1:]
|
||||||
|
args = ""
|
||||||
|
case b == len(msg.Text):
|
||||||
|
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:]
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, command := range commands {
|
||||||
|
if strings.HasPrefix(cmdMessage, command) {
|
||||||
|
ctx.State["command"] = command
|
||||||
|
ctx.State["args"] = args
|
||||||
return true
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user