client

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiscordApiURL = "https://discord.com/api/v10"
)
View Source
const DiscordAuthorizationUrl = "https://discordapp.com/api/oauth2/authorize"

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveThreadsResponse

type ActiveThreadsResponse struct {
	Threads       []discord.Channel      `json:"threads"`
	ThreadMembers []discord.ThreadMember `json:"members"`
}

type ApplicationClient added in v1.1.0

type ApplicationClient struct {
	ApplicationId discord.Snowflake
	Bot           *BotClient
}

func (*ApplicationClient) MakeRequest added in v1.1.0

func (appClient *ApplicationClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

func (*ApplicationClient) RegisterCommand added in v1.1.0

func (appClient *ApplicationClient) RegisterCommand(cmds CreateApplicationCommand) error

func (*ApplicationClient) RegisterCommands added in v1.1.0

func (appClient *ApplicationClient) RegisterCommands(cmds []CreateApplicationCommand) error

type AuthorizedUser

type AuthorizedUser struct {
	RefreshToken string
	AccessToken  string
	ExpiresIn    int
	Scopes       []oauth_scopes.OAuthScope
	Client       *http.Client
	OAuthClient  *OAuthClient
}

func NewAuthorizedUser

func NewAuthorizedUser(oauthClient *OAuthClient, refreshToken string, accessToken string, expiresIn int, scopes []oauth_scopes.OAuthScope) *AuthorizedUser

func (*AuthorizedUser) FetchGuilds

func (authedUser *AuthorizedUser) FetchGuilds() ([]discord.Guild, error)

func (*AuthorizedUser) FetchUser

func (authedUser *AuthorizedUser) FetchUser() (*discord.User, error)

func (*AuthorizedUser) MakeRequest

func (authedUser *AuthorizedUser) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

func (*AuthorizedUser) RefreshTokens

func (authedUser *AuthorizedUser) RefreshTokens() error

func (*AuthorizedUser) RevokeTokens

func (authedUser *AuthorizedUser) RevokeTokens() error

type BotClient

type BotClient struct {
	Token  string
	Client *http.Client
}

func NewBot

func NewBot(token string) *BotClient

func (*BotClient) GetApplicationClient added in v1.1.0

func (botClient *BotClient) GetApplicationClient(appId discord.Snowflake) *ApplicationClient

func (*BotClient) GetChannelClient

func (botClient *BotClient) GetChannelClient(channelId discord.Snowflake) *ChannelClient

func (*BotClient) GetGuildClient

func (botClient *BotClient) GetGuildClient(guildId discord.Snowflake) *GuildClient

func (*BotClient) GetSelfUserClient

func (botClient *BotClient) GetSelfUserClient() *UserClient

func (*BotClient) GetSelfUserID

func (botClient *BotClient) GetSelfUserID() discord.Snowflake

func (*BotClient) GetUserClient

func (botClient *BotClient) GetUserClient(userId discord.Snowflake) *UserClient

func (*BotClient) MakeRequest

func (botClient *BotClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

type ChannelClient

type ChannelClient struct {
	ChannelId discord.Snowflake
	Bot       *BotClient
}

func (*ChannelClient) AddThreadMember

func (channelClient *ChannelClient) AddThreadMember(userId discord.Snowflake) error

func (*ChannelClient) CreateThread

func (channelClient *ChannelClient) CreateThread(threadData CreateThreadData) (*discord.Channel, error)

func (*ChannelClient) Edit

func (channelClient *ChannelClient) Edit(data ModifyChannelData) (*discord.Channel, error)

func (*ChannelClient) EditMessage

func (channelClient *ChannelClient) EditMessage(messageId discord.Snowflake, editData discord.ResponseEditData) (*discord.Message, error)

func (*ChannelClient) FetchChannel

func (channelClient *ChannelClient) FetchChannel() (*discord.Channel, error)

func (*ChannelClient) GetThreadMember

func (channelClient *ChannelClient) GetThreadMember(request GetThreadMemberRequest) (*discord.ThreadMember, error)

func (*ChannelClient) JoinThread

func (channelClient *ChannelClient) JoinThread() error

func (*ChannelClient) LeaveThread

func (channelClient *ChannelClient) LeaveThread() error

func (*ChannelClient) ListThreadMembers

func (channelClient *ChannelClient) ListThreadMembers(request ListThreadMemberRequest) ([]discord.ThreadMember, error)

func (*ChannelClient) MakeRequest

func (channelClient *ChannelClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

func (*ChannelClient) RemoveThreadMember

func (channelClient *ChannelClient) RemoveThreadMember(userId discord.Snowflake) error

func (*ChannelClient) SendMessage

func (channelClient *ChannelClient) SendMessage(messageData SendMessageData) (*discord.Message, error)

type CreateApplicationCommand added in v1.1.0

type CreateApplicationCommand struct {
	Name                     string                             `json:"name"`
	NameLocalizations        map[string]string                  `json:"name_localizations,omitempty"`
	Description              *string                            `json:"description,omitempty"`
	DescriptionLocalizations map[string]string                  `json:"description_localizations,omitempty"`
	Options                  []discord.ApplicationCommandOption `json:"options,omitempty"`
	DefaultMemberPermissions *string                            `json:"default_member_permissions,omitempty"`
	DMPermission             *bool                              `json:"dm_permission,omitempty"`
	DefaultPermission        *bool                              `json:"default_permission,omitempty"`
	IntegrationTypes         []string                           `json:"integration_types,omitempty"`
	Contexts                 []string                           `json:"contexts,omitempty"`
	Type                     *int                               `json:"type,omitempty"`
	NSFW                     *bool                              `json:"nsfw,omitempty"`
}

type CreateThreadData

type CreateThreadData struct {
	Name string `json:"name"`

	// Seconds
	AutoArchiveDuration *int `json:"auto_archive_duration,omitempty"`

	//  Valid types: AnnouncementThread, PublicThread, PrivateThread
	Type channel_type.ChannelType `json:"type"`

	// Whether non-mods can invite (only if private thread)
	Invitable *bool `json:"invitable,omitempty"`

	// Seconds
	RateLimit *int `json:"rate_limit_per_user,omitempty"`

	Reason *string `json:"-"` // Audit log reason, optional
}

type DiscordRequest

type DiscordRequest struct {
	ExpectedStatus int
	Method         string
	Endpoint       string
	Body           []byte

	UnmarshalTo interface{}

	DisableAuth        bool
	DisableStatusCheck bool
	AdditionalHeaders  map[string]string
}

func (*DiscordRequest) GetUrl

func (discordRequest *DiscordRequest) GetUrl() string

func (*DiscordRequest) ValidateEndpoint

func (discordRequest *DiscordRequest) ValidateEndpoint()

type GetThreadMemberRequest

type GetThreadMemberRequest struct {
	UserId discord.Snowflake
	// Whether to request a "member" object in the ThreadMember response, requires GUILD_MEMBERS
	WithMember bool
}

type GuildClient

type GuildClient struct {
	GuildId discord.Snowflake
	Bot     *BotClient
}

func (*GuildClient) FetchGuild

func (guildClient *GuildClient) FetchGuild(withCounts bool) (*discord.Guild, error)

func (*GuildClient) GetActiveThreads

func (guildClient *GuildClient) GetActiveThreads() (ActiveThreadsResponse, error)

func (*GuildClient) GetChannels

func (guildClient *GuildClient) GetChannels() ([]discord.Channel, error)

func (*GuildClient) GetMemberClient

func (guildClient *GuildClient) GetMemberClient(memberId discord.Snowflake) *MemberClient

func (*GuildClient) JoinUserToGuild

func (guildClient *GuildClient) JoinUserToGuild(authedUser *AuthorizedUser, userId discord.Snowflake, guildId discord.Snowflake) (err error)

func (*GuildClient) ListMembers

func (guildClient *GuildClient) ListMembers(request ListMembersRequest) ([]discord.Member, error)

func (*GuildClient) MakeRequest

func (guildClient *GuildClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

type JoinUserToGuildRequest

type JoinUserToGuildRequest struct {
	AccessToken string              `json:"access_token"`
	Nick        string              `json:"nick,omitempty"`
	Roles       []discord.Snowflake `json:"roles,omitempty"`
	Mute        bool                `json:"mute,omitempty"`
	Deaf        bool                `json:"deaf,omitempty"`
}

type ListMembersRequest

type ListMembersRequest struct {
	// The last member fetched
	After *discord.Snowflake
	// Max members to fetch in one request
	Limit *int
}

type ListThreadMemberRequest

type ListThreadMemberRequest struct {
	// Whether to request a "member" object in the ThreadMember response, requires GUILD_MEMBERS privileged intent
	WithMember bool
	// The last member fetched
	After *discord.Snowflake
	// Max members to fetch in one request
	Limit *int
}

type MemberClient

type MemberClient struct {
	MemberId    discord.Snowflake
	GuildClient *GuildClient
}

func (*MemberClient) AddRoleToMember

func (memberClient *MemberClient) AddRoleToMember(opts ModifyMemberRoleOpts) error

func (*MemberClient) FetchMember

func (memberClient *MemberClient) FetchMember() (*discord.Member, error)

func (*MemberClient) MakeRequest

func (memberClient *MemberClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

type ModifyChannelData

type ModifyChannelData interface {
	ToJson() ([]byte, error)
	GetReason() *string
}

type ModifyGroupDMChannelData

type ModifyGroupDMChannelData struct {
	Name      *string `json:"name,omitempty"`
	IconBytes []byte  `json:"-"`
	Icon      *string `json:"icon,omitempty"`

	Reason *string `json:"-"` // Audit log reason, optional
}

func (ModifyGroupDMChannelData) GetReason

func (modifyData ModifyGroupDMChannelData) GetReason() *string

func (ModifyGroupDMChannelData) ToJson

func (modifyData ModifyGroupDMChannelData) ToJson() ([]byte, error)

type ModifyGuildChannelData

type ModifyGuildChannelData struct {
	Name *string `json:"name,omitempty"`
	// Can only switch between text and announcement channels
	Type     *channel_type.ChannelType `json:"type,omitempty"`
	Position *int                      `json:"position,omitempty"`
	Topic    *string                   `json:"topic,omitempty"`
	NSFW     *bool                     `json:"nsfw,omitempty"`
	// Slow-mode (in seconds)
	RateLimit *int `json:"rate_limit_per_user,omitempty"`

	// Voice Channels Only:
	Bitrate          *int    `json:"bitrate,omitempty"`
	UserLimit        *int    `json:"user_limit,omitempty"`
	RtcRegion        *string `json:"rtc_region,omitempty"`
	VideoQualityMode *int    `json:"video_quality_mode,omitempty"`

	// Default archive duration for user-created threads (in minutes), supports: 60, 1440, 4320, 10080
	DefaultAutoArchiveDuration *int `json:"default_auto_archive_duration,omitempty"`
	// Slow-mode (in seconds)
	DefaultThreadRateLimit *int                `json:"default_thread_rate_limit_per_user,omitempty"`
	PermissionOverwrites   []discord.Overwrite `json:"permission_overwrites,omitempty"`
	// Category ID
	ParentId *discord.Snowflake `json:"parent_id,omitempty"`

	// Forums Only:
	// Only supports REQUIRE_TAG (1<<4)
	Flags                *int                     `json:"flags,omitempty"`
	AvailableTags        []discord.Tag            `json:"available_tags,omitempty"`
	DefaultReactionEmoji *discord.DefaultReaction `json:"default_reaction_emoji,omitempty"`
	DefaultSortOrder     *int                     `json:"default_sort_order,omitempty"`
	DefaultForumLayout   *int                     `json:"default_forum_layout,omitempty"`

	Reason *string `json:"-"` // Audit log reason, optional
}

func (ModifyGuildChannelData) GetReason

func (modifyData ModifyGuildChannelData) GetReason() *string

func (ModifyGuildChannelData) ToJson

func (modifyData ModifyGuildChannelData) ToJson() ([]byte, error)

type ModifyMemberRoleOpts

type ModifyMemberRoleOpts struct {
	RoleID discord.Snowflake

	Reason string
}

type ModifyThreadData

type ModifyThreadData struct {
	Name     *string `json:"name,omitempty"`
	Archived *bool   `json:"archived,omitempty"`
	// Minutes, only supports: 60, 1440, 4320, 10080
	AutoArchiveDuration *int  `json:"auto_archive_duration,omitempty"`
	Locked              *bool `json:"locked,omitempty"`
	Invitable           *bool `json:"invitable,omitempty"`
	// Slow-mode (in seconds)
	RateLimit *int `json:"rate_limit_per_user,omitempty"`

	Flags       *int          `json:"flags,omitempty"`
	AppliedTags []discord.Tag `json:"applied_tags,omitempty"`

	Reason *string `json:"-"` // Audit log reason, optional
}

func (ModifyThreadData) GetReason

func (modifyData ModifyThreadData) GetReason() *string

func (ModifyThreadData) ToJson

func (modifyData ModifyThreadData) ToJson() ([]byte, error)

type OAuthClient

type OAuthClient struct {
	ClientId     string
	ClientSecret string
	Client       *http.Client
	// contains filtered or unexported fields
}

func NewOAuthClient

func NewOAuthClient(clientId string, clientSecret string, redirectUri string) *OAuthClient

func (*OAuthClient) AuthorizeUserFromCode

func (oauthClient *OAuthClient) AuthorizeUserFromCode(code string) (*AuthorizedUser, error)

func (*OAuthClient) BuildAuthorizationURL

func (oauthClient *OAuthClient) BuildAuthorizationURL(scopes []oauth_scopes.OAuthScope, state string) string

func (*OAuthClient) MakeRequest

func (oauthClient *OAuthClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

func (*OAuthClient) RefreshTokensForUser

func (oauthClient *OAuthClient) RefreshTokensForUser(refreshToken string) (tokenResponse *TokenResponse, err error)

func (*OAuthClient) RevokeTokensForUser

func (oauthClient *OAuthClient) RevokeTokensForUser(accessToken string) (err error)

type RevokeTokenRequest

type RevokeTokenRequest struct {
	Token         string `json:"token"`
	TokenTypeHint string `json:"token_type_hint"`
	ClientId      string `json:"client_id"`
	ClientSecret  string `json:"client_secret"`
}

func (*RevokeTokenRequest) ToString

func (r *RevokeTokenRequest) ToString() string

func (*RevokeTokenRequest) ToValues

func (r *RevokeTokenRequest) ToValues() url.Values

type SendMessageData

type SendMessageData struct {
	Content         *string                  `json:"content,omitempty"`
	TTS             *bool                    `json:"tts,omitempty"`
	Embeds          []discord.Embed          `json:"embeds,omitempty"`
	AllowedMentions *discord.AllowedMentions `json:"allowed_mentions,omitempty"`
	// Channel ID optional
	MessageReference *discord.MessageReference  `json:"message_reference,omitempty"`
	Components       []discord.MessageComponent `json:"components,omitempty"`
	StickerIds       []discord.Snowflake        `json:"sticker_ids,omitempty"`
	Attachments      []discord.Attachment       `json:"attachments,omitempty"`
	// Only supports "SUPPRESS_EMBEDS" (1<<2) and "SUPPRESS_NOTIFICATIONS" (1<<12)
	Flags *int `json:"flags,omitempty"`
}

type ThreadType

type ThreadType uint8

type TokenGrantType

type TokenGrantType string
const (
	GrantTypeAuthorizationCode TokenGrantType = "authorization_code"
	GrantTypeRefreshToken      TokenGrantType = "refresh_token"
)

type TokenRequest

type TokenRequest struct {
	GrantType    TokenGrantType `json:"grant_type"`
	Code         string         `json:"code,omitempty"`
	RedirectUri  string         `json:"redirect_uri,omitempty"`
	RefreshToken string         `json:"refresh_token,omitempty"`
	ClientId     string         `json:"client_id,omitempty"`
	ClientSecret string         `json:"client_secret,omitempty"`
}

func (*TokenRequest) ToString

func (t *TokenRequest) ToString() string

func (*TokenRequest) ToValues

func (t *TokenRequest) ToValues() url.Values

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
}

func (*TokenResponse) ToAuthorizedUser

func (response *TokenResponse) ToAuthorizedUser(client *OAuthClient) *AuthorizedUser

type UserClient

type UserClient struct {
	UserId discord.Snowflake
	Bot    *BotClient
}

func (*UserClient) CreateDMChannel

func (userClient *UserClient) CreateDMChannel() (*discord.Channel, error)

func (*UserClient) GetIdAsString

func (userClient *UserClient) GetIdAsString() string

func (*UserClient) MakeRequest

func (userClient *UserClient) MakeRequest(discordRequest DiscordRequest) (response *http.Response, err error)

func (*UserClient) SendMessage

func (userClient *UserClient) SendMessage(messageData SendMessageData) (*discord.Message, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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