1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-10 21:24:43 +08:00
This commit is contained in:
源文雨
2023-10-16 12:34:25 +09:00
parent fe4f7bf060
commit 415bd574f1
2 changed files with 6 additions and 7 deletions

View File

@@ -74,7 +74,6 @@ func (bot *Bot) processEvent(payload *WebsocketPayload) {
switch tp { switch tp {
case "Message": case "Message":
ctx.Message = (*Message)(x.UnsafePointer()) ctx.Message = (*Message)(x.UnsafePointer())
ctx.Message.Content = MessageUnescape(ctx.Message.Content)
log.Infoln(getLogHeader(), "收到 Guild:", ctx.Message.GuildID, ", Channel:", ctx.Message.ChannelID, "消息", ctx.Message.Author.ID, ":", ctx.Message.Content) log.Infoln(getLogHeader(), "收到 Guild:", ctx.Message.GuildID, ", Channel:", ctx.Message.ChannelID, "消息", ctx.Message.Author.ID, ":", ctx.Message.Content)
} }
go match(ctx, matchers) go match(ctx, matchers)

View File

@@ -25,7 +25,7 @@ func PrefixGroupRule(prefixes ...string) Rule {
return false return false
} }
for _, prefix := range prefixes { for _, prefix := range prefixes {
if strings.HasPrefix(msg.Content, prefix) { if strings.HasPrefix(msg.Content, MessageEscape(prefix)) {
ctx.State["prefix"] = prefix ctx.State["prefix"] = prefix
arg := strings.TrimLeft(msg.Content[len(prefix):], " ") arg := strings.TrimLeft(msg.Content[len(prefix):], " ")
ctx.State["args"] = arg ctx.State["args"] = arg
@@ -57,7 +57,7 @@ func SuffixGroupRule(suffixes ...string) Rule {
return false return false
} }
for _, suffix := range suffixes { for _, suffix := range suffixes {
if strings.HasSuffix(msg.Content, suffix) { if strings.HasSuffix(msg.Content, MessageEscape(suffix)) {
ctx.State["suffix"] = suffix ctx.State["suffix"] = suffix
arg := strings.TrimRight(msg.Content[:len(msg.Content)-len(suffix)], " ") arg := strings.TrimRight(msg.Content[:len(msg.Content)-len(suffix)], " ")
ctx.State["args"] = arg ctx.State["args"] = arg
@@ -102,7 +102,7 @@ func CommandGroupRule(commands ...string) Rule {
return false return false
} }
for _, command := range commands { for _, command := range commands {
if strings.HasPrefix(cmdMessage, command) { if strings.HasPrefix(cmdMessage, MessageEscape(command)) {
ctx.State["command"] = command ctx.State["command"] = command
ctx.State["args"] = args ctx.State["args"] = args
return true return true
@@ -158,7 +158,7 @@ func KeywordGroupRule(src ...string) Rule {
return false return false
} }
for _, str := range src { for _, str := range src {
if strings.Contains(msg.Content, str) { if strings.Contains(msg.Content, MessageEscape(str)) {
ctx.State["keyword"] = str ctx.State["keyword"] = str
return true return true
} }
@@ -184,7 +184,7 @@ func FullMatchGroupRule(src ...string) Rule {
return false return false
} }
for _, str := range src { for _, str := range src {
if str == msg.Content { if MessageEscape(str) == msg.Content {
ctx.State["matched"] = msg.Content ctx.State["matched"] = msg.Content
return true return true
} }
@@ -442,7 +442,7 @@ func MustProvidePhoto(onmessage string, needphohint, failhint string) Rule {
} }
return false return false
case newCtx := <-next: case newCtx := <-next:
ctx.State["photos"] = newCtx.State["photos"] ctx.State["attachments"] = newCtx.State["attachments"]
ctx.Event = newCtx.Event ctx.Event = newCtx.Event
return true return true
} }