-
Notifications
You must be signed in to change notification settings - Fork 5
/
openapi_schedule.go
65 lines (59 loc) · 2.74 KB
/
openapi_schedule.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
package nano
// Schedule 日程对象
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/model.html
type Schedule struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
StartTimestamp string `json:"start_timestamp,omitempty"`
EndTimestamp string `json:"end_timestamp,omitempty"`
Creator *Member `json:"creator,omitempty"`
JumpChannelID string `json:"jump_channel_id,omitempty"`
RemindType string `json:"remind_type,omitempty"` // https://bot.q.qq.com/wiki/develop/api/openapi/schedule/model.html#remindtype
}
// GetChannelSchedules 获取channel_id指定的子频道中当天的日程列表
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedules.html
func (bot *Bot) GetChannelSchedules(id string, since uint64) (schedules []Schedule, err error) {
if since == 0 {
err = bot.GetOpenAPI("/channels/"+id+"/schedules", "", &schedules)
} else {
err = bot.GetOpenAPIWithBody("/channels/"+id+"/schedules", "", &schedules, WriteBodyFromJSON(&struct {
S uint64 `json:"since"`
}{since}))
}
return
}
// GetScheduleInChannel 获取日程子频道 channel_id 下 schedule_id 指定的的日程的详情
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedule.html
func (bot *Bot) GetScheduleInChannel(channelid string, scheduleid string) (*Schedule, error) {
return bot.getOpenAPIofSchedule("/channels/" + channelid + "/schedules/" + scheduleid)
}
// CreateScheduleInChannel 在 channel_id 指定的日程子频道下创建一个日程
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/post_schedule.html
//
// schedule 会被写入返回的对象
func (bot *Bot) CreateScheduleInChannel(id string, schedule *Schedule) error {
return bot.PostOpenAPI("/channels/"+id+"/schedules", "", schedule, WriteBodyFromJSON(&struct {
S *Schedule `json:"schedule"`
}{schedule}))
}
// PatchScheduleInChannel 修改日程子频道 channel_id 下 schedule_id 指定的日程的详情
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/patch_schedule.html
//
// schedule 会被写入返回的对象
func (bot *Bot) PatchScheduleInChannel(channelid string, scheduleid string, schedule *Schedule) error {
return bot.PatchOpenAPI("/channels/"+channelid+"/schedules/"+scheduleid, "", schedule, WriteBodyFromJSON(&struct {
S *Schedule `json:"schedule"`
}{schedule}))
}
// DeleteScheduleInChannel 删除日程子频道 channel_id 下 schedule_id 指定的日程
//
// https://bot.q.qq.com/wiki/develop/api/openapi/schedule/delete_schedule.html
func (bot *Bot) DeleteScheduleInChannel(channelid string, scheduleid string) error {
return bot.DeleteOpenAPI("/channels/"+channelid+"/schedules/"+scheduleid, "", nil)
}