openapi

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 7 Imported by: 17

Documentation

Overview

Package openapi 声明了 sdk 所使用的 openapi 接口。

Index

Constants

View Source
const TraceIDKey = "X-Tps-trace-ID"

TraceIDKey 机器人openapi返回的链路追踪ID

Variables

View Source
var VersionMapping = map[APIVersion]OpenAPI{}

VersionMapping openapi 版本管理

Functions

func APIVersionString

func APIVersionString(version APIVersion) string

APIVersionString 返回version的字符串格式 ex: v1

func DoReqFilterChains

func DoReqFilterChains(req *http.Request, resp *http.Response) error

DoReqFilterChains 按照注册顺序执行请求过滤器

func DoRespFilterChains

func DoRespFilterChains(req *http.Request, resp *http.Response) error

DoRespFilterChains 按照注册顺序执行返回过滤器

func IsSuccessStatus

func IsSuccessStatus(code int) bool

IsSuccessStatus 是否是成功的状态码

func Register

func Register(version APIVersion, api OpenAPI)

Register 注册 openapi 的实现,如果默认实现为空,则将第一个注册的设置为默认实现

func RegisterReqFilter

func RegisterReqFilter(name string, filter HTTPFilter)

RegisterReqFilter 注册请求过滤器

func RegisterRespFilter

func RegisterRespFilter(name string, filter HTTPFilter)

RegisterRespFilter 注册返回过滤器

Types

type APIPermissionsAPI

type APIPermissionsAPI interface {
	// GetAPIPermissions 获取频道可用权限列表
	GetAPIPermissions(ctx context.Context, guildID string) (*dto.APIPermissions, error)
	// RequireAPIPermissions 创建频道 API 接口权限授权链接
	RequireAPIPermissions(ctx context.Context,
		guildID string, demand *dto.APIPermissionDemandToCreate) (*dto.APIPermissionDemand, error)
}

APIPermissionsAPI api 权限相关接口

type APIVersion

type APIVersion = uint32

APIVersion 接口版本

const (
	APIv1 APIVersion = 1 + iota
)

接口版本,后续增加版本直接直接增加新的常量

type AnnouncesAPI

type AnnouncesAPI interface {
	// CreateChannelAnnounces 创建子频道公告
	CreateChannelAnnounces(
		ctx context.Context,
		channelID string, announce *dto.ChannelAnnouncesToCreate,
	) (*dto.Announces, error)
	// DeleteChannelAnnounces 删除子频道公告,会校验 messageID 是否匹配
	DeleteChannelAnnounces(ctx context.Context, channelID, messageID string) error
	// CleanChannelAnnounces 删除子频道公告,不校验 messageID
	CleanChannelAnnounces(ctx context.Context, channelID string) error
	// CreateGuildAnnounces 创建频道全局公告
	CreateGuildAnnounces(
		ctx context.Context, guildID string,
		announce *dto.GuildAnnouncesToCreate,
	) (*dto.Announces, error)
	// DeleteGuildAnnounces 删除频道全局公告
	DeleteGuildAnnounces(ctx context.Context, guildID, messageID string) error
	// CleanGuildAnnounces 删除频道全局公告,不校验 messageID
	CleanGuildAnnounces(ctx context.Context, guildID string) error
}

AnnouncesAPI 公告相关接口

type AudioAPI

type AudioAPI interface {
	// PostAudio 执行音频播放,暂停等操作
	PostAudio(ctx context.Context, channelID string, value *dto.AudioControl) (*dto.AudioControl, error)
}

AudioAPI 音频接口

type Base

type Base interface {
	Version() APIVersion
	Setup(token *token.Token, inSandbox bool) OpenAPI
	// WithTimeout 设置请求接口超时时间
	WithTimeout(duration time.Duration) OpenAPI
	// Transport 透传请求,如果 sdk 没有及时跟进新的接口的变更,可以使用该方法进行透传,openapi 实现时可以按需选择是否实现该接口
	Transport(ctx context.Context, method, url string, body interface{}) ([]byte, error)
	// TraceID 返回上一次请求的 trace id
	TraceID() string
}

Base 基础能力接口

type ChannelAPI

