123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- package discordgo
- import (
- "encoding/json"
- "sync"
- "time"
- "github.com/gorilla/websocket"
- )
- type Session struct {
-
- Token string
- Debug bool
-
- OnEvent func(*Session, *Event)
- OnReady func(*Session, *Ready)
- OnTypingStart func(*Session, *TypingStart)
- OnMessageCreate func(*Session, *Message)
- OnMessageUpdate func(*Session, *Message)
- OnMessageDelete func(*Session, *MessageDelete)
- OnMessageAck func(*Session, *MessageAck)
- OnUserUpdate func(*Session, *User)
- OnPresenceUpdate func(*Session, *PresenceUpdate)
- OnVoiceStateUpdate func(*Session, *VoiceState)
- OnChannelCreate func(*Session, *Channel)
- OnChannelUpdate func(*Session, *Channel)
- OnChannelDelete func(*Session, *Channel)
- OnGuildCreate func(*Session, *Guild)
- OnGuildUpdate func(*Session, *Guild)
- OnGuildDelete func(*Session, *Guild)
- OnGuildMemberAdd func(*Session, *Member)
- OnGuildMemberRemove func(*Session, *Member)
- OnGuildMemberDelete func(*Session, *Member) // which is it?
- OnGuildMemberUpdate func(*Session, *Member)
- OnGuildRoleCreate func(*Session, *GuildRole)
- OnGuildRoleUpdate func(*Session, *GuildRole)
- OnGuildRoleDelete func(*Session, *GuildRoleDelete)
- OnGuildIntegrationsUpdate func(*Session, *GuildIntegrationsUpdate)
- OnGuildBanAdd func(*Session, *GuildBan)
- OnGuildBanRemove func(*Session, *GuildBan)
- OnGuildEmojisUpdate func(*Session, *GuildEmojisUpdate)
- OnUserSettingsUpdate func(*Session, map[string]interface{}) // TODO: Find better way?
- // Exposed but should not be modified by User.
- SessionID string // from websocket READY packet
- DataReady bool // Set to true when Data Websocket is ready
- VoiceReady bool // Set to true when Voice Websocket is ready
- UDPReady bool // Set to true when UDP Connection is ready
- // Other..
- wsConn *websocket.Conn
- //TODO, add bools for like.
- // are we connnected to websocket?
- // have we authenticated to login?
- // lets put all the general session
- // tracking and infos here.. clearly
- // Everything below here is used for Voice testing.
- // This stuff is almost guarenteed to change a lot
- // and is even a bit hackish right now.
- Voice *Voice // Stores all details related to voice connections
- // Managed state object, updated with events.
- State *State
- StateEnabled bool
- // Mutex/Bools for locks that prevent accidents.
- // TODO: Add channels.
- heartbeatLock sync.Mutex
- heartbeatChan chan struct{}
- listenLock sync.Mutex
- listenChan chan struct{}
- }
- 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 {
- MaxAge int `json:"max_age"`
- Code string `json:"code"`
- Guild *Guild `json:"guild"`
- Revoked bool `json:"revoked"`
- CreatedAt string `json:"created_at"`
- Temporary bool `json:"temporary"`
- Uses int `json:"uses"`
- MaxUses int `json:"max_uses"`
- Inviter *User `json:"inviter"`
- XkcdPass bool `json:"xkcdpass"`
- Channel *Channel `json:"channel"`
- }
- type Channel struct {
- ID string `json:"id"`
- GuildID string `json:"guild_id"`
- Name string `json:"name"`
- Topic string `json:"topic"`
- Position int `json:"position"`
- Type string `json:"type"`
- PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
- IsPrivate bool `json:"is_private"`
- LastMessageID string `json:"last_message_id"`
- Recipient *User `json:"recipient"`
- }
- type PermissionOverwrite struct {
- ID string `json:"id"`
- Type string `json:"type"`
- Deny int `json:"deny"`
- Allow int `json:"allow"`
- }
- type Emoji struct {
- Roles []string `json:"roles"`
- RequireColons bool `json:"require_colons"`
- Name string `json:"name"`
- Managed bool `json:"managed"`
- ID string `json:"id"`
- }
- type Guild struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Icon string `json:"icon"`
- Region string `json:"region"`
- AfkTimeout int `json:"afk_timeout"`
- AfkChannelID string `json:"afk_channel_id"`
- EmbedChannelID string `json:"embed_channel_id"`
- EmbedEnabled bool `json:"embed_enabled"`
- OwnerID string `json:"owner_id"`
- Large bool `json:"large"`
- JoinedAt string `json:"joined_at"`
- 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"`
- }
- type Role struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Managed bool `json:"managed"`
- Color int `json:"color"`
- Hoist bool `json:"hoist"`
- Position int `json:"position"`
- Permissions int `json:"permissions"`
- }
- type VoiceState struct {
- UserID string `json:"user_id"`
- Suppress bool `json:"suppress"`
- SessionID string `json:"session_id"`
- SelfMute bool `json:"self_mute"`
- SelfDeaf bool `json:"self_deaf"`
- Mute bool `json:"mute"`
- Deaf bool `json:"deaf"`
- ChannelID string `json:"channel_id"`
- }
- type Presence struct {
- User *User `json:"user"`
- Status string `json:"status"`
- Game *Game `json:"game"`
- }
- type Game struct {
- Name string `json:"name"`
- }
- type Member struct {
- GuildID string `json:"guild_id"`
- JoinedAt string `json:"joined_at"`
- Deaf bool `json:"deaf"`
- Mute bool `json:"mute"`
- User *User `json:"user"`
- Roles []string `json:"roles"`
- }
- type User struct {
- ID string `json:"id"`
- Email string `json:"email"`
- Username string `json:"username"`
- Avatar string `json:"Avatar"`
- Verified bool `json:"verified"`
-
- }
- type Settings struct {
- RenderEmbeds bool `json:"render_embeds"`
- InlineEmbedMedia bool `json:"inline_embed_media"`
- EnableTtsCommand bool `json:"enable_tts_command"`
- MessageDisplayCompact bool `json:"message_display_compact"`
- Locale string `json:"locale"`
- ShowCurrentGame bool `json:"show_current_game"`
- Theme string `json:"theme"`
- MutedChannels []string `json:"muted_channels"`
- }
- type Event struct {
- Type string `json:"t"`
- State int `json:"s"`
- Operation int `json:"op"`
- Direction int `json:"dir"`
- RawData json.RawMessage `json:"d"`
- }
- type Ready struct {
- Version int `json:"v"`
- SessionID string `json:"session_id"`
- HeartbeatInterval time.Duration `json:"heartbeat_interval"`
- User *User `json:"user"`
- ReadState []*ReadState
- PrivateChannels []*Channel `json:"private_channels"`
- Guilds []*Guild `json:"guilds"`
- }
- type RateLimit struct {
- Bucket string `json:"bucket"`
- Message string `json:"message"`
- RetryAfter time.Duration `json:"retry_after"`
- }
- type ReadState struct {
- MentionCount int
- LastMessageID string `json:"last_message_id"`
- ID string `json:"id"`
- }
- type TypingStart struct {
- UserID string `json:"user_id"`
- ChannelID string `json:"channel_id"`
- Timestamp int `json:"timestamp"`
- }
- type PresenceUpdate struct {
- User *User `json:"user"`
- Status string `json:"status"`
- Roles []string `json:"roles"`
- GuildID string `json:"guild_id"`
- Game *Game `json:"game"`
- }
- type MessageAck struct {
- MessageID string `json:"message_id"`
- ChannelID string `json:"channel_id"`
- }
- type MessageDelete struct {
- ID string `json:"id"`
- ChannelID string `json:"channel_id"`
- }
- type GuildIntegrationsUpdate struct {
- GuildID string `json:"guild_id"`
- }
- type GuildRole struct {
- Role *Role `json:"role"`
- GuildID string `json:"guild_id"`
- }
- type GuildRoleDelete struct {
- RoleID string `json:"role_id"`
- GuildID string `json:"guild_id"`
- }
- type GuildBan struct {
- User *User `json:"user"`
- GuildID string `json:"guild_id"`
- }
- type GuildEmojisUpdate struct {
- GuildID string `json:"guild_id"`
- Emojis []*Emoji `json:"emojis"`
- }
- type State struct {
- Ready
- }
|