|
16 | 16 |
|
17 | 17 | package api
|
18 | 18 |
|
19 |
| -/* Payloads */ |
| 19 | +const ( |
| 20 | + gatewayVersion = 9 |
| 21 | + gatewayURLQueryString = "?v=" + string(rune(gatewayVersion)) + "&encoding=json" |
| 22 | +) |
20 | 23 |
|
21 |
| -// GatewayPayload |
22 |
| -// |
23 |
| -// s and t are null when op is not 0 (Gateway Dispatch Opcode). |
| 24 | +// GatewayPayload - S and T are null when Op is not 0 (Gateway Dispatch Opcode). |
24 | 25 | type GatewayPayload struct {
|
25 |
| - Op int `json:"op"` // opcode for the payload |
26 |
| - D *interface{} `json:"d,omitempty"` // event data |
27 |
| - S *int `json:"s,omitempty"` // sequence number, used for resuming sessions and heartbeats |
28 |
| - T *string `json:"t,omitempty"` // the event name for this payload |
| 26 | + Op int `json:"op"` // Op - opcode for the payload |
| 27 | + D *interface{} `json:"d"` // D - event data |
| 28 | + S *int `json:"s"` // S - sequence number, used for resuming sessions and heartbeats |
| 29 | + T *string `json:"t"` // T - the event name for this payload |
| 30 | +} |
| 31 | + |
| 32 | +type GatewayIntents int64 |
| 33 | + |
| 34 | +//goland:noinspection GoSnakeCaseUsage |
| 35 | +const ( |
| 36 | + GUILDS GatewayIntents = 1 << 0 |
| 37 | + GUILD_MEMBERS GatewayIntents = 1 << 1 |
| 38 | + GUILD_BANS GatewayIntents = 1 << 2 |
| 39 | + GUILD_EMOJIS_AND_STICKERS GatewayIntents = 1 << 3 |
| 40 | + GUILD_INTEGRATIONS GatewayIntents = 1 << 4 |
| 41 | + GUILD_WEBHOOKS GatewayIntents = 1 << 5 |
| 42 | + GUILD_INVITES GatewayIntents = 1 << 6 |
| 43 | + GUILD_VOICE_STATES GatewayIntents = 1 << 7 |
| 44 | + GUILD_PRESENCES GatewayIntents = 1 << 8 |
| 45 | + GUILD_MESSAGES GatewayIntents = 1 << 9 |
| 46 | + GUILD_MESSAGE_REACTIONS GatewayIntents = 1 << 10 |
| 47 | + GUILD_MESSAGE_TYPING GatewayIntents = 1 << 11 |
| 48 | + DIRECT_MESSAGES GatewayIntents = 1 << 12 |
| 49 | + DIRECT_MESSAGE_REACTIONS GatewayIntents = 1 << 13 |
| 50 | + DIRECT_MESSAGE_TYPING GatewayIntents = 1 << 14 |
| 51 | + GUILD_SCHEDULE_EVENTS GatewayIntents = 1 << 16 |
| 52 | +) |
| 53 | + |
| 54 | +// Identify - Used to trigger the initial handshake with the gateway. |
| 55 | +type Identify struct { |
| 56 | + Token string `json:"token"` // Token - authentication token |
| 57 | + Properties string `json:"properties"` // Properties - IdentifyConnection properties |
| 58 | + Compress bool `json:"compress,omitempty"` // Compress - whether this connection supports compression of packets |
| 59 | + LargeThreshold int `json:"large_threshold,omitempty"` // LargeThreshold - value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list |
| 60 | + Shard [2]int `json:"shard,omitempty"` // Shard - used for Guild Sharding |
| 61 | + Presence GatewayPresenceUpdate `json:"presence,omitempty"` // Presence - presence structure for initial presence information |
| 62 | + Intents GatewayIntents `json:"intents"` // Intents - the Gateway Intents you wish to receive |
| 63 | +} |
| 64 | + |
| 65 | +type IdentifyConnection struct { |
| 66 | + OS string `json:"$os"` // OS - your operating system |
| 67 | + Browser string `json:"$browser"` // Browser - your library name |
| 68 | + Device string `json:"$device"` // Device - your library name |
| 69 | +} |
| 70 | + |
| 71 | +// Resume - Used to replay missed events when a disconnected client resumes. |
| 72 | +type Resume struct { |
| 73 | + Token string `json:"token"` // Token - session token |
| 74 | + SessionID string `json:"session_id"` // SessionID - session id |
| 75 | + Seq int `json:"seq"` // Seq - last sequence number received |
| 76 | +} |
| 77 | + |
| 78 | +// GuildRequestMembers - Used to request all members for a guild or a list of guilds. |
| 79 | +// |
| 80 | +// When initially connecting, if you don't have the GUILD_PRESENCES Gateway Intent, or if the guild is over 75k members, it will only send members who are in voice, plus the member for you (the connecting user). |
| 81 | +// |
| 82 | +// Otherwise, if a guild has over large_threshold members (value in the Gateway Identify), it will only send members who are online, have a role, have a nickname, or are in a voice channel, and if it has under large_threshold members, it will send all members. |
| 83 | +// |
| 84 | +// If a client wishes to receive additional members, they need to explicitly request them via this operation. |
| 85 | +// |
| 86 | +// The server will send Guild Members Chunk events in response with up to 1000 members per chunk until all members that match the request have been sent. |
| 87 | +// |
| 88 | +// Due to our privacy and infrastructural concerns with this feature, there are some limitations that apply: |
| 89 | +// |
| 90 | +// GUILD_PRESENCES intent is required to set presences = true. Otherwise, it will always be false |
| 91 | +// GUILD_MEMBERS intent is required to request the entire member list—(query=‘’, limit=0<=n) |
| 92 | +// You will be limited to requesting 1 guild_id per request |
| 93 | +// Requesting a prefix (query parameter) will return a maximum of 100 members |
| 94 | +// Requesting user_ids will continue to be limited to returning 100 members |
| 95 | +type GuildRequestMembers struct { |
| 96 | + GuildID Snowflake `json:"guild_id"` // GuildID - id of the guild to get members for |
| 97 | + Query string `json:"query,omitempty"` // Query - string that username starts with, or an empty string to return all members |
| 98 | + Limit int `json:"limit"` // Limit - maximum number of members to send matching the query; a limit of 0 can be used with an empty string query to return all members |
| 99 | + Presences bool `json:"presences,omitempty"` // Presences - used to specify if we want the presences of the matched members |
| 100 | + UserIDs []Snowflake `json:"user_ids,omitempty"` // UserIDs - used to specify which users you wish to fetch |
| 101 | + Nonce string `json:"nonce,omitempty"` // Nonce - nonce to identify the Guild Members Chunk response |
| 102 | +} |
| 103 | + |
| 104 | +// GatewayVoiceStateUpdate - Sent when a client wants to join, move, or disconnect from a voice channel. |
| 105 | +type GatewayVoiceStateUpdate struct { |
| 106 | + GuildID Snowflake `json:"guild_id"` // GuildID - id of the Guild |
| 107 | + ChannelID *Snowflake `json:"channel_id"` // ChannelID - id of the voice channel client wants to join (null if disconnecting) |
| 108 | + SelfMute bool `json:"self_mute"` // SelfMute - is the client muted |
| 109 | + SelfDeaf bool `json:"self_deaf"` // SelfDeaf - is the client deafened |
| 110 | +} |
| 111 | + |
| 112 | +// GatewayPresenceUpdate - Sent by the client to indicate a presence or status update. |
| 113 | +type GatewayPresenceUpdate struct { |
| 114 | + Since *int `json:"since"` // Since - unix time (in milliseconds) of when the client went idle, or null if the client is not idle |
| 115 | + Activities []Activity `json:"activities"` // Activities - the user's activities |
| 116 | + Status StatusType `json:"status"` // Status - the user's new StatusType |
| 117 | + Afk bool `json:"afk"` // Afk - whether the client is afk |
| 118 | +} |
| 119 | + |
| 120 | +// Hello - Sent on connection to the websocket. Defines the heartbeat interval that the client should heartbeat to. |
| 121 | +type Hello struct { |
| 122 | + HeartbeatInterval int `json:"heartbeat_interval"` // HeartbeatInterval - the interval (in milliseconds) the client should heartbeat with |
29 | 123 | }
|
30 | 124 |
|
31 |
| -/* Presence */ |
| 125 | +// Ready - The ready event is dispatched when a client has completed the initial handshake with the gateway (for new sessions). |
| 126 | +// |
| 127 | +// The ready event can be the largest and most complex event the gateway will send, as it contains all the state required for a client to begin interacting with the rest of the platform. |
| 128 | +// |
| 129 | +// "guilds" are the guilds of which your bot is a member. |
| 130 | +// |
| 131 | +// They start out as unavailable when you connect to the gateway. |
| 132 | +// |
| 133 | +// As they become available, your bot will be notified via Guild Create events. |
| 134 | +type Ready struct { |
| 135 | + V int `json:"v"` |
| 136 | + User User `json:"user"` |
| 137 | + Guilds []UnavailableGuild `json:"guilds"` |
| 138 | + SessionID string `json:"session_id"` |
| 139 | + Shard [2]int `json:"shard,omitempty"` |
| 140 | + Application Application `json:"application"` |
| 141 | +} |
| 142 | + |
| 143 | +type StatusType string |
| 144 | + |
| 145 | +const ( |
| 146 | + StatusTypeOnline StatusType = "online" |
| 147 | + StatusTypeDoNotDisturb StatusType = "dnd" |
| 148 | + StatusTypeIdle StatusType = "idle" |
| 149 | + StatusTypeInvisible StatusType = "invisible" |
| 150 | + StatusTypeOffline StatusType = "offline" |
| 151 | +) |
32 | 152 |
|
33 | 153 | type PresenceStatus string
|
34 | 154 |
|
|
0 commit comments