From 215cc6ac825e5beafcb46f5029dc0adb6317d6f6 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 01:09:46 +0900 Subject: [PATCH] finish all main openapi --- openapi_audio.go | 3 + openapi_forum.go | 132 +++++++++++++++++++++++++++++++++++++++++ openapi_guild.go | 1 + openapi_permissions.go | 3 + openapi_richobj.go | 3 + 5 files changed, 142 insertions(+) create mode 100644 openapi_audio.go create mode 100644 openapi_forum.go create mode 100644 openapi_permissions.go create mode 100644 openapi_richobj.go diff --git a/openapi_audio.go b/openapi_audio.go new file mode 100644 index 0000000..cc44f7d --- /dev/null +++ b/openapi_audio.go @@ -0,0 +1,3 @@ +package nano + +// https://bot.q.qq.com/wiki/develop/api/openapi/audio/model.html diff --git a/openapi_forum.go b/openapi_forum.go new file mode 100644 index 0000000..8c07d8c --- /dev/null +++ b/openapi_forum.go @@ -0,0 +1,132 @@ +package nano + +import "time" + +// Thread 话题频道内发表的主帖称为主题 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#thread +type Thread struct { + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + AuthorID string `json:"author_id"` + ThreadInfo *ThreadInfo `json:"thread_info"` +} + +// ThreadInfo 帖子事件包含的主帖内容相关信息 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#threadinfo +type ThreadInfo struct { + ThreadID string `json:"thread_id"` + Title string `json:"title"` + Content string `json:"content"` + DateTime time.Time `json:"date_time"` +} + +// Post 话题频道内对主题的评论称为帖子 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#post +type Post struct { + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + AuthorID string `json:"author_id"` + PostInfo *PostInfo `json:"post_info"` +} + +// PostInfo 帖子事件包含的帖子内容信息 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#postinfo +type PostInfo struct { + ThreadID string `json:"thread_id"` + PostID string `json:"post_id"` + Content string `json:"content"` + DateTime time.Time `json:"date_time"` +} + +// Reply 话题频道对帖子回复或删除时生产该事件中包含该对象 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#reply +type Reply struct { + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + AuthorID string `json:"author_id"` + ReplyInfo *ReplyInfo `json:"reply_info"` +} + +// ReplyInfo 回复事件包含的回复内容信息 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#replyinfo +type ReplyInfo struct { + ThreadID string `json:"thread_id"` + PostID string `json:"post_id"` + ReplyID string `json:"reply_id"` + Content string `json:"content"` + DateTime time.Time `json:"date_time"` +} + +// AuditResult 论坛帖子审核结果事件 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#auditresult +type AuditResult struct { + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + AuthorID string `json:"author_id"` + ThreadID string `json:"thread_id"` + PostID string `json:"post_id"` + ReplyID string `json:"reply_id"` + Type uint32 `json:"type"` + Result uint32 `json:"result"` + ErrMsg string `json:"err_msg"` +} + +// GetChannelThreads 获取子频道下的帖子列表 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_threads_list.html +func (bot *Bot) GetChannelThreads(id string) (threads []Thread, isfinish bool, err error) { + resp := &struct { + CodeMessageBase + T []Thread `json:"threads"` + I uint32 `json:"is_finish"` + }{} + err = bot.GetOpenAPI("/channels/"+id+"/threads", "", resp) + threads = resp.T + isfinish = resp.I > 0 + return +} + +// GetThreadInfo 获取子频道下的帖子详情 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_thread.html +func (bot *Bot) GetThreadInfo(channelid, threadid string) (*ThreadInfo, error) { + resp := &struct { + CodeMessageBase + T ThreadInfo `json:"thread"` + }{} + err := bot.GetOpenAPI("/channels/"+channelid+"/threads/"+threadid, "", resp) + return &resp.T, err +} + +// PostThread 发表帖子 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/put_thread.html +func (bot *Bot) PostThreadInChannel(id string, title string, content string, format uint32) (taskid string, createtime string, err error) { + resp := &struct { + CodeMessageBase + T string `json:"task_id"` + C string `json:"create_time"` + }{} + err = bot.PutOpenAPI("/channels/"+id+"/threads", "", resp, WriteBodyFromJSON(&struct { + T string `json:"title"` + C string `json:"content"` + F uint32 `json:"format"` + }{title, content, format})) + taskid = resp.T + createtime = resp.C + return +} + +// DeleteThreadInChannel 删除指定子频道下的某个帖子 +// +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/delete_thread.html +func (bot *Bot) DeleteThreadInChannel(channelid, threadid string) error { + return bot.DeleteOpenAPI("/channels/"+channelid+"/threads/"+threadid, "", nil) +} diff --git a/openapi_guild.go b/openapi_guild.go index eb04dad..4acecc1 100644 --- a/openapi_guild.go +++ b/openapi_guild.go @@ -50,6 +50,7 @@ func (bot *Bot) SetUserMuteInGuild(guildid, userid string, endtimestamp string, // https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html func (bot *Bot) SetUsersMuteInGuild(guildid string, endtimestamp string, seconds string, userids ...string) ([]string, error) { resp := &struct { + CodeMessageBase U []string `json:"user_ids"` }{} err := bot.PatchOpenAPI("/guilds/"+guildid+"/mute", "", resp, WriteBodyFromJSON(&struct { diff --git a/openapi_permissions.go b/openapi_permissions.go new file mode 100644 index 0000000..6324b69 --- /dev/null +++ b/openapi_permissions.go @@ -0,0 +1,3 @@ +package nano + +// https://bot.q.qq.com/wiki/develop/api/openapi/api_permissions/model.html diff --git a/openapi_richobj.go b/openapi_richobj.go new file mode 100644 index 0000000..16aa644 --- /dev/null +++ b/openapi_richobj.go @@ -0,0 +1,3 @@ +package nano + +// https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_threads_list.html