1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-23 12:40:38 +08:00

optimize: hide caller & add preblock

This commit is contained in:
源文雨
2023-10-18 13:36:48 +09:00
parent 9c5a9796e1
commit 3bab1f9031
13 changed files with 581 additions and 75 deletions

View File

@@ -44,7 +44,7 @@ func (bot *Bot) processEvent(payload *WebsocketPayload) {
Seq: payload.S,
},
State: State{},
Caller: bot,
caller: bot,
}
switch tp {
case "DirectMessageCreate":
@@ -86,14 +86,14 @@ func match(ctx *Ctx, matchers []*Matcher) {
if ctx.Message != nil && ctx.Message.Content != "" { // 确保无空
if !ctx.IsToMe {
ctx.IsToMe = func(ctx *Ctx) bool {
name := ctx.Caller.ready.User.Username
name := ctx.GetReady().User.Username
if strings.HasPrefix(ctx.Message.Content, name) {
log.Debugln(getLogHeader(), "message before process:", ctx.Message.Content)
ctx.Message.Content = strings.TrimLeft(ctx.Message.Content[len(name):], " ")
log.Debugln(getLogHeader(), "message after process:", ctx.Message.Content)
return true
}
atme := ctx.Caller.AtMe()
atme := ctx.AtMe()
if strings.HasPrefix(ctx.Message.Content, atme) {
log.Debugln(getLogHeader(), "message before process:", ctx.Message.Content)
ctx.Message.Content = strings.TrimLeft(ctx.Message.Content[len(atme):], " ")