mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-18 01:32:58 +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 != "" { // 确保无空
|
if ctx.Message != nil && ctx.Message.Text != "" { // 确保无空
|
||||||
ctx.IsToMe = func(ctx *Ctx) bool {
|
ctx.IsToMe = func(ctx *Ctx) bool {
|
||||||
if ctx.Message.Chat.IsPrivate() {
|
if ctx.Message.Chat.IsPrivate() {
|
||||||
|
log.Debugln("[event] private event")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
name := ctx.Caller.Self.String()
|
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 {
|
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 == "" || !ctx.IsToMe { // 确保无空
|
if !ok || msg.Text == "" { // 确保无空
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
msg.Text = strings.TrimSpace(msg.Text)
|
msg.Text = strings.TrimSpace(msg.Text)
|
||||||
@@ -72,10 +72,13 @@ func CommandRule(commands ...string) Rule {
|
|||||||
case strings.HasPrefix(msg.Text, "/"):
|
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, " ")
|
||||||
switch {
|
if a > 0 && !strings.HasPrefix(msg.Text[a:], "@"+ctx.Caller.Self.String()) {
|
||||||
case b <= 1 || b == len(msg.Text) || a >= b:
|
|
||||||
return false
|
return false
|
||||||
case a < 0:
|
}
|
||||||
|
switch {
|
||||||
|
case b <= 1:
|
||||||
|
return false
|
||||||
|
case a < 0 || a >= b:
|
||||||
cmdMessage = msg.Text[1:b]
|
cmdMessage = msg.Text[1:b]
|
||||||
args = msg.Text[b+1:]
|
args = msg.Text[b+1:]
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user