Skip to content

Commit c3dc596

Browse files
author
casonli
committed
sdk:精华消息接口和推荐子频道类型公告接口 (merge request !32)
Squash merge branch 'feature_20220225_casonli_pins_story_872022903' into 'master' 精华消息接口和推荐子频道类型公告接口
1 parent cdd9ce8 commit c3dc596

File tree

7 files changed

+176
-7
lines changed

7 files changed

+176
-7
lines changed

dto/announces.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package dto
22

33
// Announces 公告对象
44
type Announces struct {
5-
// 频道ID
5+
// 频道 ID
66
GuildID string `json:"guild_id"`
7-
// 子频道id
7+
// 子频道 ID
88
ChannelID string `json:"channel_id"`
9-
// 用来创建公告的消息ID
9+
// 用来创建公告的消息 ID
1010
MessageID string `json:"message_id"`
11+
// 公告类别 0:成员公告,1:欢迎公告,默认为成员公告
12+
AnnouncesType uint32 `json:"announces_type"`
13+
// 推荐子频道详情数组
14+
RecommendChannels []RecommendChannel `json:"recommend_channels,omitempty"`
1115
}
1216

1317
// ChannelAnnouncesToCreate 创建子频道公告结构体定义
@@ -17,6 +21,14 @@ type ChannelAnnouncesToCreate struct {
1721

1822
// GuildAnnouncesToCreate 创建频道全局公告结构体定义
1923
type GuildAnnouncesToCreate struct {
20-
ChannelID string `json:"channel_id"` // 用来创建公告的子频道ID
21-
MessageID string `json:"message_id"` // 用来创建公告的消息ID
24+
ChannelID string `json:"channel_id"` // 用来创建公告的子频道 ID
25+
MessageID string `json:"message_id"` // 用来创建公告的消息 ID
26+
AnnouncesType uint32 `json:"announces_type"` // 公告类别 0:成员公告,1:欢迎公告,默认为成员公告
27+
RecommendChannels []RecommendChannel `json:"recommend_channels"` // 推荐子频道详情列表
28+
}
29+
30+
// RecommendChannel 推荐子频道详情
31+
type RecommendChannel struct {
32+
ChannelID string `json:"channel_id"` // 子频道 ID
33+
Introduce string `json:"introduce"` // 推荐语
2234
}

dto/pins.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dto
2+
3+
// PinsMessage 精华消息对象
4+
type PinsMessage struct {
5+
// 频道 ID
6+
GuildID string `json:"guild_id"`
7+
// 子频道 ID
8+
ChannelID string `json:"channel_id"`
9+
// 消息 ID 数组
10+
MessageIDs []string `json:"message_ids"`
11+
}

examples/apitest/announces_test.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestAnnounces(t *testing.T) {
4040
},
4141
)
4242
t.Run(
43-
"clean channel announce no check messageID", func(t *testing.T) {
43+
"clean channel announce no check message id", func(t *testing.T) {
4444
time.Sleep(3 * time.Second)
4545
err := api.CleanChannelAnnounces(ctx, testChannelID)
4646
if err != nil {
@@ -63,6 +63,34 @@ func TestAnnounces(t *testing.T) {
6363
t.Logf("announces:%+v", announces)
6464
},
6565
)
66+
t.Run(
67+
"create recommend channel guild announce", func(t *testing.T) {
68+
time.Sleep(3 * time.Second)
69+
announces, err := api.CreateGuildAnnounces(
70+
ctx, testGuildID, &dto.GuildAnnouncesToCreate{
71+
AnnouncesType: 0,
72+
RecommendChannels: []dto.RecommendChannel{
73+
{
74+
ChannelID: "1146349",
75+
Introduce: "子频道 1146349 欢迎语",
76+
},
77+
{
78+
ChannelID: "1703191",
79+
Introduce: "子频道 1703191 欢迎语",
80+
},
81+
{
82+
ChannelID: "2651556",
83+
Introduce: "子频道 2651556 欢迎语",
84+
},
85+
},
86+
},
87+
)
88+
if err != nil {
89+
t.Error(err)
90+
}
91+
t.Logf("announces:%+v", announces)
92+
},
93+
)
6694
t.Run(
6795
"delete guild announce", func(t *testing.T) {
6896
time.Sleep(3 * time.Second)
@@ -72,7 +100,7 @@ func TestAnnounces(t *testing.T) {
72100
},
73101
)
74102
t.Run(
75-
"clean guild announce no check messageID", func(t *testing.T) {
103+
"clean guild announce no check message id", func(t *testing.T) {
76104
time.Sleep(3 * time.Second)
77105
err := api.CleanGuildAnnounces(ctx, testGuildID)
78106
if err != nil {

examples/apitest/pins_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package apitest
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestPins(t *testing.T) {
9+
10+
t.Run(
11+
"add pins", func(t *testing.T) {
12+
pins, err := api.AddPins(
13+
ctx, testChannelID, testMessageID,
14+
)
15+
if err != nil {
16+
t.Error(err)
17+
}
18+
t.Logf("pins:%+v", pins)
19+
},
20+
)
21+
t.Run(
22+
"get pins", func(t *testing.T) {
23+
time.Sleep(3 * time.Second)
24+
pins, err := api.GetPins(ctx, testChannelID)
25+
if err != nil {
26+
t.Error(err)
27+
}
28+
t.Logf("pins:%+v", pins)
29+
30+
},
31+
)
32+
t.Run(
33+
"delete pins", func(t *testing.T) {
34+
time.Sleep(3 * time.Second)
35+
err := api.DeletePins(ctx, testChannelID, testMessageID)
36+
if err != nil {
37+
t.Error(err)
38+
}
39+
},
40+
)
41+
t.Run(
42+
"clean pins no check message id", func(t *testing.T) {
43+
time.Sleep(3 * time.Second)
44+
err := api.CleanPins(ctx, testChannelID)
45+
if err != nil {
46+
t.Error(err)
47+
}
48+
},
49+
)
50+
}

openapi/iface.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type OpenAPI interface {
2424
AnnouncesAPI
2525
ScheduleAPI
2626
APIPermissionsAPI
27+
PinsAPI
2728
MessageReactionAPI
2829
}
2930

@@ -180,6 +181,18 @@ type APIPermissionsAPI interface {
180181
guildID string, demand *dto.APIPermissionDemandToCreate) (*dto.APIPermissionDemand, error)
181182
}
182183

184+
// PinsAPI 精华消息接口
185+
type PinsAPI interface {
186+
// AddPins 添加精华消息
187+
AddPins(ctx context.Context, channelID string, messageID string) (*dto.PinsMessage, error)
188+
// DeletePins 删除精华消息
189+
DeletePins(ctx context.Context, channelID, messageID string) error
190+
// CleanPins 清除全部精华消息
191+
CleanPins(ctx context.Context, channelID string) error
192+
// GetPins 获取精华消息
193+
GetPins(ctx context.Context, channelID string) (*dto.PinsMessage, error)
194+
}
195+
183196
// MessageReactionAPI 消息表情表态接口
184197
type MessageReactionAPI interface {
185198
// CreateMessageReaction 对消息发表表情表态

openapi/v1/pins.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package v1
2+
3+
import (
4+
"context"
5+
6+
"github.com/tencent-connect/botgo/dto"
7+
)
8+
9+
// AddPins 添加精华消息
10+
func (o *openAPI) AddPins(ctx context.Context, channelID string, messageID string) (*dto.PinsMessage, error) {
11+
resp, err := o.request(ctx).
12+
SetResult(dto.PinsMessage{}).
13+
SetPathParam("channel_id", channelID).
14+
SetPathParam("message_id", messageID).
15+
Put(o.getURL(pinURI))
16+
if err != nil {
17+
return nil, err
18+
}
19+
return resp.Result().(*dto.PinsMessage), nil
20+
}
21+
22+
// DeletePins 删除精华消息
23+
func (o *openAPI) DeletePins(ctx context.Context, channelID, messageID string) error {
24+
_, err := o.request(ctx).
25+
SetResult(dto.PinsMessage{}).
26+
SetPathParam("channel_id", channelID).
27+
SetPathParam("message_id", messageID).
28+
Delete(o.getURL(pinURI))
29+
return err
30+
}
31+
32+
// GetPins 获取精华消息
33+
func (o *openAPI) GetPins(ctx context.Context, channelID string) (*dto.PinsMessage, error) {
34+
resp, err := o.request(ctx).
35+
SetResult(dto.PinsMessage{}).
36+
SetPathParam("channel_id", channelID).
37+
Get(o.getURL(pinsURI))
38+
if err != nil {
39+
return nil, err
40+
}
41+
return resp.Result().(*dto.PinsMessage), nil
42+
}
43+
44+
// CleanPins 清除全部精华消息
45+
func (o *openAPI) CleanPins(ctx context.Context, channelID string) error {
46+
_, err := o.request(ctx).
47+
SetResult(dto.PinsMessage{}).
48+
SetPathParam("channel_id", channelID).
49+
SetPathParam("message_id", "all").
50+
Delete(o.getURL(pinURI))
51+
return err
52+
}

openapi/v1/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const (
5757
apiPermissionURI uri = "/guilds/{guild_id}/api_permission"
5858
apiPermissionDemandURI uri = "/guilds/{guild_id}/api_permission/demand"
5959

60+
pinsURI = "/channels/{channel_id}/pins"
61+
pinURI = "/channels/{channel_id}/pins/{message_id}"
62+
6063
messageReactionURI uri = "/channels/{channel_id}/messages/{message_id}/reactions/{emoji_type}/{emoji_id}"
6164
)
6265

0 commit comments

Comments
 (0)