mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
feat: guild channel message event & guild message reactions updated event
This commit is contained in:
parent
45ccc0a1b5
commit
498602fbca
@ -76,6 +76,8 @@ func NewQQBot(cli *client.QQClient) *CQBot {
|
|||||||
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
|
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
|
||||||
}
|
}
|
||||||
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
||||||
|
bot.Client.GuildService.OnGuildChannelMessage(bot.guildChannelMessageEvent)
|
||||||
|
bot.Client.GuildService.OnGuildMessageReactionsUpdated(bot.guildMessageReactionsUpdated)
|
||||||
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
||||||
|
@ -2,6 +2,7 @@ package coolq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -130,6 +131,73 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEven
|
|||||||
bot.dispatchEventMessage(tm)
|
bot.dispatchEventMessage(tm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) guildChannelMessageEvent(c *client.QQClient, m *message.GuildChannelMessage) {
|
||||||
|
bot.checkMedia(m.Elements, int64(m.Sender.TinyId))
|
||||||
|
guild := c.GuildService.FindGuild(m.GuildId)
|
||||||
|
if guild == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var channel *client.ChannelInfo
|
||||||
|
for _, c := range guild.Channels {
|
||||||
|
if c.ChannelId == m.ChannelId {
|
||||||
|
channel = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Infof("收到来自频道 %v(%v) 子频道 %v(%v) 内 %v(%v) 的消息: %v", guild.GuildName, guild.GuildId, channel.ChannelName, m.ChannelId, m.Sender.Nickname, m.Sender.TinyId, ToStringMessage(m.Elements, 0, true))
|
||||||
|
// todo: 数据库支持
|
||||||
|
bot.dispatchEventMessage(global.MSG{
|
||||||
|
"post_type": "message",
|
||||||
|
"message_type": "guild",
|
||||||
|
"sub_type": "channel",
|
||||||
|
"guild_id": m.GuildId,
|
||||||
|
"channel_id": m.ChannelId,
|
||||||
|
"message_id": fmt.Sprintf("%v-%v", m.Id, m.InternalId),
|
||||||
|
"user_id": m.Sender.TinyId,
|
||||||
|
"message": ToFormattedMessage(m.Elements, 0, false), // todo: 增加对频道消息 Reply 的支持
|
||||||
|
"self_id": bot.Client.Uin,
|
||||||
|
"self_tiny_id": bot.Client.GuildService.TinyId,
|
||||||
|
"time": m.Time,
|
||||||
|
"sender": global.MSG{
|
||||||
|
"user_id": m.Sender.TinyId,
|
||||||
|
"nickname": m.Sender.Nickname,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) guildMessageReactionsUpdated(c *client.QQClient, e *client.GuildMessageReactionsUpdatedEvent) {
|
||||||
|
guild := c.GuildService.FindGuild(e.GuildId)
|
||||||
|
if guild == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
str := fmt.Sprintf("频道 %v(%v) 消息 %v 表情贴片已更新: ", guild.GuildName, guild.GuildId, e.MessageId)
|
||||||
|
var currentReactions []global.MSG
|
||||||
|
for _, r := range e.CurrentReactions {
|
||||||
|
str += fmt.Sprintf("%v*%v ", r.Face.Name, r.Count)
|
||||||
|
currentReactions = append(currentReactions, global.MSG{
|
||||||
|
"emoji_id": r.EmojiId,
|
||||||
|
"emoji_index": r.Face.Index,
|
||||||
|
"emoji_type": r.EmojiType,
|
||||||
|
"emoji_name": r.Face.Name,
|
||||||
|
"count": r.Count,
|
||||||
|
"clicked": r.Clicked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(e.CurrentReactions) == 0 {
|
||||||
|
str += "无任何表情"
|
||||||
|
}
|
||||||
|
log.Infof(str)
|
||||||
|
bot.dispatchEventMessage(global.MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"notice_type": "message_reactions_updated",
|
||||||
|
"message_sender_uin": e.MessageSenderUin,
|
||||||
|
"guild_id": e.GuildId,
|
||||||
|
"channel_id": e.ChannelId,
|
||||||
|
"message_id": fmt.Sprint(e.MessageId), // todo: 支持数据库后转换为数据库id
|
||||||
|
"operator_id": e.OperatorId,
|
||||||
|
"current_reactions": currentReactions,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
|
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
|
||||||
g := c.FindGroup(e.GroupCode)
|
g := c.FindGroup(e.GroupCode)
|
||||||
if e.TargetUin == 0 {
|
if e.TargetUin == 0 {
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ replace github.com/willf/bitset v1.2.0 => github.com/bits-and-blooms/bitset v1.2
|
|||||||
require (
|
require (
|
||||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
|
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
|
||||||
github.com/Microsoft/go-winio v0.5.1
|
github.com/Microsoft/go-winio v0.5.1
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20211107055846-aba75d573399
|
github.com/Mrs4s/MiraiGo v0.0.0-20211108192542-190c4944093d
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/fumiama/go-hide-param v0.1.4
|
github.com/fumiama/go-hide-param v0.1.4
|
||||||
github.com/gabriel-vasile/mimetype v1.4.0
|
github.com/gabriel-vasile/mimetype v1.4.0
|
||||||
|
4
go.sum
4
go.sum
@ -3,8 +3,8 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/g
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
|
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
|
||||||
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20211107055846-aba75d573399 h1:ckckRyRBsf5hc0B5hdsPmehVjzIP7cKP8X8AdDn+KbQ=
|
github.com/Mrs4s/MiraiGo v0.0.0-20211108192542-190c4944093d h1:r7p/A9vej+QDH/WcSvpIaxixqOvrfVYAUzlJTFk9J4Y=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20211107055846-aba75d573399/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so=
|
github.com/Mrs4s/MiraiGo v0.0.0-20211108192542-190c4944093d/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so=
|
||||||
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
|
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
|
||||||
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
|
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user