Skip to content

Commit

Permalink
支持发送设置引导消息 (merge request !45)
Browse files Browse the repository at this point in the history
Squash merge branch 'feature_20220411_anezhou_msgsettingguide_story_873602243' into 'master'

TAPD: --story=873602243
  • Loading branch information
anezhou committed May 5, 2022
1 parent b208053 commit a319e10
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dto/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ type MarkdownParams struct {
type Keyboard struct {
ID string `json:"id"`
}

// SettingGuideToCreate 发送引导消息的结构体
type SettingGuideToCreate struct {
Content string `json:"content,omitempty"` // 频道内发引导消息可以带@
SettingGuide *SettingGuide `json:"setting_guide,omitempty"` // 设置引导
}

// SettingGuide 设置引导
type SettingGuide struct {
// 频道ID, 当通过私信发送设置引导消息时,需要指定guild_id
GuildID string `json:"guild_id"`
}
4 changes: 4 additions & 0 deletions openapi/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type MessageAPI interface {
PatchMessage(ctx context.Context,
channelID string, messageID string, msg *dto.MessageToCreate) (*dto.Message, error)
RetractMessage(ctx context.Context, channelID, msgID string, options ...RetractMessageOption) error
// PostSettingGuide 发送设置引导
PostSettingGuide(ctx context.Context, channelID string, atUserIDs []string) (*dto.Message, error)
}

// GuildAPI guild 相关接口
Expand Down Expand Up @@ -151,6 +153,8 @@ type DirectMessageAPI interface {
PostDirectMessage(ctx context.Context, dm *dto.DirectMessage, msg *dto.MessageToCreate) (*dto.Message, error)
// RetractDMMessage 撤回私信频道消息
RetractDMMessage(ctx context.Context, guildID, msgID string, options ...RetractMessageOption) error
// PostDMSettingGuide 发送私信设置引导, jumpGuildID为设置引导要跳转的频道ID
PostDMSettingGuide(ctx context.Context, dm *dto.DirectMessage, jumpGuildID string) (*dto.Message, error)
}

// AnnouncesAPI 公告相关接口
Expand Down
19 changes: 19 additions & 0 deletions openapi/v1/direct_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,22 @@ func (o *openAPI) RetractDMMessage(ctx context.Context,
_, err := request.Delete(o.getURL(dmsMessageURI))
return err
}

// PostDMSettingGuide 发送私信设置引导, jumpGuildID为设置引导要跳转的频道ID
func (o *openAPI) PostDMSettingGuide(ctx context.Context,
dm *dto.DirectMessage, jumpGuildID string) (*dto.Message, error) {
msg := &dto.SettingGuideToCreate{
SettingGuide: &dto.SettingGuide{
GuildID: jumpGuildID,
},
}
resp, err := o.request(ctx).
SetResult(dto.Message{}).
SetPathParam("guild_id", dm.GuildID).
SetBody(msg).
Post(o.getURL(dmSettingGuideURI))
if err != nil {
return nil, err
}
return resp.Result().(*dto.Message), nil
}
22 changes: 22 additions & 0 deletions openapi/v1/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
import (
"context"
"encoding/json"
"fmt"

"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/errs"
Expand Down Expand Up @@ -97,3 +98,24 @@ func (o *openAPI) RetractMessage(ctx context.Context,
_, err := request.Delete(o.getURL(messageURI))
return err
}

// PostSettingGuide 发送设置引导消息, atUserID为要at的用户
func (o *openAPI) PostSettingGuide(ctx context.Context,
channelID string, atUserIDs []string) (*dto.Message, error) {
var content string
for _, userID := range atUserIDs {
content += fmt.Sprintf("<@%s>", userID)
}
msg := &dto.SettingGuideToCreate{
Content: content,
}
resp, err := o.request(ctx).
SetResult(dto.Message{}).
SetPathParam("channel_id", channelID).
SetBody(msg).
Post(o.getURL(settingGuideURI))
if err != nil {
return nil, err
}
return resp.Result().(*dto.Message), nil
}
3 changes: 3 additions & 0 deletions openapi/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const (
messageSettingURI uri = "/guilds/{guild_id}/message/setting"

voiceChannelMembersURI uri = "/channels/{channel_id}/voice/members"

settingGuideURI uri = "/channels/{channel_id}/settingguide"
dmSettingGuideURI uri = "/dms/{guild_id}/settingguide"
)

// getURL 获取接口地址,会处理沙箱环境判断
Expand Down

0 comments on commit a319e10

Please sign in to comment.