From d934f637404bdc56f6664753a53fe8332ac4d0a1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 16 May 2024 18:03:40 +0200 Subject: [PATCH 01/31] Add guild onboarding + home audit log events (#258) * Add AuditLogGuildOnboardingUpdate * remove comments * update events * add server guide events * update events * add other home events + rename server guide events * remove home events --- discord/audit_log.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/discord/audit_log.go b/discord/audit_log.go index 4135c558..59021f4a 100644 --- a/discord/audit_log.go +++ b/discord/audit_log.go @@ -8,12 +8,10 @@ import ( // AuditLogEvent is an 8-bit unsigned integer representing an audit log event. type AuditLogEvent int -// AuditLogEventGuildUpdate ... const ( AuditLogEventGuildUpdate AuditLogEvent = 1 ) -// AuditLogEventChannelCreate const ( AuditLogEventChannelCreate AuditLogEvent = iota + 10 AuditLogEventChannelUpdate @@ -23,7 +21,6 @@ const ( AuditLogEventChannelOverwriteDelete ) -// AuditLogEventMemberKick const ( AuditLogEventMemberKick AuditLogEvent = iota + 20 AuditLogEventMemberPrune @@ -36,35 +33,30 @@ const ( AuditLogEventBotAdd ) -// AuditLogEventRoleCreate const ( AuditLogEventRoleCreate AuditLogEvent = iota + 30 AuditLogEventRoleUpdate AuditLogEventRoleDelete ) -// AuditLogEventInviteCreate const ( AuditLogEventInviteCreate AuditLogEvent = iota + 40 AuditLogEventInviteUpdate AuditLogEventInviteDelete ) -// AuditLogEventWebhookCreate const ( AuditLogEventWebhookCreate AuditLogEvent = iota + 50 AuditLogEventWebhookUpdate AuditLogEventWebhookDelete ) -// AuditLogEventEmojiCreate const ( AuditLogEventEmojiCreate AuditLogEvent = iota + 60 AuditLogEventEmojiUpdate AuditLogEventEmojiDelete ) -// AuditLogEventMessageDelete const ( AuditLogEventMessageDelete AuditLogEvent = iota + 72 AuditLogEventMessageBulkDelete @@ -72,7 +64,6 @@ const ( AuditLogEventMessageUnpin ) -// AuditLogEventIntegrationCreate const ( AuditLogEventIntegrationCreate AuditLogEvent = iota + 80 AuditLogEventIntegrationUpdate @@ -82,28 +73,24 @@ const ( AuditLogEventStageInstanceDelete ) -// AuditLogEventStickerCreate const ( AuditLogEventStickerCreate AuditLogEvent = iota + 90 AuditLogEventStickerUpdate AuditLogEventStickerDelete ) -// AuditLogGuildScheduledEventCreate const ( AuditLogGuildScheduledEventCreate AuditLogEvent = iota + 100 AuditLogGuildScheduledEventUpdate AuditLogGuildScheduledEventDelete ) -// AuditLogThreadCreate const ( AuditLogThreadCreate AuditLogEvent = iota + 110 AuditLogThreadUpdate AuditLogThreadDelete ) -// AuditLogApplicationCommandPermissionUpdate ... const ( AuditLogApplicationCommandPermissionUpdate AuditLogEvent = 121 ) @@ -122,6 +109,19 @@ const ( AuditLogCreatorMonetizationTermsAccepted ) +const ( + AuditLogOnboardingPromptCreate AuditLogEvent = iota + 163 + AuditLogOnboardingPromptUpdate + AuditLogOnboardingPromptDelete + AuditLogOnboardingCreate + AuditLogOnboardingUpdate +) + +const ( + AuditLogHomeSettingsCreate AuditLogEvent = iota + 190 + AuditLogHomeSettingsUpdate +) + // AuditLog (https://discord.com/developers/docs/resources/audit-log) These are logs of events that occurred, accessible via the Discord type AuditLog struct { ApplicationCommands []ApplicationCommand `json:"application_commands"` From b81270a6c1e5df90d7e28f589cd823529fca366e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 23 May 2024 21:26:21 +0200 Subject: [PATCH 02/31] Handle group DMs (channels) (#360) --- discord/channel.go | 90 +++++++++++++++++++++++++++++++++++++++++ discord/channels_raw.go | 10 +++++ 2 files changed, 100 insertions(+) diff --git a/discord/channel.go b/discord/channel.go index 0249b690..fe32139e 100644 --- a/discord/channel.go +++ b/discord/channel.go @@ -185,6 +185,11 @@ func (u *UnmarshalChannel) UnmarshalJSON(data []byte) error { err = json.Unmarshal(data, &v) channel = v + case ChannelTypeGroupDM: + var v GroupDMChannel + err = json.Unmarshal(data, &v) + channel = v + case ChannelTypeGuildCategory: var v GuildCategoryChannel err = json.Unmarshal(data, &v) @@ -423,6 +428,91 @@ func (c DMChannel) CreatedAt() time.Time { func (DMChannel) channel() {} func (DMChannel) messageChannel() {} +var ( + _ Channel = (*GroupDMChannel)(nil) + _ MessageChannel = (*GroupDMChannel)(nil) +) + +type GroupDMChannel struct { + id snowflake.ID + ownerID *snowflake.ID + name string + lastPinTimestamp *time.Time + lastMessageID *snowflake.ID + icon *string +} + +func (c *GroupDMChannel) UnmarshalJSON(data []byte) error { + var v groupDMChannel + if err := json.Unmarshal(data, &v); err != nil { + return err + } + + c.id = v.ID + c.ownerID = v.OwnerID + c.name = v.Name + c.lastPinTimestamp = v.LastPinTimestamp + c.lastMessageID = v.LastMessageID + c.icon = v.Icon + return nil +} + +func (c GroupDMChannel) MarshalJSON() ([]byte, error) { + return json.Marshal(groupDMChannel{ + ID: c.id, + Type: c.Type(), + OwnerID: c.ownerID, + Name: c.name, + LastPinTimestamp: c.lastPinTimestamp, + LastMessageID: c.lastMessageID, + Icon: c.icon, + }) +} + +func (c GroupDMChannel) String() string { + return channelString(c) +} + +func (c GroupDMChannel) ID() snowflake.ID { + return c.id +} + +func (GroupDMChannel) Type() ChannelType { + return ChannelTypeGroupDM +} + +func (c GroupDMChannel) OwnerID() *snowflake.ID { + return c.ownerID +} + +func (c GroupDMChannel) Name() string { + return c.name +} + +func (c GroupDMChannel) LastPinTimestamp() *time.Time { + return c.lastPinTimestamp +} + +func (c GroupDMChannel) LastMessageID() *snowflake.ID { + return c.lastMessageID +} + +func (c GroupDMChannel) CreatedAt() time.Time { + return c.id.Time() +} + +// IconURL returns the icon URL of this group DM or nil if not set +func (c GroupDMChannel) IconURL(opts ...CDNOpt) *string { + if c.icon == nil { + return nil + } + url := formatAssetURL(ChannelIcon, opts, c.id, *c.icon) + return &url +} + +func (GroupDMChannel) channel() {} +func (GroupDMChannel) messageChannel() {} + var ( _ Channel = (*GuildVoiceChannel)(nil) _ GuildChannel = (*GuildVoiceChannel)(nil) diff --git a/discord/channels_raw.go b/discord/channels_raw.go index ac66f8d5..1dba72b2 100644 --- a/discord/channels_raw.go +++ b/discord/channels_raw.go @@ -15,6 +15,16 @@ type dmChannel struct { LastPinTimestamp *time.Time `json:"last_pin_timestamp"` } +type groupDMChannel struct { + ID snowflake.ID `json:"id"` + Type ChannelType `json:"type"` + OwnerID *snowflake.ID `json:"owner_id"` + Name string `json:"name"` + LastPinTimestamp *time.Time `json:"last_pin_timestamp"` + LastMessageID *snowflake.ID `json:"last_message_id"` + Icon *string `json:"icon"` +} + type guildTextChannel struct { ID snowflake.ID `json:"id"` Type ChannelType `json:"type"` From 3599a10dcd526d2d7d790700b81cd13682d1d281 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Thu, 23 May 2024 21:31:17 +0200 Subject: [PATCH 03/31] Rename InteractionGuild funcs to PartialGuild() because they were clashing with the cache function --- discord/interaction.go | 2 +- discord/interaction_base.go | 2 +- discord/interaction_ping.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/discord/interaction.go b/discord/interaction.go index 59f131da..74d4dd37 100644 --- a/discord/interaction.go +++ b/discord/interaction.go @@ -56,7 +56,7 @@ type Interaction interface { ApplicationID() snowflake.ID Token() string Version() int - Guild() *InteractionGuild + PartialGuild() *InteractionGuild GuildID() *snowflake.ID // Deprecated: Use Interaction.Channel instead ChannelID() snowflake.ID diff --git a/discord/interaction_base.go b/discord/interaction_base.go index f6683472..f72c0bb4 100644 --- a/discord/interaction_base.go +++ b/discord/interaction_base.go @@ -37,7 +37,7 @@ func (i baseInteraction) Token() string { func (i baseInteraction) Version() int { return i.version } -func (i baseInteraction) Guild() *InteractionGuild { +func (i baseInteraction) PartialGuild() *InteractionGuild { return i.guild } func (i baseInteraction) GuildID() *snowflake.ID { diff --git a/discord/interaction_ping.go b/discord/interaction_ping.go index 8b586890..deef7cd2 100644 --- a/discord/interaction_ping.go +++ b/discord/interaction_ping.go @@ -63,7 +63,8 @@ func (i PingInteraction) Version() int { func (i PingInteraction) CreatedAt() time.Time { return i.id.Time() } -func (PingInteraction) Guild() *InteractionGuild { + +func (PingInteraction) PartialGuild() *InteractionGuild { return nil } From 5bb14bb9f74f435e5054dce934c229671209f87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?To=CF=80?= Date: Sat, 25 May 2024 11:38:02 +0200 Subject: [PATCH 04/31] fix stuck at mutex when reconnecting and error happens in Gateway.Open (#361) --- gateway/gateway_impl.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gateway/gateway_impl.go b/gateway/gateway_impl.go index e1d5d5cb..4ea8665a 100644 --- a/gateway/gateway_impl.go +++ b/gateway/gateway_impl.go @@ -94,8 +94,7 @@ func (g *gatewayImpl) open(ctx context.Context) error { g.lastHeartbeatSent = time.Now().UTC() conn, rs, err := g.config.Dialer.DialContext(ctx, gatewayURL, nil) if err != nil { - g.Close(ctx) - body := "empty" + body := "" if rs != nil && rs.Body != nil { defer func() { _ = rs.Body.Close() From fd872a169652d46a3fadf6369e70a75e3b2ce13e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 31 May 2024 16:52:46 +0200 Subject: [PATCH 05/31] Add member profiles automod rule (#256) --- discord/auto_moderation.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discord/auto_moderation.go b/discord/auto_moderation.go index 83a2c77d..4ac8d505 100644 --- a/discord/auto_moderation.go +++ b/discord/auto_moderation.go @@ -10,6 +10,7 @@ type AutoModerationEventType int const ( AutoModerationEventTypeMessageSend AutoModerationEventType = iota + 1 + AutoModerationEventTypeMemberUpdate ) type AutoModerationTriggerType int @@ -20,6 +21,7 @@ const ( AutoModerationTriggerTypeSpam AutoModerationTriggerTypeKeywordPresent AutoModerationTriggerTypeMentionSpam + AutoModerationTriggerTypeMemberProfile ) type AutoModerationTriggerMetadata struct { @@ -45,6 +47,7 @@ const ( AutoModerationActionTypeBlockMessage AutoModerationActionType = iota + 1 AutoModerationActionTypeSendAlertMessage AutoModerationActionTypeTimeout + AutoModerationActionTypeBlockMemberInteraction ) type AutoModerationAction struct { From 49119a66e2b5d1ce84426b76f374b9334106f8f1 Mon Sep 17 00:00:00 2001 From: topi314 Date: Wed, 5 Jun 2024 12:54:18 +0200 Subject: [PATCH 06/31] fix error when creating or updating global application command --- rest/applications.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest/applications.go b/rest/applications.go index b90a14ad..a73533fc 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -70,7 +70,7 @@ func (s *applicationsImpl) GetGlobalCommands(applicationID snowflake.ID, withLoc func (s *applicationsImpl) GetGlobalCommand(applicationID snowflake.ID, commandID snowflake.ID, opts ...RequestOpt) (command discord.ApplicationCommand, err error) { var unmarshalCommand discord.UnmarshalApplicationCommand - err = s.client.Do(GetGlobalCommand.Compile(nil, applicationID, commandID), nil, &command, opts...) + err = s.client.Do(GetGlobalCommand.Compile(nil, applicationID, commandID), nil, &unmarshalCommand, opts...) if err == nil { command = unmarshalCommand.ApplicationCommand } @@ -79,7 +79,7 @@ func (s *applicationsImpl) GetGlobalCommand(applicationID snowflake.ID, commandI func (s *applicationsImpl) CreateGlobalCommand(applicationID snowflake.ID, commandCreate discord.ApplicationCommandCreate, opts ...RequestOpt) (command discord.ApplicationCommand, err error) { var unmarshalCommand discord.UnmarshalApplicationCommand - err = s.client.Do(CreateGlobalCommand.Compile(nil, applicationID), commandCreate, &command, opts...) + err = s.client.Do(CreateGlobalCommand.Compile(nil, applicationID), commandCreate, &unmarshalCommand, opts...) if err == nil { command = unmarshalCommand.ApplicationCommand } From d6c9b6ac34f7ad0d738bf4572161cd06f52db372 Mon Sep 17 00:00:00 2001 From: sebm253 Date: Mon, 10 Jun 2024 19:29:16 +0200 Subject: [PATCH 07/31] Add MessageTypePurchaseNotification and update deletable types https://github.com/discord/discord-api-docs/pull/6927 --- discord/message.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/discord/message.go b/discord/message.go index 583f38c4..8c3c20c7 100644 --- a/discord/message.go +++ b/discord/message.go @@ -48,6 +48,7 @@ const ( _ MessageTypeStageTopic MessageTypeGuildApplicationPremiumSubscription + MessageTypePurchaseNotification MessageType = 44 ) func (t MessageType) System() bool { @@ -63,9 +64,7 @@ func (t MessageType) System() bool { func (t MessageType) Deleteable() bool { switch t { case MessageTypeRecipientAdd, MessageTypeRecipientRemove, MessageTypeCall, - MessageTypeChannelNameChange, MessageTypeChannelIconChange, MessageTypeGuildDiscoveryDisqualified, - MessageTypeGuildDiscoveryRequalified, MessageTypeGuildDiscoveryGracePeriodInitialWarning, - MessageTypeGuildDiscoveryGracePeriodFinalWarning, MessageTypeThreadStarterMessage: + MessageTypeChannelNameChange, MessageTypeChannelIconChange, MessageTypeThreadStarterMessage: return false default: From 1087c1a73eafdffbffe1de128f3df8c014e315d8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 10 Jun 2024 21:32:13 +0200 Subject: [PATCH 08/31] Add PermissionUseExternalApps (#363) https://github.com/discord/discord-api-docs/pull/6913 --- discord/permissions.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/permissions.go b/discord/permissions.go index 96c18a93..2206f295 100644 --- a/discord/permissions.go +++ b/discord/permissions.go @@ -66,6 +66,7 @@ const ( _ _ PermissionSendPolls + PermissionUseExternalApps PermissionsAllText = PermissionViewChannel | PermissionSendMessages | @@ -76,7 +77,8 @@ const ( PermissionReadMessageHistory | PermissionMentionEveryone | PermissionSendVoiceMessages | - PermissionSendPolls + PermissionSendPolls | + PermissionUseExternalApps PermissionsAllThread = PermissionManageThreads | PermissionCreatePublicThreads | @@ -175,6 +177,7 @@ var permissions = map[Permissions]string{ PermissionViewGuildInsights: "View Server Insights", PermissionSendVoiceMessages: "Send Voice Messages", PermissionSendPolls: "Create Polls", + PermissionUseExternalApps: "Use External Apps", } func (p Permissions) String() string { From 7380d44d395ce5152ac9c1101448afd7e904ee20 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 15 Jun 2024 18:12:18 +0200 Subject: [PATCH 09/31] Build ButtonComponents instead of using the helper (#364) * Build ButtonComponents instead of using the helper * whoops --- discord/component.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/discord/component.go b/discord/component.go index b8c0dd3e..734597fd 100644 --- a/discord/component.go +++ b/discord/component.go @@ -248,27 +248,47 @@ func NewButton(style ButtonStyle, label string, customID string, url string) But // NewPrimaryButton creates a new ButtonComponent with ButtonStylePrimary & the provided parameters func NewPrimaryButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStylePrimary, label, customID, "") + return ButtonComponent{ + Style: ButtonStylePrimary, + Label: label, + CustomID: customID, + } } // NewSecondaryButton creates a new ButtonComponent with ButtonStyleSecondary & the provided parameters func NewSecondaryButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleSecondary, label, customID, "") + return ButtonComponent{ + Style: ButtonStyleSecondary, + Label: label, + CustomID: customID, + } } // NewSuccessButton creates a new ButtonComponent with ButtonStyleSuccess & the provided parameters func NewSuccessButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleSuccess, label, customID, "") + return ButtonComponent{ + Style: ButtonStyleSuccess, + Label: label, + CustomID: customID, + } } // NewDangerButton creates a new ButtonComponent with ButtonStyleDanger & the provided parameters func NewDangerButton(label string, customID string) ButtonComponent { - return NewButton(ButtonStyleDanger, label, customID, "") + return ButtonComponent{ + Style: ButtonStyleDanger, + Label: label, + CustomID: customID, + } } // NewLinkButton creates a new link ButtonComponent with ButtonStyleLink & the provided parameters func NewLinkButton(label string, url string) ButtonComponent { - return NewButton(ButtonStyleLink, label, "", url) + return ButtonComponent{ + Style: ButtonStyleLink, + Label: label, + URL: url, + } } var ( From 44021d1db2cab11d646fc922efda580b460b6e1a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 17 Jun 2024 21:16:52 +0200 Subject: [PATCH 10/31] Add ButtonStylePremium (#359) * Add ButtonStylePremium * remove label --- discord/component.go | 19 ++++++++++++++++++- events/interaction_events.go | 3 +++ handler/interaction.go | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/discord/component.go b/discord/component.go index 734597fd..f43611e7 100644 --- a/discord/component.go +++ b/discord/component.go @@ -234,15 +234,17 @@ const ( ButtonStyleSuccess ButtonStyleDanger ButtonStyleLink + ButtonStylePremium ) // NewButton creates a new ButtonComponent with the provided parameters. Link ButtonComponent(s) need a URL and other ButtonComponent(s) need a customID -func NewButton(style ButtonStyle, label string, customID string, url string) ButtonComponent { +func NewButton(style ButtonStyle, label string, customID string, url string, skuID snowflake.ID) ButtonComponent { return ButtonComponent{ Style: style, CustomID: customID, URL: url, Label: label, + SkuID: skuID, } } @@ -291,6 +293,14 @@ func NewLinkButton(label string, url string) ButtonComponent { } } +// NewPremiumButton creates a new ButtonComponent with ButtonStylePremium & the provided parameters +func NewPremiumButton(skuID snowflake.ID) ButtonComponent { + return ButtonComponent{ + Style: ButtonStylePremium, + SkuID: skuID, + } +} + var ( _ Component = (*ButtonComponent)(nil) _ InteractiveComponent = (*ButtonComponent)(nil) @@ -301,6 +311,7 @@ type ButtonComponent struct { Label string `json:"label,omitempty"` Emoji *ComponentEmoji `json:"emoji,omitempty"` CustomID string `json:"custom_id,omitempty"` + SkuID snowflake.ID `json:"sku_id,omitempty"` URL string `json:"url,omitempty"` Disabled bool `json:"disabled,omitempty"` } @@ -362,6 +373,12 @@ func (c ButtonComponent) WithURL(url string) ButtonComponent { return c } +// WithSkuID returns a new ButtonComponent with the provided skuID +func (c ButtonComponent) WithSkuID(skuID snowflake.ID) ButtonComponent { + c.SkuID = skuID + return c +} + // AsEnabled returns a new ButtonComponent but enabled func (c ButtonComponent) AsEnabled() ButtonComponent { c.Disabled = false diff --git a/events/interaction_events.go b/events/interaction_events.go index 2f04e250..a53a6588 100644 --- a/events/interaction_events.go +++ b/events/interaction_events.go @@ -61,6 +61,7 @@ func (e *ApplicationCommandInteractionCreate) Modal(modalCreate discord.ModalCre return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ApplicationCommandInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) @@ -112,6 +113,7 @@ func (e *ComponentInteractionCreate) Modal(modalCreate discord.ModalCreate, opts return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ComponentInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) @@ -180,6 +182,7 @@ func (e *ModalSubmitInteractionCreate) DeferUpdateMessage(opts ...rest.RequestOp return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *ModalSubmitInteractionCreate) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) diff --git a/handler/interaction.go b/handler/interaction.go index 745c037b..3d2c58f7 100644 --- a/handler/interaction.go +++ b/handler/interaction.go @@ -40,6 +40,7 @@ func (e *InteractionEvent) DeferUpdateMessage(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...) } +// Deprecated: Respond with a discord.ButtonStylePremium button instead. // PremiumRequired responds to the interaction with an upgrade button if available. func (e *InteractionEvent) PremiumRequired(opts ...rest.RequestOpt) error { return e.Respond(discord.InteractionResponseTypePremiumRequired, nil, opts...) From 2bb7320557f03835783c1287ec36bbcf516e836d Mon Sep 17 00:00:00 2001 From: Malix Date: Mon, 24 Jun 2024 22:10:45 +0200 Subject: [PATCH 11/31] remove: disgo.OS (#366) --- disgo.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/disgo.go b/disgo.go index e71641d2..cd494f41 100644 --- a/disgo.go +++ b/disgo.go @@ -48,7 +48,6 @@ package disgo import ( "runtime" "runtime/debug" - "strings" "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/handlers" @@ -68,9 +67,6 @@ var ( Version = getVersion() SemVersion = "semver:" + Version - - // OS is the currently used OS - OS = getOS() ) func getVersion() string { @@ -85,17 +81,6 @@ func getVersion() string { return "unknown" } -func getOS() string { - os := runtime.GOOS - if strings.HasPrefix(os, "windows") { - return "windows" - } - if strings.HasPrefix(os, "darwin") { - return "darwin" - } - return "linux" -} - // New creates a new bot.Client with the provided token & bot.ConfigOpt(s) func New(token string, opts ...bot.ConfigOpt) (bot.Client, error) { config := bot.DefaultConfig(handlers.GetGatewayHandlers(), handlers.GetHTTPServerHandler()) @@ -105,7 +90,7 @@ func New(token string, opts ...bot.ConfigOpt) (bot.Client, error) { config, handlers.DefaultGatewayEventHandlerFunc, handlers.DefaultHTTPServerEventHandlerFunc, - OS, + runtime.GOOS, Name, GitHub, Version, From 7dbeaeb276e466e99d90ae3775f89f08667c355b Mon Sep 17 00:00:00 2001 From: sebm253 Date: Wed, 26 Jun 2024 00:02:37 +0200 Subject: [PATCH 12/31] Add Title to Attachment --- discord/attachment.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/attachment.go b/discord/attachment.go index 4a93a5a2..8d67b40b 100644 --- a/discord/attachment.go +++ b/discord/attachment.go @@ -10,6 +10,7 @@ import ( type Attachment struct { ID snowflake.ID `json:"id,omitempty"` Filename string `json:"filename,omitempty"` + Title *string `json:"title,omitempty"` Description *string `json:"description,omitempty"` ContentType *string `json:"content_type,omitempty"` Size int `json:"size,omitempty"` From 253e4ccdfc25e01c621c0d4649cef02bc0492641 Mon Sep 17 00:00:00 2001 From: sebm253 Date: Wed, 3 Jul 2024 17:59:24 +0200 Subject: [PATCH 13/31] Remove IntegrationTypes from Application --- discord/application.go | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/application.go b/discord/application.go index c100abe9..3d0c737e 100644 --- a/discord/application.go +++ b/discord/application.go @@ -38,7 +38,6 @@ type Application struct { CoverImage *string `json:"cover_image,omitempty"` Flags ApplicationFlags `json:"flags,omitempty"` ApproximateGuildCount *int `json:"approximate_guild_count,omitempty"` - IntegrationTypes []ApplicationIntegrationType `json:"integration_types"` IntegrationTypesConfig ApplicationIntegrationTypesConfig `json:"integration_types_config"` } From f37f273ae7379da846dc594e2549d749e3f62195 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 15 Jul 2024 22:24:50 +0200 Subject: [PATCH 14/31] Add Banner to OAuth2Guild (#368) --- discord/guild.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/guild.go b/discord/guild.go index 879a2518..133336e9 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -256,6 +256,7 @@ type OAuth2Guild struct { ID snowflake.ID `json:"id"` Name string `json:"name"` Icon *string `json:"icon"` + Banner *string `json:"banner"` Owner bool `json:"owner"` Permissions Permissions `json:"permissions"` Features []GuildFeature `json:"features"` From bf66a212cb6aee2ee8ccb87ac1897fc47e27d5c7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 15 Jul 2024 22:24:58 +0200 Subject: [PATCH 15/31] Add ConnectionTypeRoblox (#371) --- discord/connection.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/connection.go b/discord/connection.go index 5ba69755..2ec79fcd 100644 --- a/discord/connection.go +++ b/discord/connection.go @@ -28,6 +28,7 @@ const ( ConnectionTypePlayStationNetwork ConnectionType = "playstation" ConnectionTypeReddit ConnectionType = "reddit" ConnectionTypeRiotGames ConnectionType = "riotgames" + ConnectionTypeRoblox ConnectionType = "roblox" ConnectionTypeSpotify ConnectionType = "spotify" ConnectionTypeSkype ConnectionType = "skype" ConnectionTypeSteam ConnectionType = "steam" From b9c16e9401f1625806c3cd46968882d0935dc6ad Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 16 Jul 2024 21:07:03 +0200 Subject: [PATCH 16/31] Add message forwarding (#350) * Add message forwarding * support multiple snapshots https://github.com/discord/discord-api-docs/pull/6818/commits/14e1fa742142ff85f6c582d81e8c62ab810e1f0d * fix snapshot structure * remove Guild from MessageSnapshot * add fields to PartialMessage --- discord/message.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/discord/message.go b/discord/message.go index 8c3c20c7..4b8f3f03 100644 --- a/discord/message.go +++ b/discord/message.go @@ -102,6 +102,7 @@ type Message struct { Type MessageType `json:"type"` Flags MessageFlags `json:"flags"` MessageReference *MessageReference `json:"message_reference,omitempty"` + MessageSnapshots []MessageSnapshot `json:"message_snapshots,omitempty"` Interaction *MessageInteraction `json:"interaction,omitempty"` WebhookID *snowflake.ID `json:"webhook_id,omitempty"` Activity *MessageActivity `json:"activity,omitempty"` @@ -407,10 +408,34 @@ type MessageApplication struct { // MessageReference is a reference to another message type MessageReference struct { - MessageID *snowflake.ID `json:"message_id"` - ChannelID *snowflake.ID `json:"channel_id,omitempty"` - GuildID *snowflake.ID `json:"guild_id,omitempty"` - FailIfNotExists bool `json:"fail_if_not_exists,omitempty"` + Type MessageReferenceType `json:"type,omitempty"` + MessageID *snowflake.ID `json:"message_id"` + ChannelID *snowflake.ID `json:"channel_id,omitempty"` + GuildID *snowflake.ID `json:"guild_id,omitempty"` + FailIfNotExists bool `json:"fail_if_not_exists,omitempty"` +} + +type MessageReferenceType int + +const ( + MessageReferenceTypeDefault MessageReferenceType = iota + MessageReferenceTypeForward +) + +type MessageSnapshot struct { + Message PartialMessage `json:"message"` +} + +type PartialMessage struct { + Type MessageType `json:"type"` + Content string `json:"content,omitempty"` + Embeds []Embed `json:"embeds,omitempty"` + Attachments []Attachment `json:"attachments"` + CreatedAt time.Time `json:"timestamp"` + EditedTimestamp *time.Time `json:"edited_timestamp"` + Flags MessageFlags `json:"flags"` + Mentions []User `json:"mentions"` + MentionRoles []snowflake.ID `json:"mention_roles"` } // MessageInteraction is sent on the Message object when the message is a response to an interaction From a973fd9cf43baf07a6c743d186e44de0382c9481 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 18 Jul 2024 17:14:11 +0200 Subject: [PATCH 17/31] Add IconURL and BannerURL to OAuth2Guild (#370) * Add Banner to OAuth2Guild * Add IconURL and BannerURL to OAuth2Guild --- discord/guild.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/discord/guild.go b/discord/guild.go index 133336e9..bc4d2c5d 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -264,6 +264,22 @@ type OAuth2Guild struct { ApproximatePresenceCount int `json:"approximate_presence_count"` } +func (g OAuth2Guild) IconURL(opts ...CDNOpt) *string { + if g.Icon == nil { + return nil + } + url := formatAssetURL(GuildIcon, opts, g.ID, *g.Icon) + return &url +} + +func (g OAuth2Guild) BannerURL(opts ...CDNOpt) *string { + if g.Banner == nil { + return nil + } + url := formatAssetURL(GuildBanner, opts, g.ID, *g.Banner) + return &url +} + // GuildWelcomeScreen is the Welcome Screen of a Guild type GuildWelcomeScreen struct { Description *string `json:"description,omitempty"` From bc3930878ecbb7c6b89c02247c3ff2d818bdd044 Mon Sep 17 00:00:00 2001 From: topi314 Date: Fri, 19 Jul 2024 19:10:47 +0200 Subject: [PATCH 18/31] update disgoorg/snowflake and other dependencies --- _examples/application_commands/http/go.mod | 12 ++++---- _examples/application_commands/http/go.sum | 33 +++++++++------------- go.mod | 11 ++++---- go.sum | 22 +++++++-------- 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/_examples/application_commands/http/go.mod b/_examples/application_commands/http/go.mod index 2084037f..216350f3 100644 --- a/_examples/application_commands/http/go.mod +++ b/_examples/application_commands/http/go.mod @@ -5,15 +5,15 @@ go 1.21 replace github.com/disgoorg/disgo => ../../../ require ( - github.com/disgoorg/disgo v0.16.8 - github.com/disgoorg/snowflake/v2 v2.0.1 - github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce + github.com/disgoorg/disgo v0.18.8 + github.com/disgoorg/snowflake/v2 v2.0.2 + github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a ) require ( github.com/disgoorg/json v1.1.0 // indirect - github.com/gorilla/websocket v1.5.1 // indirect + github.com/gorilla/websocket v1.5.3 // indirect github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/crypto v0.25.0 // indirect + golang.org/x/sys v0.22.0 // indirect ) diff --git a/_examples/application_commands/http/go.sum b/_examples/application_commands/http/go.sum index aeac0e15..e0961137 100644 --- a/_examples/application_commands/http/go.sum +++ b/_examples/application_commands/http/go.sum @@ -2,28 +2,21 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= -github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0= -github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce h1:/pEpMk55wH0X+E5zedGEMOdLuWmV8P4+4W3+LZaM6kg= -github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= +github.com/disgoorg/snowflake/v2 v2.0.2 h1:BLgntOerJwbOhYQ7dwHtVDw15GQjwDuKOVfSih4YPFY= +github.com/disgoorg/snowflake/v2 v2.0.2/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q= +github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE= -github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s= +github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxEmTbaqt1hkJ/t6skqEGYiMag343ucI= github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go.mod b/go.mod index baf66a37..6c17bb14 100644 --- a/go.mod +++ b/go.mod @@ -4,17 +4,16 @@ go 1.21 require ( github.com/disgoorg/json v1.1.0 - github.com/disgoorg/snowflake/v2 v2.0.1 - github.com/gorilla/websocket v1.5.1 + github.com/disgoorg/snowflake/v2 v2.0.2 + github.com/gorilla/websocket v1.5.3 github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad - github.com/stretchr/testify v1.8.4 - golang.org/x/crypto v0.19.0 + github.com/stretchr/testify v1.9.0 + golang.org/x/crypto v0.25.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/sys v0.17.0 // indirect + golang.org/x/sys v0.22.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d4982d70..6b21ac73 100644 --- a/go.sum +++ b/go.sum @@ -2,22 +2,20 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= -github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0= -github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/disgoorg/snowflake/v2 v2.0.2 h1:BLgntOerJwbOhYQ7dwHtVDw15GQjwDuKOVfSih4YPFY= +github.com/disgoorg/snowflake/v2 v2.0.2/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxEmTbaqt1hkJ/t6skqEGYiMag343ucI= github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From 564ae163b9bb6ea2e3263503eb6bbb927166ae87 Mon Sep 17 00:00:00 2001 From: topi314 Date: Fri, 19 Jul 2024 22:19:52 +0200 Subject: [PATCH 19/31] update disgoorg/snowflake --- _examples/application_commands/http/go.mod | 2 +- _examples/application_commands/http/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/_examples/application_commands/http/go.mod b/_examples/application_commands/http/go.mod index 216350f3..a753d77a 100644 --- a/_examples/application_commands/http/go.mod +++ b/_examples/application_commands/http/go.mod @@ -6,7 +6,7 @@ replace github.com/disgoorg/disgo => ../../../ require ( github.com/disgoorg/disgo v0.18.8 - github.com/disgoorg/snowflake/v2 v2.0.2 + github.com/disgoorg/snowflake/v2 v2.0.3 github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a ) diff --git a/_examples/application_commands/http/go.sum b/_examples/application_commands/http/go.sum index e0961137..79e19b88 100644 --- a/_examples/application_commands/http/go.sum +++ b/_examples/application_commands/http/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= -github.com/disgoorg/snowflake/v2 v2.0.2 h1:BLgntOerJwbOhYQ7dwHtVDw15GQjwDuKOVfSih4YPFY= -github.com/disgoorg/snowflake/v2 v2.0.2/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= +github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro= +github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q= diff --git a/go.mod b/go.mod index 6c17bb14..b0052dca 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/disgoorg/json v1.1.0 - github.com/disgoorg/snowflake/v2 v2.0.2 + github.com/disgoorg/snowflake/v2 v2.0.3 github.com/gorilla/websocket v1.5.3 github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 6b21ac73..9d343049 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= -github.com/disgoorg/snowflake/v2 v2.0.2 h1:BLgntOerJwbOhYQ7dwHtVDw15GQjwDuKOVfSih4YPFY= -github.com/disgoorg/snowflake/v2 v2.0.2/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs= +github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro= +github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 47c540e90469195784b54d75e755e9e65b8c8f87 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 20 Jul 2024 12:27:21 +0200 Subject: [PATCH 20/31] Add application emojis (#373) * Add application emojis * rename funcs --- rest/applications.go | 38 ++++++++++++++++++++++++++++++++++++++ rest/rest_endpoints.go | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/rest/applications.go b/rest/applications.go index a73533fc..55837e53 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -43,6 +43,12 @@ type Applications interface { ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.SKU, error) + + GetApplicationEmojis(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.Emoji, error) + GetApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (*discord.Emoji, error) + CreateApplicationEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (*discord.Emoji, error) + UpdateApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (*discord.Emoji, error) + DeleteApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error } type applicationsImpl struct { @@ -219,6 +225,34 @@ func (s *applicationsImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOp return } +func (s *applicationsImpl) GetApplicationEmojis(applicationID snowflake.ID, opts ...RequestOpt) (emojis []discord.Emoji, err error) { + var rs emojisResponse + err = s.client.Do(GetApplicationEmojis.Compile(nil, applicationID), nil, &rs, opts...) + if err == nil { + emojis = rs.Items + } + return +} + +func (s *applicationsImpl) GetApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (emoji *discord.Emoji, err error) { + err = s.client.Do(GetApplicationEmoji.Compile(nil, applicationID, emojiID), nil, &emoji, opts...) + return +} + +func (s *applicationsImpl) CreateApplicationEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (emoji *discord.Emoji, err error) { + err = s.client.Do(CreateApplicationEmoji.Compile(nil, applicationID), emojiCreate, &emoji, opts...) + return +} + +func (s *applicationsImpl) UpdateApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (emoji *discord.Emoji, err error) { + err = s.client.Do(UpdateApplicationEmoji.Compile(nil, applicationID, emojiID), emojiUpdate, &emoji, opts...) + return +} + +func (s *applicationsImpl) DeleteApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error { + return s.client.Do(DeleteApplicationEmoji.Compile(nil, applicationID, emojiID), nil, nil, opts...) +} + func unmarshalApplicationCommandsToApplicationCommands(unmarshalCommands []discord.UnmarshalApplicationCommand) []discord.ApplicationCommand { commands := make([]discord.ApplicationCommand, len(unmarshalCommands)) for i := range unmarshalCommands { @@ -226,3 +260,7 @@ func unmarshalApplicationCommandsToApplicationCommands(unmarshalCommands []disco } return commands } + +type emojisResponse struct { + Items []discord.Emoji `json:"items"` +} diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 329bfe05..08e9c08f 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -303,6 +303,12 @@ var ( ConsumeEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements/{entitlement.id}/consume") GetSKUs = NewEndpoint(http.MethodGet, "/applications/{application.id}/skus") + + GetApplicationEmojis = NewEndpoint(http.MethodGet, "/applications/{application.id}/emojis") + GetApplicationEmoji = NewEndpoint(http.MethodGet, "/applications/{application.id}/emojis/{emoji.id}") + CreateApplicationEmoji = NewEndpoint(http.MethodPost, "/applications/{application.id}/emojis") + UpdateApplicationEmoji = NewEndpoint(http.MethodPatch, "/applications/{application.id}/emojis/{emoji.id}") + DeleteApplicationEmoji = NewEndpoint(http.MethodDelete, "/applications/{application.id}/emojis/{emoji.id}") ) // NewEndpoint returns a new Endpoint which requires bot auth with the given http method & route. From e70ebbc16258d65ee4817ac5dbc90b294253f08c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 20 Jul 2024 12:27:55 +0200 Subject: [PATCH 21/31] Add Banner to Member (#369) --- discord/cdn_endpoints.go | 1 + discord/member.go | 26 ++++++++++++++++++++++---- discord/user.go | 5 +---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/discord/cdn_endpoints.go b/discord/cdn_endpoints.go index 3b1a7ca3..597d3293 100644 --- a/discord/cdn_endpoints.go +++ b/discord/cdn_endpoints.go @@ -28,6 +28,7 @@ var ( ChannelIcon = NewCDN("/channel-icons/{channel.id}/{channel.icon.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP) MemberAvatar = NewCDN("/guilds/{guild.id}/users/{user.id}/avatars/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF) + MemberBanner = NewCDN("/guilds/{guild.id}/users/{user.id}/banners/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF) AvatarDecoration = NewCDN("/avatar-decoration-presets/{user.avatar.decoration.hash}", FileFormatPNG) diff --git a/discord/member.go b/discord/member.go index 2bf9278f..f6bd33ce 100644 --- a/discord/member.go +++ b/discord/member.go @@ -16,6 +16,7 @@ type Member struct { User User `json:"user"` Nick *string `json:"nick"` Avatar *string `json:"avatar"` + Banner *string `json:"banner"` RoleIDs []snowflake.ID `json:"roles,omitempty"` JoinedAt time.Time `json:"joined_at"` PremiumSince *time.Time `json:"premium_since,omitempty"` @@ -53,10 +54,7 @@ func (m Member) EffectiveAvatarURL(opts ...CDNOpt) string { if m.Avatar == nil { return m.User.EffectiveAvatarURL(opts...) } - if avatar := m.AvatarURL(opts...); avatar != nil { - return *avatar - } - return "" + return formatAssetURL(MemberAvatar, opts, m.GuildID, m.User.ID, *m.Avatar) } // AvatarURL returns the guild-specific avatar URL of the user if set or nil @@ -68,6 +66,26 @@ func (m Member) AvatarURL(opts ...CDNOpt) *string { return &url } +// EffectiveBannerURL returns the guild-specific banner URL of the user if set, falling back to the banner URL of the user +func (m Member) EffectiveBannerURL(opts ...CDNOpt) string { + if m.Banner == nil { + if banner := m.User.BannerURL(opts...); banner != nil { + return *banner + } + return "" + } + return formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner) +} + +// BannerURL returns the guild-specific banner URL of the user if set or nil +func (m Member) BannerURL(opts ...CDNOpt) *string { + if m.Banner == nil { + return nil + } + url := formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner) + return &url +} + // AvatarDecorationURL returns the avatar decoration URL if set or nil func (m Member) AvatarDecorationURL(opts ...CDNOpt) *string { if m.AvatarDecorationData == nil { diff --git a/discord/user.go b/discord/user.go index 68f58f5d..bdf74c4f 100644 --- a/discord/user.go +++ b/discord/user.go @@ -106,10 +106,7 @@ func (u User) EffectiveAvatarURL(opts ...CDNOpt) string { if u.Avatar == nil { return u.DefaultAvatarURL(opts...) } - if avatar := u.AvatarURL(opts...); avatar != nil { - return *avatar - } - return "" + return formatAssetURL(UserAvatar, opts, u.ID, *u.Avatar) } // AvatarURL returns the avatar URL of the user if set or nil From e13fad532f5cb4b9d82bf6d1deb00b7c2d1e5f23 Mon Sep 17 00:00:00 2001 From: sebm253 Date: Sat, 20 Jul 2024 17:29:41 +0200 Subject: [PATCH 22/31] Remove custom unmarshaller for EventMessageUpdate the timestamp is now properly sent on edits: https://github.com/discord/discord-api-docs/pull/7017 --- discord/message.go | 15 +++++++-------- gateway/gateway_events.go | 11 ----------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/discord/message.go b/discord/message.go index 4b8f3f03..d83a06e2 100644 --- a/discord/message.go +++ b/discord/message.go @@ -80,14 +80,13 @@ func MessageURL(guildID snowflake.ID, channelID snowflake.ID, messageID snowflak // Message is a struct for messages sent in discord text-based channels type Message struct { - ID snowflake.ID `json:"id"` - GuildID *snowflake.ID `json:"guild_id"` - Reactions []MessageReaction `json:"reactions"` - Attachments []Attachment `json:"attachments"` - TTS bool `json:"tts"` - Embeds []Embed `json:"embeds,omitempty"` - Components []ContainerComponent `json:"components,omitempty"` - // Note: for message update events, this field is populated by the creation of the ID during unmarshalling + ID snowflake.ID `json:"id"` + GuildID *snowflake.ID `json:"guild_id"` + Reactions []MessageReaction `json:"reactions"` + Attachments []Attachment `json:"attachments"` + TTS bool `json:"tts"` + Embeds []Embed `json:"embeds,omitempty"` + Components []ContainerComponent `json:"components,omitempty"` CreatedAt time.Time `json:"timestamp"` Mentions []User `json:"mentions"` MentionEveryone bool `json:"mention_everyone"` diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 7efd85bf..740a33b0 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -488,17 +488,6 @@ type EventMessageUpdate struct { discord.Message } -func (e *EventMessageUpdate) UnmarshalJSON(data []byte) error { - type eventMessageUpdate EventMessageUpdate - var v eventMessageUpdate - if err := json.Unmarshal(data, &v); err != nil { - return err - } - *e = EventMessageUpdate(v) - e.CreatedAt = e.ID.Time() - return nil -} - func (EventMessageUpdate) messageData() {} func (EventMessageUpdate) eventData() {} From b06f2e7a4f9f929daa5c6c8c982ce41046ea1a2b Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sun, 4 Aug 2024 13:08:07 +0200 Subject: [PATCH 23/31] Fix EmbedTypeGifV value and add EmbedTypeAutoModerationMessage --- discord/embed.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/discord/embed.go b/discord/embed.go index 3de752ff..afdb011b 100644 --- a/discord/embed.go +++ b/discord/embed.go @@ -7,12 +7,13 @@ type EmbedType string // Constants for EmbedType const ( - EmbedTypeRich EmbedType = "rich" - EmbedTypeImage EmbedType = "image" - EmbedTypeVideo EmbedType = "video" - EmbedTypeGifV EmbedType = "rich" - EmbedTypeArticle EmbedType = "article" - EmbedTypeLink EmbedType = "link" + EmbedTypeRich EmbedType = "rich" + EmbedTypeImage EmbedType = "image" + EmbedTypeVideo EmbedType = "video" + EmbedTypeGifV EmbedType = "gifv" + EmbedTypeArticle EmbedType = "article" + EmbedTypeLink EmbedType = "link" + EmbedTypeAutoModerationMessage EmbedType = "auto_moderation_message" ) // Embed allows you to send embeds to discord From 8f3c66b7ad857e5916a9b40d1d40d7e2bd6bb04d Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:34:11 +0200 Subject: [PATCH 24/31] Add ScheduledEventRecurrenceRule https://github.com/discord/discord-api-docs/pull/7058 --- discord/guild_scheduled_event.go | 129 ++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 35 deletions(-) diff --git a/discord/guild_scheduled_event.go b/discord/guild_scheduled_event.go index 93964faa..dbd673e9 100644 --- a/discord/guild_scheduled_event.go +++ b/discord/guild_scheduled_event.go @@ -9,22 +9,23 @@ import ( // GuildScheduledEvent a representation of a scheduled event in a Guild (https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object) type GuildScheduledEvent struct { - ID snowflake.ID `json:"id"` - GuildID snowflake.ID `json:"guild_id"` - ChannelID *snowflake.ID `json:"channel_id"` - CreatorID snowflake.ID `json:"creator_id"` - Name string `json:"name"` - Description string `json:"description"` - ScheduledStartTime time.Time `json:"scheduled_start_time"` - ScheduledEndTime *time.Time `json:"scheduled_end_time"` - PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"` - Status ScheduledEventStatus `json:"status"` - EntityType ScheduledEventEntityType `json:"entity_type"` - EntityID *snowflake.ID `json:"entity_id"` - EntityMetaData *EntityMetaData `json:"entity_metadata"` - Creator User `json:"creator"` - UserCount int `json:"user_count"` - Image *string `json:"image"` + ID snowflake.ID `json:"id"` + GuildID snowflake.ID `json:"guild_id"` + ChannelID *snowflake.ID `json:"channel_id"` + CreatorID snowflake.ID `json:"creator_id"` + Name string `json:"name"` + Description string `json:"description"` + ScheduledStartTime time.Time `json:"scheduled_start_time"` + ScheduledEndTime *time.Time `json:"scheduled_end_time"` + PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"` + Status ScheduledEventStatus `json:"status"` + EntityType ScheduledEventEntityType `json:"entity_type"` + EntityID *snowflake.ID `json:"entity_id"` + EntityMetaData *EntityMetaData `json:"entity_metadata"` + Creator User `json:"creator"` + UserCount int `json:"user_count"` + Image *string `json:"image"` + RecurrenceRule *ScheduledEventRecurrenceRule `json:"recurrence_rule"` } func (e GuildScheduledEvent) CreatedAt() time.Time { @@ -41,28 +42,30 @@ func (e GuildScheduledEvent) CoverURL(opts ...CDNOpt) *string { } type GuildScheduledEventCreate struct { - ChannelID snowflake.ID `json:"channel_id,omitempty"` - EntityMetaData *EntityMetaData `json:"entity_metadata,omitempty"` - Name string `json:"name"` - PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"` - ScheduledStartTime time.Time `json:"scheduled_start_time"` - ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"` - Description string `json:"description,omitempty"` - EntityType ScheduledEventEntityType `json:"entity_type"` - Image *Icon `json:"image,omitempty"` + ChannelID snowflake.ID `json:"channel_id,omitempty"` + EntityMetaData *EntityMetaData `json:"entity_metadata,omitempty"` + Name string `json:"name"` + PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"` + ScheduledStartTime time.Time `json:"scheduled_start_time"` + ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"` + Description string `json:"description,omitempty"` + EntityType ScheduledEventEntityType `json:"entity_type"` + Image *Icon `json:"image,omitempty"` + RecurrenceRule *ScheduledEventRecurrenceRule `json:"recurrence_rule,omitempty"` } type GuildScheduledEventUpdate struct { - ChannelID *snowflake.ID `json:"channel_id,omitempty"` - EntityMetaData *EntityMetaData `json:"entity_metadata,omitempty"` - Name string `json:"name,omitempty"` - PrivacyLevel *ScheduledEventPrivacyLevel `json:"privacy_level,omitempty"` - ScheduledStartTime *time.Time `json:"scheduled_start_time,omitempty"` - ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"` - Description *string `json:"description,omitempty"` - EntityType *ScheduledEventEntityType `json:"entity_type,omitempty"` - Status *ScheduledEventStatus `json:"status,omitempty"` - Image *json.Nullable[Icon] `json:"image,omitempty"` + ChannelID *snowflake.ID `json:"channel_id,omitempty"` + EntityMetaData *EntityMetaData `json:"entity_metadata,omitempty"` + Name string `json:"name,omitempty"` + PrivacyLevel *ScheduledEventPrivacyLevel `json:"privacy_level,omitempty"` + ScheduledStartTime *time.Time `json:"scheduled_start_time,omitempty"` + ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"` + Description *string `json:"description,omitempty"` + EntityType *ScheduledEventEntityType `json:"entity_type,omitempty"` + Status *ScheduledEventStatus `json:"status,omitempty"` + Image *json.Nullable[Icon] `json:"image,omitempty"` + RecurrenceRule *json.Nullable[ScheduledEventRecurrenceRule] `json:"recurrence_rule,omitempty"` } type GuildScheduledEventUser struct { @@ -98,6 +101,62 @@ const ( ScheduledEventEntityTypeExternal ) +type ScheduledEventRecurrenceRule struct { + Start time.Time `json:"start"` + End *time.Time `json:"end"` + Frequency ScheduledEventRecurrenceRuleFrequency `json:"frequency"` + Interval int `json:"interval"` + ByWeekday []ScheduledEventRecurrenceRuleWeekday `json:"by_weekday"` + ByNWeekday []ScheduledEventRecurrenceRuleNWeekday `json:"by_n_weekday"` + ByMonth []ScheduledEventRecurrenceRuleMonth `json:"by_month"` + ByMonthDay []int `json:"by_month_day"` + ByYearDay []int `json:"by_year_day"` + Count *int `json:"count"` +} + +type ScheduledEventRecurrenceRuleFrequency int + +const ( + ScheduledEventRecurrenceRuleFrequencyYearly ScheduledEventRecurrenceRuleFrequency = iota + ScheduledEventRecurrenceRuleFrequencyMonthly + ScheduledEventRecurrenceRuleFrequencyWeekly + ScheduledEventRecurrenceRuleFrequencyDaily +) + +type ScheduledEventRecurrenceRuleWeekday int + +const ( + ScheduledEventRecurrenceRuleWeekdayMonday ScheduledEventRecurrenceRuleWeekday = iota + ScheduledEventRecurrenceRuleWeekdayTuesday + ScheduledEventRecurrenceRuleWeekdayWednesday + ScheduledEventRecurrenceRuleWeekdayThursday + ScheduledEventRecurrenceRuleWeekdayFriday + ScheduledEventRecurrenceRuleWeekdaySaturday + ScheduledEventRecurrenceRuleWeekdaySunday +) + +type ScheduledEventRecurrenceRuleNWeekday struct { + N int `json:"n"` + Day ScheduledEventRecurrenceRuleWeekday `json:"day"` +} + +type ScheduledEventRecurrenceRuleMonth int + +const ( + ScheduledEventRecurrenceRuleMonthJanuary ScheduledEventRecurrenceRuleMonth = iota + 1 + ScheduledEventRecurrenceRuleMonthFebruary + ScheduledEventRecurrenceRuleMonthMarch + ScheduledEventRecurrenceRuleMonthApril + ScheduledEventRecurrenceRuleMonthMay + ScheduledEventRecurrenceRuleMonthJune + ScheduledEventRecurrenceRuleMonthJuly + ScheduledEventRecurrenceRuleMonthAugust + ScheduledEventRecurrenceRuleMonthSeptember + ScheduledEventRecurrenceRuleMonthOctober + ScheduledEventRecurrenceRuleMonthNovember + ScheduledEventRecurrenceRuleMonthDecember +) + // EntityMetaData additional metadata for the scheduled event (https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-metadata) type EntityMetaData struct { Location string `json:"location"` From 8e9d18dfa28bf7b96de024cc214a3f02d6d54c78 Mon Sep 17 00:00:00 2001 From: Sebastian <42180891+sebm253@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:46:58 +0200 Subject: [PATCH 25/31] Add get voice state endpoints (#375) --- rest/members.go | 12 ++++++++++++ rest/rest_endpoints.go | 2 ++ 2 files changed, 14 insertions(+) diff --git a/rest/members.go b/rest/members.go index ccaa6360..fca98657 100644 --- a/rest/members.go +++ b/rest/members.go @@ -25,6 +25,8 @@ type Members interface { UpdateCurrentMember(guildID snowflake.ID, nick string, opts ...RequestOpt) (*string, error) + GetCurrentUserVoiceState(guildID snowflake.ID, opts ...RequestOpt) (*discord.VoiceState, error) + GetUserVoiceState(guildID snowflake.ID, userID snowflake.ID, opts ...RequestOpt) (*discord.VoiceState, error) UpdateCurrentUserVoiceState(guildID snowflake.ID, currentUserVoiceStateUpdate discord.CurrentUserVoiceStateUpdate, opts ...RequestOpt) error UpdateUserVoiceState(guildID snowflake.ID, userID snowflake.ID, userVoiceStateUpdate discord.UserVoiceStateUpdate, opts ...RequestOpt) error } @@ -105,6 +107,16 @@ func (s *memberImpl) UpdateCurrentMember(guildID snowflake.ID, nick string, opts return } +func (s *memberImpl) GetCurrentUserVoiceState(guildID snowflake.ID, opts ...RequestOpt) (state *discord.VoiceState, err error) { + err = s.client.Do(GetCurrentUserVoiceState.Compile(nil, guildID), nil, &state, opts...) + return +} + +func (s *memberImpl) GetUserVoiceState(guildID snowflake.ID, userID snowflake.ID, opts ...RequestOpt) (state *discord.VoiceState, err error) { + err = s.client.Do(GetUserVoiceState.Compile(nil, guildID, userID), nil, &state, opts...) + return +} + func (s *memberImpl) UpdateCurrentUserVoiceState(guildID snowflake.ID, currentUserVoiceStateUpdate discord.CurrentUserVoiceStateUpdate, opts ...RequestOpt) error { return s.client.Do(UpdateCurrentUserVoiceState.Compile(nil, guildID), currentUserVoiceStateUpdate, nil, opts...) } diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 08e9c08f..5ec41297 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -93,6 +93,8 @@ var ( GetGuildOnboarding = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/onboarding") UpdateGuildOnboarding = NewEndpoint(http.MethodPut, "/guilds/{guild.id}/onboarding") + GetCurrentUserVoiceState = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/voice-states/@me") + GetUserVoiceState = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/voice-states/{user.id}") UpdateCurrentUserVoiceState = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/voice-states/@me") UpdateUserVoiceState = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/voice-states/{user.id}") ) From dc43cbe9a6de0e668548907f7dd03956dbce898d Mon Sep 17 00:00:00 2001 From: Sebastian <42180891+sebm253@users.noreply.github.com> Date: Sat, 10 Aug 2024 00:53:26 +0200 Subject: [PATCH 26/31] Add get sticker pack endpoint (#376) --- rest/rest_endpoints.go | 1 + rest/stickers.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 5ec41297..6385e587 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -229,6 +229,7 @@ var ( // Stickers var ( GetNitroStickerPacks = NewEndpoint(http.MethodGet, "/sticker-packs") + GetNitroStickerPack = NewEndpoint(http.MethodGet, "/sticker-packs/{pack.id}") GetSticker = NewEndpoint(http.MethodGet, "/stickers/{sticker.id}") GetGuildStickers = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/stickers") CreateGuildSticker = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/stickers") diff --git a/rest/stickers.go b/rest/stickers.go index 45090c9b..694ab0f8 100644 --- a/rest/stickers.go +++ b/rest/stickers.go @@ -14,6 +14,7 @@ func NewStickers(client Client) Stickers { type Stickers interface { GetNitroStickerPacks(opts ...RequestOpt) ([]discord.StickerPack, error) + GetNitroStickerPack(packID snowflake.ID, opts ...RequestOpt) (*discord.StickerPack, error) GetSticker(stickerID snowflake.ID, opts ...RequestOpt) (*discord.Sticker, error) GetStickers(guildID snowflake.ID, opts ...RequestOpt) ([]discord.Sticker, error) CreateSticker(guildID snowflake.ID, createSticker discord.StickerCreate, opts ...RequestOpt) (*discord.Sticker, error) @@ -34,6 +35,11 @@ func (s *stickerImpl) GetNitroStickerPacks(opts ...RequestOpt) (stickerPacks []d return } +func (s *stickerImpl) GetNitroStickerPack(packID snowflake.ID, opts ...RequestOpt) (pack *discord.StickerPack, err error) { + err = s.client.Do(GetNitroStickerPack.Compile(nil, packID), nil, &pack, opts...) + return +} + func (s *stickerImpl) GetSticker(stickerID snowflake.ID, opts ...RequestOpt) (sticker *discord.Sticker, err error) { err = s.client.Do(GetSticker.Compile(nil, stickerID), nil, &sticker, opts...) return From 6326854842d0425c2fcd4ff7089835fe73b8593c Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 10 Aug 2024 13:00:56 +0200 Subject: [PATCH 27/31] Add ApproximateUserInstallCount to Application https://github.com/discord/discord-api-docs/pull/7070 --- discord/application.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/application.go b/discord/application.go index 3d0c737e..21906703 100644 --- a/discord/application.go +++ b/discord/application.go @@ -38,6 +38,7 @@ type Application struct { CoverImage *string `json:"cover_image,omitempty"` Flags ApplicationFlags `json:"flags,omitempty"` ApproximateGuildCount *int `json:"approximate_guild_count,omitempty"` + ApproximateUserInstallCount *int `json:"approximate_user_install_count,omitempty"` IntegrationTypesConfig ApplicationIntegrationTypesConfig `json:"integration_types_config"` } From f24ca9aea841552cb235cd3386ca6f8a708b9096 Mon Sep 17 00:00:00 2001 From: topi314 Date: Mon, 12 Aug 2024 15:03:11 +0200 Subject: [PATCH 28/31] use discord.ExtendedInvite for GetGuildInvites & GetChannelInvites --- discord/invite.go | 1 - rest/invites.go | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/discord/invite.go b/discord/invite.go index 36bc7c74..3dd15129 100644 --- a/discord/invite.go +++ b/discord/invite.go @@ -22,7 +22,6 @@ type Invite struct { Code string `json:"code"` Guild *InviteGuild `json:"guild"` Channel *InviteChannel `json:"channel"` - ChannelID snowflake.ID `json:"channel_id"` Inviter *User `json:"inviter"` TargetUser *User `json:"target_user"` TargetType InviteTargetType `json:"target_user_type"` diff --git a/rest/invites.go b/rest/invites.go index 5416c455..20a46c81 100644 --- a/rest/invites.go +++ b/rest/invites.go @@ -16,8 +16,8 @@ type Invites interface { GetInvite(code string, opts ...RequestOpt) (*discord.Invite, error) CreateInvite(channelID snowflake.ID, inviteCreate discord.InviteCreate, opts ...RequestOpt) (*discord.Invite, error) DeleteInvite(code string, opts ...RequestOpt) (*discord.Invite, error) - GetGuildInvites(guildID snowflake.ID, opts ...RequestOpt) ([]discord.Invite, error) - GetChannelInvites(channelID snowflake.ID, opts ...RequestOpt) ([]discord.Invite, error) + GetGuildInvites(guildID snowflake.ID, opts ...RequestOpt) ([]discord.ExtendedInvite, error) + GetChannelInvites(channelID snowflake.ID, opts ...RequestOpt) ([]discord.ExtendedInvite, error) } type inviteImpl struct { @@ -39,12 +39,12 @@ func (s *inviteImpl) DeleteInvite(code string, opts ...RequestOpt) (invite *disc return } -func (s *inviteImpl) GetGuildInvites(guildID snowflake.ID, opts ...RequestOpt) (invites []discord.Invite, err error) { +func (s *inviteImpl) GetGuildInvites(guildID snowflake.ID, opts ...RequestOpt) (invites []discord.ExtendedInvite, err error) { err = s.client.Do(GetGuildInvites.Compile(nil, guildID), nil, &invites, opts...) return } -func (s *inviteImpl) GetChannelInvites(channelID snowflake.ID, opts ...RequestOpt) (invites []discord.Invite, err error) { +func (s *inviteImpl) GetChannelInvites(channelID snowflake.ID, opts ...RequestOpt) (invites []discord.ExtendedInvite, err error) { err = s.client.Do(GetChannelInvites.Compile(nil, channelID), nil, &invites, opts...) return } From 0f6d90b8eed3df647a38cf81422eec5d52038952 Mon Sep 17 00:00:00 2001 From: topi314 Date: Mon, 12 Aug 2024 15:29:34 +0200 Subject: [PATCH 29/31] fix invite create event --- events/guild_invite_events.go | 39 +++++++++++++++++++++++++---------- gateway/gateway_events.go | 13 +++++++++++- handlers/invite_handlers.go | 26 ++++++----------------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/events/guild_invite_events.go b/events/guild_invite_events.go index 756bf22c..095ff918 100644 --- a/events/guild_invite_events.go +++ b/events/guild_invite_events.go @@ -4,28 +4,45 @@ import ( "github.com/disgoorg/snowflake/v2" "github.com/disgoorg/disgo/discord" + "github.com/disgoorg/disgo/gateway" ) -// GenericInvite is called upon receiving InviteCreate or InviteDelete (requires gateway.IntentGuildInvites) -type GenericInvite struct { +// InviteCreate is called upon creation of a new discord.Invite (requires gateway.IntentGuildInvites) +type InviteCreate struct { *GenericEvent - GuildID *snowflake.ID - ChannelID snowflake.ID - Code string + + gateway.EventInviteCreate } // Channel returns the discord.GuildChannel the GenericInvite happened in. -func (e *GenericInvite) Channel() (discord.GuildChannel, bool) { +func (e *InviteCreate) Channel() (discord.GuildChannel, bool) { return e.Client().Caches().Channel(e.ChannelID) } -// InviteCreate is called upon creation of a new discord.Invite (requires gateway.IntentGuildInvites) -type InviteCreate struct { - *GenericInvite - Invite discord.Invite +func (e *InviteCreate) Guild() (discord.Guild, bool) { + if e.GuildID == nil { + return discord.Guild{}, false + } + return e.Client().Caches().Guild(*e.GuildID) } // InviteDelete is called upon deletion of a discord.Invite (requires gateway.IntentGuildInvites) type InviteDelete struct { - *GenericInvite + *GenericEvent + + GuildID *snowflake.ID + ChannelID snowflake.ID + Code string +} + +// Channel returns the discord.GuildChannel the GenericInvite happened in. +func (e *InviteDelete) Channel() (discord.GuildChannel, bool) { + return e.Client().Caches().Channel(e.ChannelID) +} + +func (e *InviteDelete) Guild() (discord.Guild, bool) { + if e.GuildID == nil { + return discord.Guild{}, false + } + return e.Client().Caches().Guild(*e.GuildID) } diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 740a33b0..ddbd35a4 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -462,7 +462,18 @@ func (EventInteractionCreate) messageData() {} func (EventInteractionCreate) eventData() {} type EventInviteCreate struct { - discord.Invite + ChannelID snowflake.ID `json:"channel_id"` + Code string `json:"code"` + CreatedAt time.Time `json:"created_at"` + GuildID *snowflake.ID `json:"guild_id"` + Inviter *discord.User `json:"inviter"` + MaxAge int `json:"max_age"` + MaxUses int `json:"max_uses"` + TargetType discord.InviteTargetType `json:"target_type"` + TargetUser *discord.User `json:"target_user"` + TargetApplication *discord.PartialApplication `json:"target_application"` + Temporary bool `json:"temporary"` + Uses int `json:"uses"` } func (EventInviteCreate) messageData() {} diff --git a/handlers/invite_handlers.go b/handlers/invite_handlers.go index 9ea078e8..d419be38 100644 --- a/handlers/invite_handlers.go +++ b/handlers/invite_handlers.go @@ -1,37 +1,23 @@ package handlers import ( - "github.com/disgoorg/snowflake/v2" - "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/gateway" ) func gatewayHandlerInviteCreate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventInviteCreate) { - var guildID *snowflake.ID - if event.Guild != nil { - guildID = &event.Guild.ID - } - client.EventManager().DispatchEvent(&events.InviteCreate{ - GenericInvite: &events.GenericInvite{ - GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), - GuildID: guildID, - Code: event.Code, - ChannelID: event.ChannelID, - }, - Invite: event.Invite, + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + EventInviteCreate: event, }) } func gatewayHandlerInviteDelete(client bot.Client, sequenceNumber int, shardID int, event gateway.EventInviteDelete) { client.EventManager().DispatchEvent(&events.InviteDelete{ - GenericInvite: &events.GenericInvite{ - GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), - GuildID: event.GuildID, - ChannelID: event.ChannelID, - Code: event.Code, - }, + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + GuildID: event.GuildID, + ChannelID: event.ChannelID, + Code: event.Code, }) } From f97241f9c4da06c4b6b03f482c8d2e32d9df28d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?To=CF=80?= Date: Mon, 12 Aug 2024 20:53:21 +0200 Subject: [PATCH 30/31] Fix/audit log changes (#378) * fix audit log changes struct * Make the Audit Log Change Key typed and add constants for its possible values (#377) * fix: make AuditLogChange.Key typed with constants instead of just a string. * chore: move type declaration to immediately before related definitions. --------- Co-authored-by: Vegard Berg --------- Co-authored-by: Vegard Berg <162863+myrkvi@users.noreply.github.com> Co-authored-by: Vegard Berg --- discord/audit_log.go | 177 +++++++++++++++++++++++++++++-------------- 1 file changed, 119 insertions(+), 58 deletions(-) diff --git a/discord/audit_log.go b/discord/audit_log.go index 59021f4a..f859b454 100644 --- a/discord/audit_log.go +++ b/discord/audit_log.go @@ -122,6 +122,105 @@ const ( AuditLogHomeSettingsUpdate ) +// AuditLogChangeKey is a string representing a key in the audit log change object. +type AuditLogChangeKey string + +const ( + AuditLogChangeKeyAFKChannelID AuditLogChangeKey = "afk_channel_id" + AuditLogChangeKeyAFKTimeout AuditLogChangeKey = "afk_timeout" + // AuditLogChangeKeyAllow is sent when a role's permission overwrites changed (stringy int) + AuditLogChangeKeyAllow AuditLogChangeKey = "allow" + AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id" + // AuditLogChangeKeyArchived is sent when a channel thread is archived/unarchived (bool) + AuditLogChangeKeyArchived AuditLogChangeKey = "archived" + AuditLogChangeKeyAsset AuditLogChangeKey = "asset" + // AuditLogChangeKeyAutoArchiveDuration is sent when a thread's auto archive duration is changed (int) + AuditLogChangeKeyAutoArchiveDuration AuditLogChangeKey = "auto_archive_duration" + AuditLogChangeKeyAvailable AuditLogChangeKey = "available" + AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash" + AuditLogChangeKeyBannerHash AuditLogChangeKey = "banner_hash" + AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate" + AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id" + AuditLogChangeKeyCode AuditLogChangeKey = "code" + // AuditLogChangeKeyColor is sent when a role's color is changed (int) + AuditLogChangeKeyColor AuditLogChangeKey = "color" + // AuditLogChangeKeyCommunicationDisabledUntil is sent when a user's communication disabled until datetime is changed (stringy ISO8601 datetime) + AuditLogChangeKeyCommunicationDisabledUntil AuditLogChangeKey = "communication_disabled_until" + // AuditLogChangeKeyDeaf is sent when a user is set to be server deafened/undeafened (bool) + AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf" + AuditLogChangeKeyDefaultAutoArchiveDuration AuditLogChangeKey = "default_auto_archive_duration" + AuditLogChangeKeyDefaultMessageNotifications AuditLogChangeKey = "default_message_notifications" + // AuditLogChangeKeyDeny is sent when a role's permission overwrites changed (stringed int) + AuditLogChangeKeyDeny AuditLogChangeKey = "deny" + AuditLogChangeKeyDescription AuditLogChangeKey = "description" + AuditLogChangeKeyDiscoverySplashHash AuditLogChangeKey = "discovery_splash_hash" + AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons" + AuditLogChangeKeyEntityType AuditLogChangeKey = "entity_type" + AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior" + AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period" + AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter" + AuditLogChangeKeyFormatType AuditLogChangeKey = "format_type" + AuditLogChangeKeyGuildID AuditLogChangeKey = "guild_id" + // AuditLogChangeKeyHoist is sent when a role is set to be displayed separately from online members (bool) + AuditLogChangeKeyHoist AuditLogChangeKey = "hoist" + AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash" + AuditLogChangeKeyID AuditLogChangeKey = "id" + AuditLogChangeKeyInvitable AuditLogChangeKey = "invitable" + AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id" + AuditLogChangeKeyLocation AuditLogChangeKey = "location" + // AuditLogChangeKeyLocked is sent when a channel thread is locked/unlocked (bool) + AuditLogChangeKeyLocked AuditLogChangeKey = "locked" + AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age" + AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses" + // AuditLogChangeKeyMentionable is sent when a role changes its mentionable state (bool) + AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable" + AuditLogChangeKeyMFALevel AuditLogChangeKey = "mfa_level" + // AuditLogChangeKeyMute is sent when a user is server muted/unmuted (bool) + AuditLogChangeKeyMute AuditLogChangeKey = "mute" + AuditLogChangeKeyName AuditLogChangeKey = "name" + // AuditLogChangeKeyNick is sent when a user's nickname is changed (string) + AuditLogChangeKeyNick AuditLogChangeKey = "nick" + AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw" + // AuditLogChangeKeyOwnerID is sent when owner id of a guild changed (snowflake.ID) + AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id" + // AuditLogChangeKeyPermissionOverwrites is sent when a role's permission overwrites changed (string) + AuditLogChangeKeyPermissionOverwrites AuditLogChangeKey = "permission_overwrites" + // AuditLogChangeKeyPermissions is sent when a role's permissions changed (string) + AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions" + // AuditLogChangeKeyPosition is sent when channel position changed (int) + AuditLogChangeKeyPosition AuditLogChangeKey = "position" + AuditLogChangeKeyPreferredLocale AuditLogChangeKey = "preferred_locale" + AuditLogChangeKeyPrivacyLevel AuditLogChangeKey = "privacy_level" + AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days" + AuditLogChangeKeyPublicUpdatesChannelID AuditLogChangeKey = "public_updates_channel_id" + AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user" + AuditLogChangeKeyRegion AuditLogChangeKey = "region" + AuditLogChangeKeyRulesChannelID AuditLogChangeKey = "rules_channel_id" + AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash" + AuditLogChangeKeyStatus AuditLogChangeKey = "status" + // AuditLogChangeKeySystemChannelID is sent when system channel id of a guild changed (snowflake.ID) + AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id" + AuditLogChangeKeyTags AuditLogChangeKey = "tags" + AuditLogChangeKeyTemporary AuditLogChangeKey = "temporary" + // AuditLogChangeKeyTopic is sent when channel topic changed (string) + AuditLogChangeKeyTopic AuditLogChangeKey = "topic" + AuditLogChangeKeyType AuditLogChangeKey = "type" + AuditLogChangeKeyUnicodeEmoji AuditLogChangeKey = "unicode_emoji" + // AuditLogChangeKeyUserLimit is sent when user limit of a voice channel changed (int) + AuditLogChangeKeyUserLimit AuditLogChangeKey = "user_limit" + AuditLogChangeKeyUses AuditLogChangeKey = "uses" + AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code" + // AuditLogChangeKeyVerificationLevel is sent when verification level of the server changed (int) + AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level" + AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id" + // AuditLogChangeKeyWidgetEnabled is sent when a server widget is enabled/disabled (bool) + AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled" + // AuditLogChangeKeyRoleAdd is sent when roles are added to a user (array of discord.PartialRole JSON) + AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add" + // AuditLogChangeKeyRoleRemove is sent when roles are removed from a user (array of discord.PartialRole JSON) + AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove" +) + // AuditLog (https://discord.com/developers/docs/resources/audit-log) These are logs of events that occurred, accessible via the Discord type AuditLog struct { ApplicationCommands []ApplicationCommand `json:"application_commands"` @@ -174,7 +273,7 @@ func (l *AuditLog) UnmarshalJSON(data []byte) error { // AuditLogEntry (https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object) type AuditLogEntry struct { TargetID *snowflake.ID `json:"target_id"` - Changes []AuditLogChangeKey `json:"changes"` + Changes []AuditLogChange `json:"changes"` UserID snowflake.ID `json:"user_id"` ID snowflake.ID `json:"id"` ActionType AuditLogEvent `json:"action_type"` @@ -182,63 +281,25 @@ type AuditLogEntry struct { Reason *string `json:"reason"` } -// AuditLogChangeKey (https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key) is data representing changes values/settings in an audit log. -type AuditLogChangeKey struct { - Name *string `json:"name"` - Description *string `json:"description"` - IconHash *string `json:"icon_hash"` - SplashHash *string `json:"splash_hash"` - DiscoverySplashHash *string `json:"discovery_splash_hash"` - BannerHash *string `json:"banner_hash"` - OwnerID *snowflake.ID `json:"owner_id"` - Region *string `json:"region"` - PreferredLocale *string `json:"preferred_locale"` - AFKChannelID *snowflake.ID `json:"afk_channel_id"` - AFKTimeout *int `json:"afk_timeout"` - RulesChannelID *snowflake.ID `json:"rules_channel_id"` - PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id"` - MFALevel *MFALevel `json:"mfa_level"` - VerificationLevel *VerificationLevel `json:"verification_level"` - ExplicitContentFilterLevel *ExplicitContentFilterLevel `json:"explicit_content_filter"` - DefaultMessageNotifications *MessageNotificationsLevel `json:"default_message_notifications"` - VanityURLCode *string `json:"vanity_url_code"` - Add []PartialRole `json:"$add"` - Remove []PartialRole `json:"$remove"` - PruneDeleteDays *int `json:"prune_delete_days"` - WidgetEnabled *bool `json:"widget_enabled"` - WidgetChannelID *string `json:"widget_channel_id"` - SystemChannelID *string `json:"system_channel_id"` - Position *int `json:"position"` - Topic *string `json:"topic"` - Bitrate *int `json:"bitrate"` - PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"` - NSFW *bool `json:"nsfw"` - ApplicationID *snowflake.ID `json:"application_id"` - RateLimitPerUser *int `json:"ratelimit_per_user"` - Permissions *string `json:"permissions"` - Color *int `json:"color"` - Hoist *bool `json:"hoist"` - Mentionable *bool `json:"mentionable"` - Allow *Permissions `json:"allow"` - Deny *Permissions `json:"deny"` - Code *string `json:"code"` - ChannelID *snowflake.ID `json:"channel_id"` - InviterID *snowflake.ID `json:"inviter_id"` - MaxUses *int `json:"max_uses"` - Uses *int `json:"uses"` - MaxAge *string `json:"max_age"` - Temporary *bool `json:"temporary"` - Deaf *bool `json:"deaf"` - Mute *bool `json:"mute"` - Nick *string `json:"nick"` - AvatarHash *string `json:"avatar_hash"` - ID *snowflake.ID `json:"id"` - Type any `json:"type"` - EnableEmoticons *bool `json:"enable_emoticons"` - ExpireBehavior *IntegrationExpireBehavior `json:"expire_behavior"` - ExpireGracePeriod *int `json:"expire_grace_period"` - UserLimit *int `json:"user_limit"` - PrivacyLevel *StagePrivacyLevel `json:"privacy_level"` +// AuditLogChange (https://discord.com/developers/docs/resources/audit-log#audit-log-change-object) contains what was changed. +// For a list of possible keys & values see the discord documentation. +type AuditLogChange struct { + // NewValue is the new value of the key after the change as a json.RawMessage. + NewValue json.RawMessage `json:"new_value"` + // OldValue is the old value of the key before the change as a json.RawMessage. + OldValue json.RawMessage `json:"old_value"` + // Key is the key of the change. + Key AuditLogChangeKey `json:"key"` +} + +// UnmarshalNewValue unmarshals the NewValue field into the provided type. +func (c *AuditLogChange) UnmarshalNewValue(v any) error { + return json.Unmarshal(c.NewValue, v) +} + +// UnmarshalOldValue unmarshals the OldValue field into the provided type. +func (c *AuditLogChange) UnmarshalOldValue(v any) error { + return json.Unmarshal(c.OldValue, v) } // OptionalAuditLogEntryInfo (https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info) From 4cd4fff14228523686160ca5bdc6ef8002096110 Mon Sep 17 00:00:00 2001 From: Vegard Berg <162863+myrkvi@users.noreply.github.com> Date: Tue, 13 Aug 2024 23:08:34 +0200 Subject: [PATCH 31/31] Change GuildPrivateThreadCreate to have NonInvitable field instead of Invitable (#379) * fix: Invitable=false does nothing since it is annotated as omitempty. * fix: Use pointer to bool for Invitable. --- discord/thread.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/thread.go b/discord/thread.go index 1beae101..5a6c19da 100644 --- a/discord/thread.go +++ b/discord/thread.go @@ -80,7 +80,7 @@ func (GuildPublicThreadCreate) Type() ChannelType { type GuildPrivateThreadCreate struct { Name string `json:"name"` AutoArchiveDuration AutoArchiveDuration `json:"auto_archive_duration,omitempty"` - Invitable bool `json:"invitable,omitempty"` + Invitable *bool `json:"invitable,omitempty"` } func (c GuildPrivateThreadCreate) MarshalJSON() ([]byte, error) {