-
Notifications
You must be signed in to change notification settings - Fork 5
/
openapi_forum.go
132 lines (120 loc) · 4.08 KB
/
openapi_forum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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)
}