github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/openapi_emoji.go (about) 1 package nano 2 3 import "strconv" 4 5 // Emoji 表情对象 6 // 7 // https://bot.q.qq.com/wiki/develop/api/openapi/emoji/model.html 8 type Emoji struct { 9 ID string `json:"id"` 10 Type uint32 `json:"type"` 11 } 12 13 func (e *Emoji) String() string { 14 return "<emoji:" + e.ID + ">" 15 } 16 17 // MessageReaction https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#messagereaction 18 type MessageReaction struct { 19 UserID string `json:"user_id"` 20 GuildID string `json:"guild_id"` 21 ChannelID string `json:"channel_id"` 22 Target *ReactionTarget `json:"target"` 23 Emoji *Emoji `json:"emoji"` 24 } 25 26 // ReactionTargetType https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontargettype 27 type ReactionTargetType string 28 29 // ReactionTarget https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontarget 30 type ReactionTarget struct { 31 ID string `json:"id"` 32 Type ReactionTargetType `json:"type"` // 实际是 string 而非 int 33 } 34 35 // GiveMessageReaction 对消息 message_id 进行表情表态 36 // 37 // https://bot.q.qq.com/wiki/develop/api/openapi/reaction/put_message_reaction.html 38 func (bot *Bot) GiveMessageReaction(channelid, messageid string, emoji Emoji) error { 39 return bot.PutOpenAPI("/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, "", nil, nil) 40 } 41 42 // DeleteMessageReaction 删除自己对消息 message_id 的表情表态 43 // 44 // https://bot.q.qq.com/wiki/develop/api/openapi/reaction/delete_own_message_reaction.html 45 func (bot *Bot) DeleteMessageReaction(channelid, messageid string, emoji Emoji) error { 46 return bot.DeleteOpenAPI("/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, "", nil) 47 } 48 49 // MessageReactionUsers https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html#%E8%BF%94%E5%9B%9E 50 type MessageReactionUsers struct { 51 Users []User `json:"users"` 52 Cookie string `json:"cookie"` 53 IsEnd bool `json:"is_end"` 54 } 55 56 // GetMessageReactionUsers 拉取对消息 message_id 指定表情表态的用户列表 57 // 58 // https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html 59 func (bot *Bot) GetMessageReactionUsers(channelid, messageid string, emoji Emoji, cookie string, limit int) (*MessageReactionUsers, error) { 60 return bot.getOpenAPIofMessageReactionUsers(WriteHTTPQueryIfNotNil( 61 "/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, 62 "cookie", cookie, 63 "limit", limit, 64 )) 65 }