mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-05 00:50:25 +08:00
fix cd cmdrules istome
This commit is contained in:
6
cd.go
6
cd.go
@@ -17,7 +17,7 @@ var startTime int64
|
||||
|
||||
func init() {
|
||||
// 插件冲突检测 会在本群发送一条消息并在约 1s 后撤回
|
||||
OnMessageFullMatch("插件冲突检测", OnlyGroup, AdminPermission, OnlyToMe).SetBlock(true).secondPriority().
|
||||
OnMessageFullMatch("插件冲突检测", OnlyPublic, AdminPermission, OnlyToMe).SetBlock(true).secondPriority().
|
||||
Handle(func(ctx *Ctx) {
|
||||
tok := genToken()
|
||||
if tok == "" || len([]rune(tok)) != 4 {
|
||||
@@ -33,7 +33,7 @@ func init() {
|
||||
_, _ = ctx.Caller.Send(tgba.NewDeleteMessage(ctx.Message.Chat.ID, msg.MessageID))
|
||||
})
|
||||
|
||||
OnMessageRegex("^●cd([\u4e00-\u8e00]{4})$", OnlyGroup).SetBlock(true).secondPriority().
|
||||
OnMessageRegex("^●cd([\u4e00-\u8e00]{4})$", OnlyPublic).SetBlock(true).secondPriority().
|
||||
Handle(func(ctx *Ctx) {
|
||||
if isValidToken(ctx.State["regex_matched"].([]string)[1]) {
|
||||
gid := ctx.Message.Chat.ID
|
||||
@@ -63,7 +63,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
|
||||
OnMessageRegex("^●cd●(([\u4e00-\u8e00]*[\u3d01-\u3d06]?))", OnlyGroup).SetBlock(true).secondPriority().
|
||||
OnMessageRegex("^●cd●(([\u4e00-\u8e00]*[\u3d01-\u3d06]?))", OnlyPublic).SetBlock(true).secondPriority().
|
||||
Handle(func(ctx *Ctx) {
|
||||
if time.Now().Unix()-startTime < 10 {
|
||||
gid := ctx.Message.Chat.ID
|
||||
|
||||
10
event.go
10
event.go
@@ -84,6 +84,9 @@ func match(ctx *Ctx, matchers []*Matcher) {
|
||||
log.Debugln("[event] message before process:", ctx.Message.Text)
|
||||
if len(ctx.Message.Entities) > 0 {
|
||||
n := len(name)
|
||||
for i := n; ctx.Message.Text[i] == ' '; i++ {
|
||||
n++
|
||||
}
|
||||
c := 0
|
||||
i := 0
|
||||
for _, e := range ctx.Message.Entities {
|
||||
@@ -116,7 +119,7 @@ func match(ctx *Ctx, matchers []*Matcher) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.Message.Text = ctx.Message.Text[len(name):]
|
||||
ctx.Message.Text = strings.TrimLeft(ctx.Message.Text[len(name):], " ")
|
||||
log.Debugln("[event] message after process:", ctx.Message.Text)
|
||||
return true
|
||||
}
|
||||
@@ -148,7 +151,7 @@ func match(ctx *Ctx, matchers []*Matcher) {
|
||||
}
|
||||
if ctx.Message.Text[0] == ' ' {
|
||||
n := 0
|
||||
for c := range ctx.Message.Text {
|
||||
for _, c := range ctx.Message.Text {
|
||||
if c == ' ' {
|
||||
n++
|
||||
} else {
|
||||
@@ -190,9 +193,10 @@ func match(ctx *Ctx, matchers []*Matcher) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return strings.Contains(ctx.Message.Text, name)
|
||||
}(ctx)
|
||||
}
|
||||
log.Debugln("[event] is to me:", ctx.IsToMe)
|
||||
loop:
|
||||
for _, matcher := range matchers {
|
||||
for k := range ctx.State { // Clear State
|
||||
|
||||
19
rules.go
19
rules.go
@@ -66,25 +66,12 @@ func CommandRule(commands ...string) Rule {
|
||||
cmdMessage := ""
|
||||
args := ""
|
||||
switch {
|
||||
case msg.IsCommand():
|
||||
case ctx.IsToMe && msg.IsCommand():
|
||||
cmdMessage = msg.Command()
|
||||
args = msg.CommandArguments()
|
||||
case strings.HasPrefix(msg.Text, "/"):
|
||||
a := strings.Index(msg.Text, "@")
|
||||
b := strings.Index(msg.Text, " ")
|
||||
if a > 0 && !strings.HasPrefix(msg.Text[a:], "@"+ctx.Caller.Self.String()) {
|
||||
return false
|
||||
}
|
||||
switch {
|
||||
case b <= 1:
|
||||
return false
|
||||
case a < 0 || a >= b:
|
||||
cmdMessage = msg.Text[1:b]
|
||||
args = msg.Text[b+1:]
|
||||
default:
|
||||
cmdMessage = msg.Text[1:a]
|
||||
args = msg.Text[b+1:]
|
||||
}
|
||||
cmdMessage, args, _ = strings.Cut(msg.Text, " ")
|
||||
cmdMessage, _, _ = strings.Cut(cmdMessage, "@")
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user