github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/openapi_forum.go (about)

     1  package nano
     2  
     3  import "time"
     4  
     5  // Thread 话题频道内发表的主帖称为主题
     6  //
     7  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#thread
     8  type Thread struct {
     9  	GuildID    string      `json:"guild_id"`
    10  	ChannelID  string      `json:"channel_id"`
    11  	AuthorID   string      `json:"author_id"`
    12  	ThreadInfo *ThreadInfo `json:"thread_info"`
    13  }
    14  
    15  // ThreadInfo 帖子事件包含的主帖内容相关信息
    16  //
    17  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#threadinfo
    18  type ThreadInfo struct {
    19  	ThreadID string    `json:"thread_id"`
    20  	Title    string    `json:"title"`
    21  	Content  string    `json:"content"`
    22  	DateTime time.Time `json:"date_time"`
    23  }
    24  
    25  // Post 话题频道内对主题的评论称为帖子
    26  //
    27  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#post
    28  type Post struct {
    29  	GuildID   string    `json:"guild_id"`
    30  	ChannelID string    `json:"channel_id"`
    31  	AuthorID  string    `json:"author_id"`
    32  	PostInfo  *PostInfo `json:"post_info"`
    33  }
    34  
    35  // PostInfo 帖子事件包含的帖子内容信息
    36  //
    37  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#postinfo
    38  type PostInfo struct {
    39  	ThreadID string    `json:"thread_id"`
    40  	PostID   string    `json:"post_id"`
    41  	Content  string    `json:"content"`
    42  	DateTime time.Time `json:"date_time"`
    43  }
    44  
    45  // Reply 话题频道对帖子回复或删除时生产该事件中包含该对象
    46  //
    47  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#reply
    48  type Reply struct {
    49  	GuildID   string     `json:"guild_id"`
    50  	ChannelID string     `json:"channel_id"`
    51  	AuthorID  string     `json:"author_id"`
    52  	ReplyInfo *ReplyInfo `json:"reply_info"`
    53  }
    54  
    55  // ReplyInfo 回复事件包含的回复内容信息
    56  //
    57  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#replyinfo
    58  type ReplyInfo struct {
    59  	ThreadID string    `json:"thread_id"`
    60  	PostID   string    `json:"post_id"`
    61  	ReplyID  string    `json:"reply_id"`
    62  	Content  string    `json:"content"`
    63  	DateTime time.Time `json:"date_time"`
    64  }
    65  
    66  // AuditResult 论坛帖子审核结果事件
    67  //
    68  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#auditresult
    69  type AuditResult struct {
    70  	GuildID   string `json:"guild_id"`
    71  	ChannelID string `json:"channel_id"`
    72  	AuthorID  string `json:"author_id"`
    73  	ThreadID  string `json:"thread_id"`
    74  	PostID    string `json:"post_id"`
    75  	ReplyID   string `json:"reply_id"`
    76  	Type      uint32 `json:"type"`
    77  	Result    uint32 `json:"result"`
    78  	ErrMsg    string `json:"err_msg"`
    79  }
    80  
    81  // GetChannelThreads 获取子频道下的帖子列表
    82  //
    83  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_threads_list.html
    84  func (bot *Bot) GetChannelThreads(id string) (threads []Thread, isfinish bool, err error) {
    85  	resp := &struct {
    86  		CodeMessageBase
    87  		T []Thread `json:"threads"`
    88  		I uint32   `json:"is_finish"`
    89  	}{}
    90  	err = bot.GetOpenAPI("/channels/"+id+"/threads", "", resp)
    91  	threads = resp.T
    92  	isfinish = resp.I > 0
    93  	return
    94  }
    95  
    96  // GetThreadInfo 获取子频道下的帖子详情
    97  //
    98  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_thread.html
    99  func (bot *Bot) GetThreadInfo(channelid, threadid string) (*ThreadInfo, error) {
   100  	resp := &struct {
   101  		CodeMessageBase
   102  		T ThreadInfo `json:"thread"`
   103  	}{}
   104  	err := bot.GetOpenAPI("/channels/"+channelid+"/threads/"+threadid, "", resp)
   105  	return &resp.T, err
   106  }
   107  
   108  // PostThread 发表帖子
   109  //
   110  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/put_thread.html
   111  func (bot *Bot) PostThreadInChannel(id string, title string, content string, format uint32) (taskid string, createtime string, err error) {
   112  	resp := &struct {
   113  		CodeMessageBase
   114  		T string `json:"task_id"`
   115  		C string `json:"create_time"`
   116  	}{}
   117  	err = bot.PutOpenAPI("/channels/"+id+"/threads", "", resp, WriteBodyFromJSON(&struct {
   118  		T string `json:"title"`
   119  		C string `json:"content"`
   120  		F uint32 `json:"format"`
   121  	}{title, content, format}))
   122  	taskid = resp.T
   123  	createtime = resp.C
   124  	return
   125  }
   126  
   127  // DeleteThreadInChannel 删除指定子频道下的某个帖子
   128  //
   129  // https://bot.q.qq.com/wiki/develop/api/openapi/forum/delete_thread.html
   130  func (bot *Bot) DeleteThreadInChannel(channelid, threadid string) error {
   131  	return bot.DeleteOpenAPI("/channels/"+channelid+"/threads/"+threadid, "", nil)
   132  }