type ChannelAPI interface {
	// Channel 拉取指定子频道信息
	Channel(ctx context.Context, channelID string) (*dto.Channel, error)
	// Channels 拉取子频道列表
	Channels(ctx context.Context, guildID string) ([]*dto.Channel, error)
	// PostChannel 创建子频道
	PostChannel(ctx context.Context, guildID string, value *dto.ChannelValueObject) (*dto.Channel, error)
	// PatchChannel 修改子频道
	PatchChannel(ctx context.Context, channelID string, value *dto.ChannelValueObject) (*dto.Channel, error)
	// DeleteChannel 删除指定子频道
	DeleteChannel(ctx context.Context, channelID string) error
	// CreatePrivateChannel 创建私密子频道
	CreatePrivateChannel(ctx context.Context,
		guildID string, value *dto.ChannelValueObject, userIds []string) (*dto.Channel, error)
	ListVoiceChannelMembers(ctx context.Context, channelID string) ([]*dto.Member, error)
}

ChannelAPI 频道相关接口

type ChannelPermissionsAPI

type ChannelPermissionsAPI interface {
	// ChannelPermissions 获取指定子频道的权限
	ChannelPermissions(ctx context.Context, channelID, userID string) (*dto.ChannelPermissions, error)
	// PutChannelPermissions 修改指定子频道的权限
	PutChannelPermissions(ctx context.Context, channelID, userID string, p *dto.UpdateChannelPermissions) error
	// ChannelRolesPermissions  获取指定子频道身份组的权限
	ChannelRolesPermissions(ctx context.Context, channelID, roleID string) (*dto.ChannelRolesPermissions, error)
	// PutChannelRolesPermissions 修改指定子频道身份组的权限
	PutChannelRolesPermissions(ctx context.Context, channelID, roleID string, p *dto.UpdateChannelPermissions) error
}

ChannelPermissionsAPI 子频道权限相关接口

type DirectMessageAPI

type DirectMessageAPI interface {
	// CreateDirectMessage 创建私信频道
	CreateDirectMessage(ctx context.Context, dm *dto.DirectMessageToCreate) (*dto.DirectMessage, error)
	// PostDirectMessage 在私信频道内发消息
	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)
}

DirectMessageAPI 信息相关接口

type GuildAPI

type GuildAPI interface {
	Guild(ctx context.Context, guildID string) (*dto.Guild, error)
	GuildMember(ctx context.Context, guildID, userID string) (*dto.Member, error)
	GuildMembers(ctx context.Context, guildID string, pager *dto.GuildMembersPager) ([]*dto.Member, error)
	DeleteGuildMember(ctx context.Context, guildID, userID string, opts ...dto.MemberDeleteOption) error
	// 频道禁言
	GuildMute(ctx context.Context, guildID string, mute *dto.UpdateGuildMute) error
}

GuildAPI guild 相关接口

type HTTPFilter

type HTTPFilter func(req *http.Request, response *http.Response) error

HTTPFilter 请求过滤器

type InteractionAPI added in v0.1.0

type InteractionAPI interface {
	// PutInteraction 更新互动信息
	PutInteraction(ctx context.Context, interactionID string, body string) error
}

InteractionAPI 互动接口

type MemberAPI

type MemberAPI interface {
	MemberAddRole(
		ctx context.Context,
		guildID string, roleID dto.RoleID, userID string, value *dto.MemberAddRoleBody,
	) error
	MemberDeleteRole(
		ctx context.Context,
		guildID string, roleID dto.RoleID, userID string, value *dto.MemberAddRoleBody,
	) error
	// MemberMute 频道指定单个成员禁言
	MemberMute(ctx context.Context, guildID, userID string, mute *dto.UpdateGuildMute) error
	// MultiMemberMute 频道指定批量成员禁言
	MultiMemberMute(ctx context.Context, guildID string,
		mute *dto.UpdateGuildMute) (*dto.UpdateGuildMuteResponse, error)
}

MemberAPI 成员相关接口,添加成员到用户组等

type MessageAPI

type MessageAPI interface {
	Message(ctx context.Context, channelID string, messageID string) (*dto.Message, error)
	Messages(ctx context.Context, channelID string, pager *dto.MessagesPager) ([]*dto.Message, error)
	PostMessage(ctx context.Context, channelID string, msg *dto.MessageToCreate) (*dto.Message, error)
	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)
}

