Skip to content

Commit

Permalink
enhance IsToMe (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanrichan committed Apr 5, 2021
1 parent 33e13ab commit 3aab063
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion bot.go
Expand Up @@ -2,6 +2,7 @@ package zero

import (
"runtime/debug"
"strconv"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -61,6 +62,7 @@ func processEvent(response []byte, caller APICaller) {
event.DetailType = event.MessageType
case "notice":
event.DetailType = event.NoticeType
preprocessNoticeEvent(&event)
case "request":
event.DetailType = event.RequestType
}
Expand Down Expand Up @@ -130,7 +132,8 @@ func preprocessMessageEvent(e *Event) {
e.IsToMe = false
for i, m := range e.Message {
if m.Type == "at" {
if m.Data["qq"] == BotConfig.SelfID {
qq, _ := strconv.ParseInt(m.Data["qq"], 10, 64)
if qq == e.SelfID {
e.IsToMe = true
e.Message = append(e.Message[:i], e.Message[i+1:]...)
return
Expand Down Expand Up @@ -160,6 +163,22 @@ func preprocessMessageEvent(e *Event) {
e.Message[0].Data["text"] = strings.TrimLeft(e.Message[0].Data["text"], " ") // Trim Again!
}

// preprocessNoticeEvent 更新事件
func preprocessNoticeEvent(e *Event) {
switch e.NoticeType {
case "group_upload", "friend_add", "friend_recall":
//
case "group_admin", "group_decrease", "group_increase", "group_ban", "group_recall", "honor":
if e.UserID == e.SelfID {
e.IsToMe = true
}
case "poke", "lucky_king":
if e.TargetID == e.SelfID {
e.IsToMe = true
}
}
}

// GetBot 获取指定的bot (Ctx)实例
func GetBot(id int64) *Ctx {
caller, ok := APICallers.Load(id)
Expand Down
1 change: 1 addition & 0 deletions types.go
Expand Up @@ -64,6 +64,7 @@ type Event struct {
MessageID int64 `json:"message_id"`
GroupID int64 `json:"group_id"`
UserID int64 `json:"user_id"`
TargetID int64 `json:"target_id"`
SelfID int64 `json:"self_id"`
RawMessage string `json:"raw_message"` // raw_message is always string
Anonymous interface{} `json:"anonymous"`
Expand Down

0 comments on commit 3aab063

Please sign in to comment.