Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesycod committed Dec 9, 2021
1 parent 70c4396 commit 3393c4b
Show file tree
Hide file tree
Showing 11 changed files with 1,210 additions and 127 deletions.
44 changes: 22 additions & 22 deletions components.go
Expand Up @@ -9,9 +9,9 @@ type ComponentType uint

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

// MessageComponent is a base interface for all message components.
Expand All @@ -36,11 +36,11 @@ 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
Expand Down Expand Up @@ -89,27 +89,27 @@ 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
)

// ComponentEmoji represents button emoji, if it does have one.
// ComponentEmoji represents a button's emoji, if it has one.
type ComponentEmoji struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Expand All @@ -123,7 +123,7 @@ type Button struct {
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 @@ -133,7 +133,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 @@ -146,8 +146,8 @@ func (b Button) MarshalJSON() ([]byte, error) {
}

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

// SelectMenuOption represents an option for a select menu.
Expand Down Expand Up @@ -175,7 +175,7 @@ type SelectMenu struct {

// Type is a method to get the type of a component.
func (SelectMenu) Type() ComponentType {
return SelectMenuComponent
return ComponentSelectMenu
}

// MarshalJSON is a method for marshaling SelectMenu to a JSON object.
Expand Down
43 changes: 33 additions & 10 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,9 @@ 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 }
EndpointGuildActiveThreads = func(gID string) string { return EndpointGuilds + gID + "/threads/active" }

EndpointChannel = func(cID string) string { return EndpointChannels + cID }
EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" }
Expand All @@ -115,10 +120,28 @@ var (
EndpointChannelMessagesPins = func(cID string) string { return EndpointChannel(cID) + "/pins" }
EndpointChannelMessagePin = func(cID, mID string) string { return EndpointChannel(cID) + "/pins/" + mID }
EndpointChannelMessageCrosspost = func(cID, mID string) string { return EndpointChannel(cID) + "/messages/" + mID + "/crosspost" }
EndpointChannelFollow = func(cID string) string { return EndpointChannel(cID) + "/followers" }
EndpointChannelUsers = func(cID string) string { return EndpointChannel(cID) + "/users" }
EndpointChannelMessageThreads = func(cID, mID string) string {
return EndpointChannels + cID + "/messages/" + mID + "/threads"
}

EndpointThreads = func(cID string) string { return EndpointChannel(cID) + "/threads" }
EndpointThreadMembers = func(cID string) string { return EndpointChannel(cID) + "/thread-members" }
EndpointThreadMember = func(cID, uID string) string { return EndpointChannel(cID) + "/thread-members/" + uID }
EndpointThreadsArchived = func(cID string) string { return EndpointThreads(cID) + "/archived" }
EndpointThreadsPublicArchived = func(cID string) string { return EndpointThreadsArchived(cID) + "/public" }
EndpointThreadsPrivateArchived = func(cID string) string { return EndpointThreadsArchived(cID) + "/private" }
EndpointThreadsJoinedPrivateArchived = func(cID string) string { return EndpointChannelUsers(cID) + "/@me/threads/archived/private" }

EndpointChannelFollow = func(cID string) string { return EndpointChannel(cID) + "/followers" }

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.

37 changes: 37 additions & 0 deletions events.go
Expand Up @@ -289,6 +289,43 @@ type InteractionCreate struct {
*Interaction
}

// ThreadCreate is the data for a ThreadCreate event
type ThreadCreate struct {
*Channel
}

// ThreadUpdate is the data for a ThreadUpdate event
type ThreadUpdate struct {
*Channel
}

// ThreadDelete is the data for a ThreadDelete event
type ThreadDelete struct {
*Channel
}

// ThreadMemberUpdate is the data for a ThreadMemberUpdate event
type ThreadMemberUpdate struct {
*ThreadMember
}

// ThreadMembersUpdate is the data for a ThreadMembersUpdate event
type ThreadMembersUpdate struct {
ID string `json:"id"`
GuildID string `json:"guild_id"`
MemberCount int `json:"member_count"`
AddedMembers []*ThreadMember `json:"added_members"`
RemovedMemberIDs []string `json:"removed_member_ids"`
}

// ThreadListSync is the data for a ThreadListSync event
type ThreadListSync struct {
GuildID string `json:"guild_id"`
ChannelIDs []string `json:"channel_ids"`
Threads []*Channel `json:"threads"`
Members []*ThreadMember `json:"members"`
}

// UnmarshalJSON is a helper function to unmarshal Interaction object.
func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &i.Interaction)
Expand Down

0 comments on commit 3393c4b

Please sign in to comment.