MessageAPI 消息相关接口

type MessageReactionAPI

type MessageReactionAPI interface {
	// CreateMessageReaction 对消息发表表情表态
	CreateMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
	// DeleteOwnMessageReaction 删除自己的消息表情表态
	DeleteOwnMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
	// GetMessageReactionUsers 获取消息表情表态用户列表
	GetMessageReactionUsers(ctx context.Context, channelID, messageID string, emoji dto.Emoji,
		pager *dto.MessageReactionPager) (*dto.MessageReactionUsers, error)
}

MessageReactionAPI 消息表情表态接口

type MessageSettingAPI added in v0.1.5

type MessageSettingAPI interface {
	GetMessageSetting(ctx context.Context, guildID string) (*dto.MessageSetting, error)
}

MessageSettingAPI 频道消息设置接口

type PinsAPI

type PinsAPI interface {
	// AddPins 添加精华消息
	AddPins(ctx context.Context, channelID string, messageID string) (*dto.PinsMessage, error)
	// DeletePins 删除精华消息
	DeletePins(ctx context.Context, channelID, messageID string) error
	// CleanPins 清除全部精华消息
	CleanPins(ctx context.Context, channelID string) error
	// GetPins 获取精华消息
	GetPins(ctx context.Context, channelID string) (*dto.PinsMessage, error)
}

PinsAPI 精华消息接口

type RetractMessageOption added in v0.1.0

type RetractMessageOption int

RetractMessageOption 撤回消息可选参数

const (
	// RetractMessageOptionHidetip 撤回消息隐藏小灰条可选参数
	RetractMessageOptionHidetip RetractMessageOption = 1
)

type RoleAPI

type RoleAPI interface {
	Roles(ctx context.Context, guildID string) (*dto.GuildRoles, error)
	PostRole(ctx context.Context, guildID string, role *dto.Role) (*dto.UpdateResult, error)
	PatchRole(ctx context.Context, guildID string, roleID dto.RoleID, role *dto.Role) (*dto.UpdateResult, error)
	DeleteRole(ctx context.Context, guildID string, roleID dto.RoleID) error
}

RoleAPI 用户组相关接口

type ScheduleAPI

type ScheduleAPI interface {
	// ListSchedules 查询某个子频道下,since开始的当天的日程列表。若since为0,默认返回当天的日程列表
	ListSchedules(ctx context.Context, channelID string, since uint64) ([]*dto.Schedule, error)
	// GetSchedule 获取单个日程信息
	GetSchedule(ctx context.Context, channelID, scheduleID string) (*dto.Schedule, error)
	// CreateSchedule 创建日程
	CreateSchedule(ctx context.Context, channelID string, schedule *dto.Schedule) (*dto.Schedule, error)
	// ModifySchedule 修改日程
	ModifySchedule(ctx context.Context, channelID, scheduleID string, schedule *dto.Schedule) (*dto.Schedule, error)
	// DeleteSchedule 删除日程
	DeleteSchedule(ctx context.Context, channelID, scheduleID string) error
}

ScheduleAPI 日程相关接口

type UserAPI

type UserAPI interface {
	Me(ctx context.Context) (*dto.User, error)
	MeGuilds(ctx context.Context, pager *dto.GuildPager) ([]*dto.Guild, error)
}

UserAPI 用户相关接口

type WebhookAPI added in v0.1.0

type WebhookAPI interface {
	CreateSession(ctx context.Context, identity dto.HTTPIdentity) (*dto.HTTPReady, error)
	CheckSessions(ctx context.Context) ([]*dto.HTTPSession, error)
	SessionList(ctx context.Context) ([]*dto.HTTPSession, error)
	RemoveSession(ctx context.Context, sessionID string) error
}

WebhookAPI http 事件网关相关接口

type WebsocketAPI

type WebsocketAPI interface {
	WS(ctx context.Context, params map[string]string, body string) (*dto.WebsocketAP, error)
}

WebsocketAPI websocket 接入地址

Directories

Path Synopsis
Package v1 是 openapi v1 版本的实现。
Package v1 是 openapi v1 版本的实现。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL