From 84615389056aa7bbc73bd2f44a0aaecc7df7586e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:37:43 +0900 Subject: [PATCH] finish emoji --- openapi.go | 2 +- openapi_codegen_getopenapiof.go | 12 +++++++ openapi_emoji.go | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 openapi_emoji.go diff --git a/openapi.go b/openapi.go index 826ca92..5c03412 100644 --- a/openapi.go +++ b/openapi.go @@ -19,7 +19,7 @@ func checkrespbaseunsafe(ptr any) error { return nil } -//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList ChannelPermissions Message MessageSetting PinsMessage Schedule +//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList ChannelPermissions Message MessageSetting PinsMessage Schedule MessageReactionUsers // GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase func (bot *Bot) GetOpenAPI(ep, contenttype string, ptr any) error { diff --git a/openapi_codegen_getopenapiof.go b/openapi_codegen_getopenapiof.go index b5c8227..1b5a325 100644 --- a/openapi_codegen_getopenapiof.go +++ b/openapi_codegen_getopenapiof.go @@ -149,3 +149,15 @@ func (bot *Bot) getOpenAPIofSchedule(ep string) (*Schedule, error) { } return &resp.Schedule, err } + +func (bot *Bot) getOpenAPIofMessageReactionUsers(ep string) (*MessageReactionUsers, error) { + resp := &struct { + CodeMessageBase + MessageReactionUsers + }{} + err := bot.GetOpenAPI(ep, "", resp) + if err != nil { + err = errors.Wrap(err, getCallerFuncName()) + } + return &resp.MessageReactionUsers, err +} diff --git a/openapi_emoji.go b/openapi_emoji.go new file mode 100644 index 0000000..81a1b31 --- /dev/null +++ b/openapi_emoji.go @@ -0,0 +1,61 @@ +package nano + +import "strconv" + +// Emoji 表情对象 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/emoji/model.html +type Emoji struct { + ID string `json:"id"` + Type uint32 `json:"type"` +} + +// MessageReaction https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#messagereaction +type MessageReaction struct { + UserID string `json:"user_id"` + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + Target *ReactionTarget `json:"target"` + Emoji *Emoji `json:"emoji"` +} + +// ReactionTargetType https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontargettype +type ReactionTargetType int + +// ReactionTarget https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontarget +type ReactionTarget struct { + ID string `json:"id"` + Type ReactionTargetType `json:"type"` +} + +// GiveMessageReaction 对消息 message_id 进行表情表态 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/reaction/put_message_reaction.html +func (bot *Bot) GiveMessageReaction(channelid, messageid string, emoji Emoji) error { + return bot.PutOpenAPI("/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, "", nil, nil) +} + +// DeleteMessageReaction 删除自己对消息 message_id 的表情表态 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/reaction/delete_own_message_reaction.html +func (bot *Bot) DeleteMessageReaction(channelid, messageid string, emoji Emoji) error { + return bot.DeleteOpenAPI("/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, "", nil) +} + +// MessageReactionUsers https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html#%E8%BF%94%E5%9B%9E +type MessageReactionUsers struct { + Users []User `json:"users"` + Cookie string `json:"cookie"` + IsEnd bool `json:"is_end"` +} + +// GetMessageReactionUsers 拉取对消息 message_id 指定表情表态的用户列表 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html +func (bot *Bot) GetMessageReactionUsers(channelid, messageid string, emoji Emoji, cookie string, limit int) (*MessageReactionUsers, error) { + return bot.getOpenAPIofMessageReactionUsers(WriteHTTPQueryIfNotNil( + "/channels/"+channelid+"/messages/"+messageid+"/reactions/"+strconv.FormatUint(uint64(emoji.Type), 10)+"/"+emoji.ID, + "cookie", cookie, + "limit", limit, + )) +}