Skip to content

Commit 7449a96

Browse files
committed
document sticker/go; update gateway.go and guild.go accordingly
1 parent 893117b commit 7449a96

File tree

5 files changed

+293
-13
lines changed

5 files changed

+293
-13
lines changed

api/gateway.go

+129-9
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,139 @@
1616

1717
package api
1818

19-
/* Payloads */
19+
const (
20+
gatewayVersion = 9
21+
gatewayURLQueryString = "?v=" + string(rune(gatewayVersion)) + "&encoding=json"
22+
)
2023

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).
2425
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
29123
}
30124

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+
)
32152

33153
type PresenceStatus string
34154

api/guild.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ type Guild struct {
6363
ApproximatePresenceCount uint64 `json:"approximate_presence_count,omitempty"`
6464
WelcomeScreen WelcomeScreen `json:"welcome_screen,omitempty"`
6565
NsfwLevel GuildNsfwLevel `json:"nsfw_level"`
66-
// TODO: Stickers
67-
PremiumProgressBarEnabled bool `json:"premium_progress_bar_enabled"`
66+
Stickers []Sticker `json:"stickers,omitempty"`
67+
PremiumProgressBarEnabled bool `json:"premium_progress_bar_enabled"`
6868

6969
// These fields are only sent within the GUILD_CREATE event
7070

@@ -146,6 +146,7 @@ const (
146146

147147
type GuildFeatures string
148148

149+
//goland:noinspection SpellCheckingInspection
149150
const (
150151
AnimatedIcon GuildFeatures = "ANIMATED_ICON"
151152
Banner GuildFeatures = "BANNER"
@@ -171,6 +172,11 @@ const (
171172
WelcomeScreenEnabled GuildFeatures = "WELCOME_SCREEN_ENABLED"
172173
)
173174

175+
type UnavailableGuild struct {
176+
ID Snowflake `json:"id"`
177+
Unavailable bool `json:"unavailable"`
178+
}
179+
174180
/* GUILD WIDGET OBJECT */
175181

176182
type GuildWidget struct {

api/reference.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
/* API Versioning */
2525

2626
const apiBase string = "https://discord.com/api"
27-
const apiVersion string = "/v9"
28-
const api = apiBase + apiVersion
27+
const apiVersion string = "/v"
28+
const api = apiBase + apiVersion + string(rune(gatewayVersion))
2929

3030
/* Authentication */
3131

api/sticker.go

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2022. Veteran Software
3+
*
4+
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
7+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
8+
* version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program.
14+
* If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package api
18+
19+
import (
20+
"fmt"
21+
"net/http"
22+
23+
"github.com/veteran-software/discord-api-wrapper/routes"
24+
)
25+
26+
// Sticker - Represents a sticker that can be sent in messages.
27+
type Sticker struct {
28+
ID Snowflake `json:"id"` // ID - id of the sticker
29+
PackID Snowflake `json:"pack_id,omitempty"` // PackID - for standard stickers, id of the pack the sticker is from
30+
Name string `json:"name"` // Name - name of the sticker
31+
Description *string `json:"description"` // Description - description of the sticker
32+
Tags string `json:"tags,omitempty"` // Tags - autocomplete/suggestion tags for the sticker (max 200 characters)
33+
Asset string `json:"asset,omitempty"` // Asset - Deprecated: previously the sticker asset hash, now an empty string
34+
Type StickerType `json:"type"` // Type - type of sticker
35+
FormatType int `json:"format_type"` // FormatType - type of sticker format
36+
Available bool `json:"available,omitempty"` // Available - whether this guild sticker can be used, may be false due to loss of Server Boosts
37+
GuildID Snowflake `json:"guild_id,omitempty"` // GuildID - id of the guild that owns this sticker
38+
User User `json:"user,omitempty"` // User - the user that uploaded the guild sticker
39+
SortValue int `json:"sort_value,omitempty"` // SortValue - the standard sticker's sort order within its pack
40+
}
41+
42+
type StickerType int
43+
44+
const (
45+
StickerTypeStandard StickerType = iota + 1 // StickerTypeStandard - an official sticker in a pack, part of Nitro or in a removed purchasable pack
46+
StickerTypeGuild // StickerTypeGuild - a sticker uploaded to a Boosted guild for the guild's members
47+
)
48+
49+
type StickerFormatType int
50+
51+
const (
52+
StickerFormatTypePng StickerFormatType = iota + 1
53+
StickerFormatTypeAnimatedPng
54+
StickerFormatTypeLottie
55+
)
56+
57+
// StickerItem - The smallest amount of data required to render a sticker. A partial sticker object.
58+
type StickerItem struct {
59+
ID Snowflake `json:"id"` // ID - id of the sticker
60+
Name string `json:"name"` // Name - name of the sticker
61+
FormatType StickerFormatType `json:"format_type"` // FormatType - type of sticker format
62+
}
63+
64+
// StickerPack - Represents a pack of standard stickers.
65+
type StickerPack struct {
66+
ID Snowflake `json:"id"` // ID - id of the sticker pack
67+
Stickers []Sticker `json:"stickers"` // Stickers - the stickers in the pack
68+
Name string `json:"name"` // Name - name of the sticker pack
69+
SkuID Snowflake `json:"sku_id"` // SkuID - id of the pack's SKU
70+
CoverStickerID Snowflake `json:"cover_sticker_id,omitempty"` // CoverStickerID - id of a sticker in the pack which is shown as the pack's icon
71+
Description string `json:"description"` // Description - description of the sticker pack
72+
BannerAssetID Snowflake `json:"banner_asset_id,omitempty"` // BannerAssetID - id of the sticker pack's banner image
73+
}
74+
75+
// GetSticker - Returns a sticker object for the given sticker ID.
76+
func (s *Sticker) GetSticker() (string, string) {
77+
return http.MethodGet, fmt.Sprintf(routes.Stickers_, api, s.ID.String())
78+
}
79+
80+
// ListNitroStickerPacks - Returns the list of sticker packs available to Nitro subscribers.
81+
func ListNitroStickerPacks() (string, string) {
82+
return http.MethodGet, fmt.Sprintf(routes.StickerPacks, api)
83+
}
84+
85+
// ListGuildStickers - Returns an array of sticker objects for the given guild.
86+
//
87+
// Includes user fields if the bot has the ManageEmojisAndStickers permission.
88+
func (g *Guild) ListGuildStickers() (string, string) {
89+
return http.MethodGet, fmt.Sprintf(routes.Guilds_Stickers, api, g.ID.String())
90+
}
91+
92+
func (g *Guild) GetGuildSticker(stickerID Snowflake) (string, string) {
93+
return http.MethodGet, fmt.Sprintf(routes.Guilds_Stickers_, api, g.ID.String(), stickerID.String())
94+
}
95+
96+
// CreateGuildSticker - Create a new sticker for the guild.
97+
//
98+
// Send a multipart/form-data body.
99+
//
100+
// Requires the ManageEmojisAndStickers permission.
101+
//
102+
// Returns the new sticker object on success.
103+
func (g *Guild) CreateGuildSticker() (string, string) {
104+
return http.MethodPost, fmt.Sprintf(routes.Guilds_Stickers, api, g.ID.String())
105+
}
106+
107+
// ModifyGuildSticker - Modify the given sticker.
108+
//
109+
// Requires the ManageEmojisAndStickers permission.
110+
//
111+
// Returns the updated sticker object on success.
112+
//
113+
// All parameters to this endpoint are optional.
114+
//
115+
// This endpoint supports the "X-Audit-Log-Reason" header.
116+
func (g *Guild) ModifyGuildSticker(stickerID Snowflake) (string, string) {
117+
return http.MethodPatch, fmt.Sprintf(routes.Guilds_Stickers_, api, g.ID.String(), stickerID.String())
118+
}
119+
120+
// DeleteGuildSticker - Delete the given sticker.
121+
//
122+
// Requires the MANAGE_EMOJIS_AND_STICKERS permission.
123+
//
124+
// Returns "204 No Content" on success.
125+
//
126+
// This endpoint supports the "X-Audit-Log-Reason" header.
127+
func (g *Guild) DeleteGuildSticker(stickerID Snowflake) (string, string) {
128+
return http.MethodDelete, fmt.Sprintf(routes.Guilds_Stickers_, api, g.ID.String(), stickerID.String())
129+
}

routes/sticker.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022. Veteran Software
3+
*
4+
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
7+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
8+
* version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program.
14+
* If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package routes
18+
19+
//goland:noinspection GoSnakeCaseUsage
20+
const (
21+
Guilds_Stickers = "%s/guilds/%s/stickers"
22+
Guilds_Stickers_ = "%s/guilds/%s/stickers/%s"
23+
Stickers_ = "%s/stickers/%s"
24+
StickerPacks = "%s/sticker-packs"
25+
)

0 commit comments

Comments
 (0)