123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954 |
- package discordgo
- import (
- "encoding/json"
- "fmt"
- "net/http"
- "sync"
- "time"
- "github.com/gorilla/websocket"
- )
- type Session struct {
- sync.RWMutex
-
-
- Token string
- MFA bool
-
- Debug bool
- LogLevel int
-
- ShouldReconnectOnError bool
-
- Compress bool
-
- ShardID int
- ShardCount int
-
-
-
- StateEnabled bool
-
-
- SyncEvents bool
-
-
- DataReady bool
-
- MaxRestRetries int
-
-
- status int32
-
- VoiceReady bool
-
- UDPReady bool
-
- VoiceConnections map[string]*VoiceConnection
-
-
- State *State
-
- Client *http.Client
-
- LastHeartbeatAck time.Time
-
- Ratelimiter *RateLimiter
-
- handlersMu sync.RWMutex
- handlers map[string][]*eventHandlerInstance
- onceHandlers map[string][]*eventHandlerInstance
-
- wsConn *websocket.Conn
-
- listening chan interface{}
-
- sequence *int64
-
- gateway string
-
- sessionID string
-
- wsMutex sync.Mutex
- }
- type UserConnection struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Revoked bool `json:"revoked"`
- Integrations []*Integration `json:"integrations"`
- }
- type Integration struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Enabled bool `json:"enabled"`
- Syncing bool `json:"syncing"`
- RoleID string `json:"role_id"`
- ExpireBehavior int `json:"expire_behavior"`
- ExpireGracePeriod int `json:"expire_grace_period"`
- User *User `json:"user"`
- Account IntegrationAccount `json:"account"`
- SyncedAt Timestamp `json:"synced_at"`
- }
- type IntegrationAccount struct {
- ID string `json:"id"`
- Name string `json:"name"`
- }
- type VoiceRegion struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Hostname string `json:"sample_hostname"`
- Port int `json:"sample_port"`
- }
- type VoiceICE struct {
- TTL string `json:"ttl"`
- Servers []*ICEServer `json:"servers"`
- }
- type ICEServer struct {
- URL string `json:"url"`
- Username string `json:"username"`
- Credential string `json:"credential"`
- }
- type Invite struct {
- Guild *Guild `json:"guild"`
- Channel *Channel `json:"channel"`
- Inviter *User `json:"inviter"`
- Code string `json:"code"`
- CreatedAt Timestamp `json:"created_at"`
- MaxAge int `json:"max_age"`
- Uses int `json:"uses"`
- MaxUses int `json:"max_uses"`
- Revoked bool `json:"revoked"`
- Temporary bool `json:"temporary"`
- Unique bool `json:"unique"`
-
- ApproximatePresenceCount int `json:"approximate_presence_count"`
- ApproximateMemberCount int `json:"approximate_member_count"`
- }
- type ChannelType int
- const (
- ChannelTypeGuildText ChannelType = iota
- ChannelTypeDM
- ChannelTypeGuildVoice
- ChannelTypeGroupDM
- ChannelTypeGuildCategory
- )
- type Channel struct {
-
- ID string `json:"id"`
-
-
- GuildID string `json:"guild_id"`
-
- Name string `json:"name"`
-
- Topic string `json:"topic"`
-
- Type ChannelType `json:"type"`
-
-
- LastMessageID string `json:"last_message_id"`
-
- NSFW bool `json:"nsfw"`
-
- Icon string `json:"icon"`
-
- Position int `json:"position"`
-
- Bitrate int `json:"bitrate"`
-
- Recipients []*User `json:"recipients"`
-
-
- Messages []*Message `json:"-"`
-
- PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
-
- UserLimit int `json:"user_limit"`
-
- ParentID string `json:"parent_id"`
- }
- func (c *Channel) Mention() string {
- return fmt.Sprintf("<#%s>", c.ID)
- }
- type ChannelEdit struct {
- Name string `json:"name,omitempty"`
- Topic string `json:"topic,omitempty"`
- NSFW bool `json:"nsfw,omitempty"`
- Position int `json:"position"`
- Bitrate int `json:"bitrate,omitempty"`
- UserLimit int `json:"user_limit,omitempty"`
- PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
- ParentID string `json:"parent_id,omitempty"`
- }
- type PermissionOverwrite struct {
- ID string `json:"id"`
- Type string `json:"type"`
- Deny int `json:"deny"`
- Allow int `json:"allow"`
- }
- type Emoji struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Roles []string `json:"roles"`
- Managed bool `json:"managed"`
- RequireColons bool `json:"require_colons"`
- Animated bool `json:"animated"`
- }
- func (e *Emoji) APIName() string {
- if e.ID != "" && e.Name != "" {
- return e.Name + ":" + e.ID
- }
- if e.Name != "" {
- return e.Name
- }
- return e.ID
- }
- type VerificationLevel int
- const (
- VerificationLevelNone VerificationLevel = iota
- VerificationLevelLow
- VerificationLevelMedium
- VerificationLevelHigh
- )
- type ExplicitContentFilterLevel int
- const (
- ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
- ExplicitContentFilterMembersWithoutRoles
- ExplicitContentFilterAllMembers
- )
- type MfaLevel int
- const (
- MfaLevelNone MfaLevel = iota
- MfaLevelElevated
- )
- type Guild struct {
-
- ID string `json:"id"`
-
- Name string `json:"name"`
-
-
- Icon string `json:"icon"`
-
- Region string `json:"region"`
-
- AfkChannelID string `json:"afk_channel_id"`
-
- EmbedChannelID string `json:"embed_channel_id"`
-
- OwnerID string `json:"owner_id"`
-
-
-
- JoinedAt Timestamp `json:"joined_at"`
-
- Splash string `json:"splash"`
-
- AfkTimeout int `json:"afk_timeout"`
-
-
-
- MemberCount int `json:"member_count"`
-
- VerificationLevel VerificationLevel `json:"verification_level"`
-
- EmbedEnabled bool `json:"embed_enabled"`
-
-
-
- Large bool `json:"large"`
-
-
- DefaultMessageNotifications int `json:"default_message_notifications"`
-
- Roles []*Role `json:"roles"`
-
- Emojis []*Emoji `json:"emojis"`
-
-
-
- Members []*Member `json:"members"`
-
-
-
- Presences []*Presence `json:"presences"`
-
-
-
- Channels []*Channel `json:"channels"`
-
-
-
- VoiceStates []*VoiceState `json:"voice_states"`
-
-
-
- Unavailable bool `json:"unavailable"`
-
- ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
-
- Features []string `json:"features"`
-
- MfaLevel MfaLevel `json:"mfa_level"`
-
- WidgetEnabled bool `json:"widget_enabled"`
-
- WidgetChannelID string `json:"widget_channel_id"`
-
- SystemChannelID string `json:"system_channel_id"`
- }
- type UserGuild struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Icon string `json:"icon"`
- Owner bool `json:"owner"`
- Permissions int `json:"permissions"`
- }
- type GuildParams struct {
- Name string `json:"name,omitempty"`
- Region string `json:"region,omitempty"`
- VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
- DefaultMessageNotifications int `json:"default_message_notifications,omitempty"`
- AfkChannelID string `json:"afk_channel_id,omitempty"`
- AfkTimeout int `json:"afk_timeout,omitempty"`
- Icon string `json:"icon,omitempty"`
- OwnerID string `json:"owner_id,omitempty"`
- Splash string `json:"splash,omitempty"`
- }
- type Role struct {
-
- ID string `json:"id"`
-
- Name string `json:"name"`
-
-
- Managed bool `json:"managed"`
-
- Mentionable bool `json:"mentionable"`
-
- Hoist bool `json:"hoist"`
-
- Color int `json:"color"`
-
- Position int `json:"position"`
-
-
-
- Permissions int `json:"permissions"`
- }
- func (r *Role) Mention() string {
- return fmt.Sprintf("<@&%s>", r.ID)
- }
- type Roles []*Role
- func (r Roles) Len() int {
- return len(r)
- }
- func (r Roles) Less(i, j int) bool {
- return r[i].Position > r[j].Position
- }
- func (r Roles) Swap(i, j int) {
- r[i], r[j] = r[j], r[i]
- }
- type VoiceState struct {
- UserID string `json:"user_id"`
- SessionID string `json:"session_id"`
- ChannelID string `json:"channel_id"`
- GuildID string `json:"guild_id"`
- Suppress bool `json:"suppress"`
- SelfMute bool `json:"self_mute"`
- SelfDeaf bool `json:"self_deaf"`
- Mute bool `json:"mute"`
- Deaf bool `json:"deaf"`
- }
- type Presence struct {
- User *User `json:"user"`
- Status Status `json:"status"`
- Game *Game `json:"game"`
- Nick string `json:"nick"`
- Roles []string `json:"roles"`
- Since *int `json:"since"`
- }
- type GameType int
- const (
- GameTypeGame GameType = iota
- GameTypeStreaming
- GameTypeListening
- GameTypeWatching
- )
- type Game struct {
- Name string `json:"name"`
- Type GameType `json:"type"`
- URL string `json:"url,omitempty"`
- Details string `json:"details,omitempty"`
- State string `json:"state,omitempty"`
- TimeStamps TimeStamps `json:"timestamps,omitempty"`
- Assets Assets `json:"assets,omitempty"`
- ApplicationID string `json:"application_id,omitempty"`
- Instance int8 `json:"instance,omitempty"`
-
- }
- type TimeStamps struct {
- EndTimestamp int64 `json:"end,omitempty"`
- StartTimestamp int64 `json:"start,omitempty"`
- }
- func (t *TimeStamps) UnmarshalJSON(b []byte) error {
- temp := struct {
- End float64 `json:"end,omitempty"`
- Start float64 `json:"start,omitempty"`
- }{}
- err := json.Unmarshal(b, &temp)
- if err != nil {
- return err
- }
- t.EndTimestamp = int64(temp.End)
- t.StartTimestamp = int64(temp.Start)
- return nil
- }
- type Assets struct {
- LargeImageID string `json:"large_image,omitempty"`
- SmallImageID string `json:"small_image,omitempty"`
- LargeText string `json:"large_text,omitempty"`
- SmallText string `json:"small_text,omitempty"`
- }
- type Member struct {
-
- GuildID string `json:"guild_id"`
-
- JoinedAt string `json:"joined_at"`
-
- Nick string `json:"nick"`
-
- Deaf bool `json:"deaf"`
-
- Mute bool `json:"mute"`
-
- User *User `json:"user"`
-
- Roles []string `json:"roles"`
- }
- type Settings struct {
- RenderEmbeds bool `json:"render_embeds"`
- InlineEmbedMedia bool `json:"inline_embed_media"`
- InlineAttachmentMedia bool `json:"inline_attachment_media"`
- EnableTtsCommand bool `json:"enable_tts_command"`
- MessageDisplayCompact bool `json:"message_display_compact"`
- ShowCurrentGame bool `json:"show_current_game"`
- ConvertEmoticons bool `json:"convert_emoticons"`
- Locale string `json:"locale"`
- Theme string `json:"theme"`
- GuildPositions []string `json:"guild_positions"`
- RestrictedGuilds []string `json:"restricted_guilds"`
- FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
- Status Status `json:"status"`
- DetectPlatformAccounts bool `json:"detect_platform_accounts"`
- DeveloperMode bool `json:"developer_mode"`
- }
- type Status string
- const (
- StatusOnline Status = "online"
- StatusIdle Status = "idle"
- StatusDoNotDisturb Status = "dnd"
- StatusInvisible Status = "invisible"
- StatusOffline Status = "offline"
- )
- type FriendSourceFlags struct {
- All bool `json:"all"`
- MutualGuilds bool `json:"mutual_guilds"`
- MutualFriends bool `json:"mutual_friends"`
- }
- type Relationship struct {
- User *User `json:"user"`
- Type int `json:"type"`
- ID string `json:"id"`
- }
- type TooManyRequests struct {
- Bucket string `json:"bucket"`
- Message string `json:"message"`
- RetryAfter time.Duration `json:"retry_after"`
- }
- type ReadState struct {
- MentionCount int `json:"mention_count"`
- LastMessageID string `json:"last_message_id"`
- ID string `json:"id"`
- }
- type Ack struct {
- Token string `json:"token"`
- }
- type GuildRole struct {
- Role *Role `json:"role"`
- GuildID string `json:"guild_id"`
- }
- type GuildBan struct {
- Reason string `json:"reason"`
- User *User `json:"user"`
- }
- type GuildEmbed struct {
- Enabled bool `json:"enabled"`
- ChannelID string `json:"channel_id"`
- }
- type GuildAuditLog struct {
- Webhooks []struct {
- ChannelID string `json:"channel_id"`
- GuildID string `json:"guild_id"`
- ID string `json:"id"`
- Avatar string `json:"avatar"`
- Name string `json:"name"`
- } `json:"webhooks,omitempty"`
- Users []struct {
- Username string `json:"username"`
- Discriminator string `json:"discriminator"`
- Bot bool `json:"bot"`
- ID string `json:"id"`
- Avatar string `json:"avatar"`
- } `json:"users,omitempty"`
- AuditLogEntries []struct {
- TargetID string `json:"target_id"`
- Changes []struct {
- NewValue interface{} `json:"new_value"`
- OldValue interface{} `json:"old_value"`
- Key string `json:"key"`
- } `json:"changes,omitempty"`
- UserID string `json:"user_id"`
- ID string `json:"id"`
- ActionType int `json:"action_type"`
- Options struct {
- DeleteMembersDay string `json:"delete_member_days"`
- MembersRemoved string `json:"members_removed"`
- ChannelID string `json:"channel_id"`
- Count string `json:"count"`
- ID string `json:"id"`
- Type string `json:"type"`
- RoleName string `json:"role_name"`
- } `json:"options,omitempty"`
- Reason string `json:"reason"`
- } `json:"audit_log_entries"`
- }
- const (
- AuditLogActionGuildUpdate = 1
- AuditLogActionChannelCreate = 10
- AuditLogActionChannelUpdate = 11
- AuditLogActionChannelDelete = 12
- AuditLogActionChannelOverwriteCreate = 13
- AuditLogActionChannelOverwriteUpdate = 14
- AuditLogActionChannelOverwriteDelete = 15
- AuditLogActionMemberKick = 20
- AuditLogActionMemberPrune = 21
- AuditLogActionMemberBanAdd = 22
- AuditLogActionMemberBanRemove = 23
- AuditLogActionMemberUpdate = 24
- AuditLogActionMemberRoleUpdate = 25
- AuditLogActionRoleCreate = 30
- AuditLogActionRoleUpdate = 31
- AuditLogActionRoleDelete = 32
- AuditLogActionInviteCreate = 40
- AuditLogActionInviteUpdate = 41
- AuditLogActionInviteDelete = 42
- AuditLogActionWebhookCreate = 50
- AuditLogActionWebhookUpdate = 51
- AuditLogActionWebhookDelete = 52
- AuditLogActionEmojiCreate = 60
- AuditLogActionEmojiUpdate = 61
- AuditLogActionEmojiDelete = 62
- AuditLogActionMessageDelete = 72
- )
- type UserGuildSettingsChannelOverride struct {
- Muted bool `json:"muted"`
- MessageNotifications int `json:"message_notifications"`
- ChannelID string `json:"channel_id"`
- }
- type UserGuildSettings struct {
- SupressEveryone bool `json:"suppress_everyone"`
- Muted bool `json:"muted"`
- MobilePush bool `json:"mobile_push"`
- MessageNotifications int `json:"message_notifications"`
- GuildID string `json:"guild_id"`
- ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
- }
- type UserGuildSettingsEdit struct {
- SupressEveryone bool `json:"suppress_everyone"`
- Muted bool `json:"muted"`
- MobilePush bool `json:"mobile_push"`
- MessageNotifications int `json:"message_notifications"`
- ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
- }
- type APIErrorMessage struct {
- Code int `json:"code"`
- Message string `json:"message"`
- }
- type Webhook struct {
- ID string `json:"id"`
- GuildID string `json:"guild_id"`
- ChannelID string `json:"channel_id"`
- User *User `json:"user"`
- Name string `json:"name"`
- Avatar string `json:"avatar"`
- Token string `json:"token"`
- }
- type WebhookParams struct {
- Content string `json:"content,omitempty"`
- Username string `json:"username,omitempty"`
- AvatarURL string `json:"avatar_url,omitempty"`
- TTS bool `json:"tts,omitempty"`
- File string `json:"file,omitempty"`
- Embeds []*MessageEmbed `json:"embeds,omitempty"`
- }
- type MessageReaction struct {
- UserID string `json:"user_id"`
- MessageID string `json:"message_id"`
- Emoji Emoji `json:"emoji"`
- ChannelID string `json:"channel_id"`
- GuildID string `json:"guild_id,omitempty"`
- }
- type GatewayBotResponse struct {
- URL string `json:"url"`
- Shards int `json:"shards"`
- }
- const (
- PermissionReadMessages = 1 << (iota + 10)
- PermissionSendMessages
- PermissionSendTTSMessages
- PermissionManageMessages
- PermissionEmbedLinks
- PermissionAttachFiles
- PermissionReadMessageHistory
- PermissionMentionEveryone
- PermissionUseExternalEmojis
- )
- const (
- PermissionVoiceConnect = 1 << (iota + 20)
- PermissionVoiceSpeak
- PermissionVoiceMuteMembers
- PermissionVoiceDeafenMembers
- PermissionVoiceMoveMembers
- PermissionVoiceUseVAD
- )
- const (
- PermissionChangeNickname = 1 << (iota + 26)
- PermissionManageNicknames
- PermissionManageRoles
- PermissionManageWebhooks
- PermissionManageEmojis
- )
- const (
- PermissionCreateInstantInvite = 1 << iota
- PermissionKickMembers
- PermissionBanMembers
- PermissionAdministrator
- PermissionManageChannels
- PermissionManageServer
- PermissionAddReactions
- PermissionViewAuditLogs
- PermissionAllText = PermissionReadMessages |
- PermissionSendMessages |
- PermissionSendTTSMessages |
- PermissionManageMessages |
- PermissionEmbedLinks |
- PermissionAttachFiles |
- PermissionReadMessageHistory |
- PermissionMentionEveryone
- PermissionAllVoice = PermissionVoiceConnect |
- PermissionVoiceSpeak |
- PermissionVoiceMuteMembers |
- PermissionVoiceDeafenMembers |
- PermissionVoiceMoveMembers |
- PermissionVoiceUseVAD
- PermissionAllChannel = PermissionAllText |
- PermissionAllVoice |
- PermissionCreateInstantInvite |
- PermissionManageRoles |
- PermissionManageChannels |
- PermissionAddReactions |
- PermissionViewAuditLogs
- PermissionAll = PermissionAllChannel |
- PermissionKickMembers |
- PermissionBanMembers |
- PermissionManageServer |
- PermissionAdministrator
- )
- const (
- ErrCodeUnknownAccount = 10001
- ErrCodeUnknownApplication = 10002
- ErrCodeUnknownChannel = 10003
- ErrCodeUnknownGuild = 10004
- ErrCodeUnknownIntegration = 10005
- ErrCodeUnknownInvite = 10006
- ErrCodeUnknownMember = 10007
- ErrCodeUnknownMessage = 10008
- ErrCodeUnknownOverwrite = 10009
- ErrCodeUnknownProvider = 10010
- ErrCodeUnknownRole = 10011
- ErrCodeUnknownToken = 10012
- ErrCodeUnknownUser = 10013
- ErrCodeUnknownEmoji = 10014
- ErrCodeBotsCannotUseEndpoint = 20001
- ErrCodeOnlyBotsCanUseEndpoint = 20002
- ErrCodeMaximumGuildsReached = 30001
- ErrCodeMaximumFriendsReached = 30002
- ErrCodeMaximumPinsReached = 30003
- ErrCodeMaximumGuildRolesReached = 30005
- ErrCodeTooManyReactions = 30010
- ErrCodeUnauthorized = 40001
- ErrCodeMissingAccess = 50001
- ErrCodeInvalidAccountType = 50002
- ErrCodeCannotExecuteActionOnDMChannel = 50003
- ErrCodeEmbedCisabled = 50004
- ErrCodeCannotEditFromAnotherUser = 50005
- ErrCodeCannotSendEmptyMessage = 50006
- ErrCodeCannotSendMessagesToThisUser = 50007
- ErrCodeCannotSendMessagesInVoiceChannel = 50008
- ErrCodeChannelVerificationLevelTooHigh = 50009
- ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
- ErrCodeOAuth2ApplicationLimitReached = 50011
- ErrCodeInvalidOAuthState = 50012
- ErrCodeMissingPermissions = 50013
- ErrCodeInvalidAuthenticationToken = 50014
- ErrCodeNoteTooLong = 50015
- ErrCodeTooFewOrTooManyMessagesToDelete = 50016
- ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
- ErrCodeCannotExecuteActionOnSystemMessage = 50021
- ErrCodeMessageProvidedTooOldForBulkDelete = 50034
- ErrCodeInvalidFormBody = 50035
- ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
- ErrCodeReactionBlocked = 90001
- )
|