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

fix command rule

This commit is contained in:
源文雨
2022-10-04 16:34:25 +08:00
parent 5633f01473
commit 63a0752c61
2 changed files with 8 additions and 4 deletions

View File

@@ -76,6 +76,7 @@ func match(ctx *Ctx, matchers []*Matcher) {
if ctx.Message != nil && ctx.Message.Text != "" { // 确保无空
ctx.IsToMe = func(ctx *Ctx) bool {
if ctx.Message.Chat.IsPrivate() {
log.Debugln("[event] private event")
return true
}
name := ctx.Caller.Self.String()

View File

@@ -56,7 +56,7 @@ 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 == "" || !ctx.IsToMe { // 确保无空
if !ok || msg.Text == "" { // 确保无空
return false
}
msg.Text = strings.TrimSpace(msg.Text)
@@ -72,10 +72,13 @@ func CommandRule(commands ...string) Rule {
case strings.HasPrefix(msg.Text, "/"):
a := strings.Index(msg.Text, "@")
b := strings.Index(msg.Text, " ")
switch {
case b <= 1 || b == len(msg.Text) || a >= b:
if a > 0 && !strings.HasPrefix(msg.Text[a:], "@"+ctx.Caller.Self.String()) {
return false
case a < 0:
}
switch {
case b <= 1:
return false
case a < 0 || a >= b:
cmdMessage = msg.Text[1:b]
args = msg.Text[b+1:]
default: