Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8 & v9 stuff #982

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03a52c2
Added stickers
vys534 Jul 27, 2021
60ccd3f
upgrade to discord api v9
vys534 Jul 28, 2021
e746973
optimize parameters for thread rest api functions
vys534 Jul 28, 2021
9ca8b33
lint
vys534 Jul 28, 2021
8727f0c
store threads in state & update them accordingly
vys534 Jul 30, 2021
6408522
Reverted Invite() for backwards compatibility; changes moved to Invit…
vys534 Jul 30, 2021
f0d574e
Added select menu as a message component
vys534 Jul 30, 2021
6ab7ae6
Fixed wrong label in SelectOption, renamed ButtonEmoji to ComponentEm…
vys534 Jul 30, 2021
85c7477
Fix incorrect type for Message.Interaction, added field for values fr…
vys534 Jul 30, 2021
b9fe5fa
Change int to ArchiveDuration on thread metadata AutoArchiveDuration
vys534 Jul 30, 2021
9cc08be
Merge branch 'bwmarrin:master' into master
vys534 Jul 30, 2021
29791b6
Merge branch 'v9'
vys534 Jul 30, 2021
9459b08
Added functions for stickers, naming scheme fix for threads, added st…
vys534 Jul 30, 2021
c56255a
Added stage instance support, added missing audit log change keys & a…
vys534 Jul 30, 2021
a93fb91
gofmt
vys534 Jul 30, 2021
f3b5c0a
Fix incorrect values for ArchiveDurationOneHour
vys534 Jul 31, 2021
04013da
Revert 60*60 to 60
vys534 Jul 31, 2021
ecd5d0d
Restored UnmarshalJSON to Message, rename StickerFormatType -> Sticke…
vys534 Aug 1, 2021
32da67e
Add ThreadEdit function
Aug 24, 2021
356f82e
Merge pull request #1 from binwiederhier/vysiondev-threads
vys534 Aug 24, 2021
2962d8f
Merge remote-tracking branch 'upstream/master'
vys534 Aug 24, 2021
6bf33ca
Gofmt, fixed button types in component example
vys534 Aug 24, 2021
8574857
Integrated bug fixes and additions from #922
vys534 Aug 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 66 additions & 24 deletions components.go
Expand Up @@ -9,8 +9,9 @@ type ComponentType uint

// MessageComponent types.
const (
ActionsRowComponent ComponentType = 1
ButtonComponent ComponentType = 2
ComponentActionRow ComponentType = 1
ComponentButton ComponentType = 2
ComponentSelectMenu ComponentType = 3
)

// MessageComponent is a base interface for all message components.
Expand All @@ -35,14 +36,18 @@ func (umc *unmarshalableMessageComponent) UnmarshalJSON(src []byte) error {

var data MessageComponent
switch v.Type {
case ActionsRowComponent:
case ComponentActionRow:
v := ActionsRow{}
err = json.Unmarshal(src, &v)
data = v
case ButtonComponent:
case ComponentButton:
v := Button{}
err = json.Unmarshal(src, &v)
data = v
case ComponentSelectMenu:
v := SelectMenu{}
err = json.Unmarshal(src, &v)
data = v
}
if err != nil {
return err
Expand Down Expand Up @@ -87,41 +92,41 @@ func (r *ActionsRow) UnmarshalJSON(data []byte) error {

// Type is a method to get the type of a component.
func (r ActionsRow) Type() ComponentType {
return ActionsRowComponent
return ComponentActionRow
}

// ButtonStyle is style of button.
type ButtonStyle uint

// Button styles.
const (
// PrimaryButton is a button with blurple color.
PrimaryButton ButtonStyle = 1
// SecondaryButton is a button with grey color.
SecondaryButton ButtonStyle = 2
// SuccessButton is a button with green color.
SuccessButton ButtonStyle = 3
// DangerButton is a button with red color.
DangerButton ButtonStyle = 4
// LinkButton is a special type of button which navigates to a URL. Has grey color.
LinkButton ButtonStyle = 5
// ButtonPrimary is a button with blurple color.
ButtonPrimary ButtonStyle = 1
// ButtonSecondary is a button with grey color.
ButtonSecondary ButtonStyle = 2
// ButtonSuccess is a button with green color.
ButtonSuccess ButtonStyle = 3
// ButtonDanger is a button with red color.
ButtonDanger ButtonStyle = 4
// ButtonLink is a special type of button which navigates to a URL. Has grey color.
ButtonLink ButtonStyle = 5
)

// ButtonEmoji represents button emoji, if it does have one.
type ButtonEmoji struct {
// ComponentEmoji represents a component's emoji, if it has one.
type ComponentEmoji struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Animated bool `json:"animated,omitempty"`
}

// Button represents button component.
type Button struct {
Label string `json:"label"`
Style ButtonStyle `json:"style"`
Disabled bool `json:"disabled"`
Emoji ButtonEmoji `json:"emoji"`
Label string `json:"label"`
Style ButtonStyle `json:"style"`
Disabled bool `json:"disabled"`
Emoji ComponentEmoji `json:"emoji"`

// NOTE: Only button with LinkButton style can have link. Also, URL is mutually exclusive with CustomID.
// NOTE: Only button with ButtonLink style can have link. Also, URL is mutually exclusive with CustomID.
URL string `json:"url,omitempty"`
CustomID string `json:"custom_id,omitempty"`
}
Expand All @@ -131,7 +136,7 @@ func (b Button) MarshalJSON() ([]byte, error) {
type button Button

if b.Style == 0 {
b.Style = PrimaryButton
b.Style = ButtonPrimary
}

return json.Marshal(struct {
Expand All @@ -145,5 +150,42 @@ func (b Button) MarshalJSON() ([]byte, error) {

// Type is a method to get the type of a component.
func (b Button) Type() ComponentType {
return ButtonComponent
return ComponentButton
}

// SelectMenu is the select menu component.
type SelectMenu struct {
CustomID string `json:"custom_id"`
Options []SelectOption `json:"options"`
Placeholder string `json:"placeholder,omitempty"`
MinValues int `json:"min_values,omitempty"`
MaxValues int `json:"max_values,omitempty"`
Disabled bool `json:"disabled"`
}

// SelectOption is a choice on the SelectMenu component.
type SelectOption struct {
Label string `json:"label"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
Emoji ComponentEmoji `json:"emoji,omitempty"`
Default bool `json:"default,omitempty"`
}

// MarshalJSON is a method for marshaling SelectMenu to a JSON object.
func (b SelectMenu) MarshalJSON() ([]byte, error) {
type selectMenu SelectMenu

return json.Marshal(struct {
selectMenu
Type ComponentType `json:"type"`
}{
selectMenu: selectMenu(b),
Type: b.Type(),
})
}

// Type is a method to get the type of a component.
func (b SelectMenu) Type() ComponentType {
return ComponentSelectMenu
}
37 changes: 28 additions & 9 deletions endpoints.go
Expand Up @@ -14,7 +14,7 @@ package discordgo
import "strconv"

// APIVersion is the Discord API version used for the REST and Websocket API.
var APIVersion = "8"
var APIVersion = "9"

// Known Discord API Endpoints.
var (
Expand All @@ -23,14 +23,16 @@ var (
EndpointSmActive = EndpointSm + "active.json"
EndpointSmUpcoming = EndpointSm + "upcoming.json"

EndpointDiscord = "https://discord.com/"
EndpointAPI = EndpointDiscord + "api/v" + APIVersion + "/"
EndpointGuilds = EndpointAPI + "guilds/"
EndpointChannels = EndpointAPI + "channels/"
EndpointUsers = EndpointAPI + "users/"
EndpointGateway = EndpointAPI + "gateway"
EndpointGatewayBot = EndpointGateway + "/bot"
EndpointWebhooks = EndpointAPI + "webhooks/"
EndpointDiscord = "https://discord.com/"
EndpointAPI = EndpointDiscord + "api/v" + APIVersion + "/"
EndpointGuilds = EndpointAPI + "guilds/"
EndpointChannels = EndpointAPI + "channels/"
EndpointUsers = EndpointAPI + "users/"
EndpointGateway = EndpointAPI + "gateway"
EndpointGatewayBot = EndpointGateway + "/bot"
EndpointWebhooks = EndpointAPI + "webhooks/"
EndpointStickers = EndpointAPI + "stickers/"
EndpointStageInstances = EndpointAPI + "stage-instances/"

EndpointCDN = "https://cdn.discordapp.com/"
EndpointCDNAttachments = EndpointCDN + "attachments/"
Expand Down Expand Up @@ -102,6 +104,8 @@ var (
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }
EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" }
EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }

EndpointChannel = func(cID string) string { return EndpointChannels + cID }
EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" }
Expand All @@ -117,8 +121,23 @@ var (
EndpointChannelMessageCrosspost = func(cID, mID string) string { return EndpointChannel(cID) + "/messages/" + mID + "/crosspost" }
EndpointChannelFollow = func(cID string) string { return EndpointChannel(cID) + "/followers" }

EndpointChannelStartThreadWithMessage = func(cID string, mID string) string { return EndpointChannels + cID + "/messages/" + mID + "/threads" }
EndpointChannelStartThreadWithoutMessage = func(cID string) string { return EndpointChannels + cID + "/threads" }
EndpointChannelThread = func(cID string) string { return EndpointChannels + cID + "/thread-members/@me" }
EndpointChannelMember = func(cID string, uID string) string { return EndpointChannels + cID + "/thread-members/" + uID }
EndpointChannelListMembers = func(cID string) string { return EndpointChannels + cID + "/thread-members" }
EndpointChannelListActiveThreads = func(cID string) string { return EndpointChannels + cID + "/threads/active" }
EndpointChannelListPublicArchivedThreads = func(cID string) string { return EndpointChannels + cID + "/threads/archived/public" }
EndpointChannelListPrivateArchivedThreads = func(cID string) string { return EndpointChannels + cID + "/threads/archived/private" }
EndpointChannelListJoinedPrivateArchivedThreads = func(cID string) string { return EndpointChannels + cID + "/users/@me/threads/archived/private" }

EndpointGroupIcon = func(cID, hash string) string { return EndpointCDNChannelIcons + cID + "/" + hash + ".png" }

EndpointSticker = func(sID string) string { return EndpointStickers + sID }
EndpointNitroStickerPacks = EndpointAPI + "/sticker-packs"

EndpointStageInstance = func(cID string) string { return EndpointStageInstances + cID }

EndpointChannelWebhooks = func(cID string) string { return EndpointChannel(cID) + "/webhooks" }
EndpointWebhook = func(wID string) string { return EndpointWebhooks + wID }
EndpointWebhookToken = func(wID, token string) string { return EndpointWebhooks + wID + "/" + token }
Expand Down
144 changes: 144 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.