Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance IsToMe #16

Merged
merged 1 commit into from Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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