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:
1
event.go
1
event.go
@@ -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()
|
||||
|
||||
11
rules.go
11
rules.go
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user