diff --git a/bot/button/handlers/addadmin.go b/bot/button/handlers/addadmin.go index 13b31c2..6d815ec 100644 --- a/bot/button/handlers/addadmin.go +++ b/bot/button/handlers/addadmin.go @@ -214,9 +214,13 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) { Deny: 0, }) + pos := 0 + if ch.Position != nil { + pos = *ch.Position + } data := rest.ModifyChannelData{ PermissionOverwrites: overwrites, - Position: ch.Position, + Position: pos, } ticketAuditReason := fmt.Sprintf("Added admin to ticket %d", ticket.Id) diff --git a/bot/button/handlers/addsupport.go b/bot/button/handlers/addsupport.go index 39b3d84..6624d07 100644 --- a/bot/button/handlers/addsupport.go +++ b/bot/button/handlers/addsupport.go @@ -239,9 +239,13 @@ func updateChannelPermissions(ctx cmdregistry.CommandContext, id uint64, mention Deny: 0, }) + pos := 0 + if ch.Position != nil { + pos = *ch.Position + } data := rest.ModifyChannelData{ PermissionOverwrites: overwrites, - Position: ch.Position, + Position: pos, } ticketAuditReason := fmt.Sprintf("Added support to ticket %d", ticket.Id) diff --git a/bot/button/handlers/form.go b/bot/button/handlers/form.go index 1d895fa..631d37b 100644 --- a/bot/button/handlers/form.go +++ b/bot/button/handlers/form.go @@ -72,7 +72,7 @@ func (h *FormHandler) Execute(ctx *context.ModalContext) { answer := "" switch actionRow.Component.Type { - case component.ComponentSelectMenu: + case component.ComponentStringSelect: answer = strings.Join(actionRow.Component.Values, ", ") case component.ComponentInputText: answer = actionRow.Component.Value diff --git a/bot/button/handlers/panel.go b/bot/button/handlers/panel.go index bd53061..143a694 100644 --- a/bot/button/handlers/panel.go +++ b/bot/button/handlers/panel.go @@ -117,7 +117,7 @@ func buildForm(panel database.Panel, form database.Form, inputs []database.FormI switch input.Type { // String Select - case int(component.ComponentSelectMenu): + case int(component.ComponentStringSelect): opts := make([]component.SelectOption, len(options)) for j, option := range options { opts[j] = component.SelectOption{ diff --git a/bot/button/handlers/tickets/edit/editlabelsbutton.go b/bot/button/handlers/tickets/edit/editlabelsbutton.go index 1851a06..a85369d 100644 --- a/bot/button/handlers/tickets/edit/editlabelsbutton.go +++ b/bot/button/handlers/tickets/edit/editlabelsbutton.go @@ -65,7 +65,7 @@ func (h *EditLabelsButtonHandler) Execute(ctx *context.ButtonContext) { Label: labels[i].Name, Value: fmt.Sprintf("%d", labels[i].LabelId), Default: utils.Contains(ticketLabelIds, labels[i].LabelId), - Emoji: &emoji.Emoji{Name: colourEmoji}, + Emoji: &emoji.Emoji{Name: utils.Ptr(colourEmoji)}, }) } diff --git a/bot/button/handlers/unclaim.go b/bot/button/handlers/unclaim.go index 21099ec..5f6439e 100644 --- a/bot/button/handlers/unclaim.go +++ b/bot/button/handlers/unclaim.go @@ -126,7 +126,7 @@ func (h *UnclaimHandler) Execute(ctx *context.ButtonContext) { // Always update the name to match the new panel's naming scheme shouldUpdateName := true claimedChannelName, _ := logic.GenerateChannelName(ctx.Context, ctx.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, &whoClaimed) - if ch.Name != claimedChannelName { + if ch.Name == nil || *ch.Name != claimedChannelName { shouldUpdateName = false } diff --git a/bot/button/manager/handler.go b/bot/button/manager/handler.go index 010d51b..2cb9209 100644 --- a/bot/button/manager/handler.go +++ b/bot/button/manager/handler.go @@ -59,7 +59,7 @@ func HandleInteraction(ctx context.Context, manager *ComponentInteractionManager switch data.Data.Type() { case component.ComponentButton: cc = cmdcontext.NewButtonContext(ctx, worker, data, premiumTier, responseCh) - case component.ComponentSelectMenu: + case component.ComponentStringSelect: cc = cmdcontext.NewSelectMenuContext(ctx, worker, data, premiumTier, responseCh) default: sentry.ErrorWithContext(fmt.Errorf("invalid message component type: %d", data.Data.ComponentType), errorcontext.WorkerErrorContext{ @@ -137,7 +137,7 @@ func HandleInteraction(ctx context.Context, manager *ComponentInteractionManager } return canEdit - case component.ComponentSelectMenu: + case component.ComponentStringSelect: handler := manager.MatchSelect(data.Data.AsSelectMenu().CustomId) if handler == nil { return false diff --git a/bot/command/context/buttoncontext.go b/bot/command/context/buttoncontext.go index bd7c7c2..45a88a8 100644 --- a/bot/command/context/buttoncontext.go +++ b/bot/command/context/buttoncontext.go @@ -173,7 +173,7 @@ func (c *ButtonContext) User() (user.User, error) { func (c *ButtonContext) InteractionUser() user.User { if c.Interaction.Member != nil { - return c.Interaction.Member.User + return *c.Interaction.Member.User } else if c.Interaction.User != nil { return *c.Interaction.User } else { // Infallible diff --git a/bot/command/context/interactionextensions.go b/bot/command/context/interactionextensions.go index eea689a..322559f 100644 --- a/bot/command/context/interactionextensions.go +++ b/bot/command/context/interactionextensions.go @@ -21,35 +21,38 @@ func NewInteractionExtension(interaction interaction.ApplicationCommandInteracti } func (i InteractionExtension) Resolved() interaction.ResolvedData { - return i.interaction.Data.Resolved + if i.interaction.Data.Resolved == nil { + return interaction.ResolvedData{} + } + return *i.interaction.Data.Resolved } func (i InteractionExtension) ResolvedUser(id uint64) (user.User, bool) { - user, ok := i.interaction.Data.Resolved.Users[objects.Snowflake(id)] + user, ok := i.Resolved().Users[objects.Snowflake(id)] return user, ok } func (i InteractionExtension) ResolvedMember(id uint64) (member.Member, bool) { - member, ok := i.interaction.Data.Resolved.Members[objects.Snowflake(id)] + member, ok := i.Resolved().Members[objects.Snowflake(id)] return member, ok } func (i InteractionExtension) ResolvedRole(id uint64) (guild.Role, bool) { - role, ok := i.interaction.Data.Resolved.Roles[objects.Snowflake(id)] + role, ok := i.Resolved().Roles[objects.Snowflake(id)] return role, ok } func (i InteractionExtension) ResolvedChannel(id uint64) (channel.Channel, bool) { - channel, ok := i.interaction.Data.Resolved.Channels[objects.Snowflake(id)] + channel, ok := i.Resolved().Channels[objects.Snowflake(id)] return channel, ok } func (i InteractionExtension) ResolvedMessage(id uint64) (message.Message, bool) { - message, ok := i.interaction.Data.Resolved.Messages[objects.Snowflake(id)] + message, ok := i.Resolved().Messages[objects.Snowflake(id)] return message, ok } func (i InteractionExtension) ResolvedAttachment(id uint64) (channel.Attachment, bool) { - attachment, ok := i.interaction.Data.Resolved.Attachments[objects.Snowflake(id)] + attachment, ok := i.Resolved().Attachments[objects.Snowflake(id)] return attachment, ok } diff --git a/bot/command/context/mentionabletype.go b/bot/command/context/mentionabletype.go index 0b6557f..989cf71 100644 --- a/bot/command/context/mentionabletype.go +++ b/bot/command/context/mentionabletype.go @@ -16,9 +16,9 @@ const ( func (m MentionableType) OverwriteType() channel.PermissionOverwriteType { switch m { case MentionableTypeUser: - return channel.PermissionTypeMember + return channel.PermissionOverwriteTypeMember case MentionableTypeRole: - return channel.PermissionTypeRole + return channel.PermissionOverwriteTypeRole default: return -1 } diff --git a/bot/command/context/modalcontext.go b/bot/command/context/modalcontext.go index 2c8de6a..9ba3a65 100644 --- a/bot/command/context/modalcontext.go +++ b/bot/command/context/modalcontext.go @@ -197,7 +197,7 @@ func (c *ModalContext) User() (user.User, error) { func (c *ModalContext) InteractionUser() user.User { if c.Interaction.Member != nil { - return c.Interaction.Member.User + return *c.Interaction.Member.User } else if c.Interaction.User != nil { return *c.Interaction.User } else { // Infallible diff --git a/bot/command/context/selectmenucontext.go b/bot/command/context/selectmenucontext.go index 8336a02..f939d1b 100644 --- a/bot/command/context/selectmenucontext.go +++ b/bot/command/context/selectmenucontext.go @@ -173,7 +173,7 @@ func (c *SelectMenuContext) User() (user.User, error) { func (c *SelectMenuContext) InteractionUser() user.User { if c.Interaction.Member != nil { - return c.Interaction.Member.User + return *c.Interaction.Member.User } else if c.Interaction.User != nil { return *c.Interaction.User } else { // Infallible diff --git a/bot/command/impl/admin/adminblacklist.go b/bot/command/impl/admin/adminblacklist.go index 9ebe521..6d42fb2 100644 --- a/bot/command/impl/admin/adminblacklist.go +++ b/bot/command/impl/admin/adminblacklist.go @@ -31,9 +31,9 @@ func (AdminBlacklistCommand) Properties() registry.Properties { Category: command.Settings, AdminOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("guild_id", "ID of the guild to blacklist", interaction.OptionTypeString, i18n.MessageInvalidArgument), - command.NewOptionalArgument("reason", "Reason for blacklisting the guild", interaction.OptionTypeString, i18n.MessageInvalidArgument), - command.NewOptionalArgument("real_owner_id", "ID of the real owner (if different from Discord server owner)", interaction.OptionTypeString, i18n.MessageInvalidArgument), + command.NewRequiredArgument("guild_id", "ID of the guild to blacklist", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), + command.NewOptionalArgument("reason", "Reason for blacklisting the guild", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), + command.NewOptionalArgument("real_owner_id", "ID of the real owner (if different from Discord server owner)", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } diff --git a/bot/command/impl/admin/admingenpremium.go b/bot/command/impl/admin/admingenpremium.go index 9907721..48ddea1 100644 --- a/bot/command/impl/admin/admingenpremium.go +++ b/bot/command/impl/admin/admingenpremium.go @@ -30,9 +30,9 @@ func (c AdminGenPremiumCommand) Properties() registry.Properties { Category: command.Settings, AdminOnly: true, Arguments: command.Arguments( - command.NewRequiredAutocompleteableArgument("sku", "SKU for the key to grant", interaction.OptionTypeString, i18n.MessageInvalidArgument, c.AutoCompleteHandler), - command.NewRequiredArgument("length", "Length in days of the key", interaction.OptionTypeInteger, i18n.MessageInvalidArgument), - command.NewOptionalArgument("amount", "Amount of keys to generate", interaction.OptionTypeInteger, i18n.MessageInvalidArgument), + command.NewRequiredAutocompleteableArgument("sku", "SKU for the key to grant", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument, c.AutoCompleteHandler), + command.NewRequiredArgument("length", "Length in days of the key", interaction.ApplicationCommandOptionTypeInteger, i18n.MessageInvalidArgument), + command.NewOptionalArgument("amount", "Amount of keys to generate", interaction.ApplicationCommandOptionTypeInteger, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } diff --git a/bot/command/impl/admin/adminlistuserentitlements.go b/bot/command/impl/admin/adminlistuserentitlements.go index 7792059..ad44e87 100644 --- a/bot/command/impl/admin/adminlistuserentitlements.go +++ b/bot/command/impl/admin/adminlistuserentitlements.go @@ -27,7 +27,7 @@ func (AdminListUserEntitlementsCommand) Properties() registry.Properties { Category: command.Settings, HelperOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("user", "User to fetch entitlements for", interaction.OptionTypeUser, i18n.MessageInvalidArgument), + command.NewRequiredArgument("user", "User to fetch entitlements for", interaction.ApplicationCommandOptionTypeUser, i18n.MessageInvalidArgument), ), Timeout: time.Second * 15, } diff --git a/bot/command/impl/admin/adminrecache.go b/bot/command/impl/admin/adminrecache.go index 05809ee..a25619a 100644 --- a/bot/command/impl/admin/adminrecache.go +++ b/bot/command/impl/admin/adminrecache.go @@ -31,7 +31,7 @@ func (AdminRecacheCommand) Properties() registry.Properties { Category: command.Settings, HelperOnly: true, Arguments: command.Arguments( - command.NewOptionalArgument("guildid", "ID of the guild to recache", interaction.OptionTypeString, i18n.MessageInvalidArgument), + command.NewOptionalArgument("guildid", "ID of the guild to recache", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } diff --git a/bot/command/impl/admin/adminwhitelabelassignguild.go b/bot/command/impl/admin/adminwhitelabelassignguild.go index 3d7b266..e800ee8 100644 --- a/bot/command/impl/admin/adminwhitelabelassignguild.go +++ b/bot/command/impl/admin/adminwhitelabelassignguild.go @@ -28,8 +28,8 @@ func (AdminWhitelabelAssignGuildCommand) Properties() registry.Properties { Category: command.Settings, HelperOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("bot_id", "ID of the bot to assign to the guild", interaction.OptionTypeString, i18n.MessageInvalidArgument), - command.NewRequiredArgument("guild_id", "ID of the guild to assign the bot to", interaction.OptionTypeString, i18n.MessageInvalidArgument), + command.NewRequiredArgument("bot_id", "ID of the bot to assign to the guild", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), + command.NewRequiredArgument("guild_id", "ID of the guild to assign the bot to", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } diff --git a/bot/command/impl/admin/adminwhitelabeldata.go b/bot/command/impl/admin/adminwhitelabeldata.go index ea1f380..81eb331 100644 --- a/bot/command/impl/admin/adminwhitelabeldata.go +++ b/bot/command/impl/admin/adminwhitelabeldata.go @@ -31,7 +31,7 @@ func (AdminWhitelabelDataCommand) Properties() registry.Properties { Category: command.Settings, HelperOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("user_id", "ID of the user who has the whitelabel subscription", interaction.OptionTypeUser, i18n.MessageInvalidArgument), + command.NewRequiredArgument("user_id", "ID of the user who has the whitelabel subscription", interaction.ApplicationCommandOptionTypeUser, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } diff --git a/bot/command/impl/admin/debug/debugserver.go b/bot/command/impl/admin/debug/debugserver.go index 2152416..e93a354 100644 --- a/bot/command/impl/admin/debug/debugserver.go +++ b/bot/command/impl/admin/debug/debugserver.go @@ -39,7 +39,7 @@ func (AdminDebugServerCommand) Properties() registry.Properties { HelperOnly: true, DisableAutoDefer: true, Arguments: command.Arguments( - command.NewRequiredArgument("guild_id", "ID of the guild", interaction.OptionTypeString, i18n.MessageInvalidArgument), + command.NewRequiredArgument("guild_id", "ID of the guild", interaction.ApplicationCommandOptionTypeString, i18n.MessageInvalidArgument), ), Timeout: time.Second * 10, } @@ -203,7 +203,11 @@ func (AdminDebugServerCommand) Execute(ctx registry.CommandContext, raw string) if settings.UseThreads && settings.TicketNotificationChannel != nil { ch, err := worker.GetChannel(*settings.TicketNotificationChannel) if err == nil { - return ch.Name, strconv.FormatUint(ch.Id, 10) + name := "" + if ch.Name != nil { + name = *ch.Name + } + return name, strconv.FormatUint(ch.Id, 10) } } return "Disabled", "Disabled" @@ -254,8 +258,8 @@ func (AdminDebugServerCommand) Execute(ctx registry.CommandContext, raw string) fmt.Sprintf("Name: `%s`", guild.Name), fmt.Sprintf("Owner: `%s` - <@%s> (%s) ", owner.Username, ownerId, ownerId), } - if guild.VanityUrlCode != "" { - guildInfo = append(guildInfo, fmt.Sprintf("Vanity URL: `.gg/%s`", guild.VanityUrlCode)) + if guild.VanityUrlCode != nil && *guild.VanityUrlCode != "" { + guildInfo = append(guildInfo, fmt.Sprintf("Vanity URL: `.gg/%s`", *guild.VanityUrlCode)) } // Add blacklist information diff --git a/bot/command/impl/general/gdpr.go b/bot/command/impl/general/gdpr.go index d82a1d9..58ead8f 100644 --- a/bot/command/impl/general/gdpr.go +++ b/bot/command/impl/general/gdpr.go @@ -45,7 +45,7 @@ func (c GDPRCommand) Properties() registry.Properties { Contexts: []interaction.InteractionContextType{interaction.InteractionContextBotDM}, IgnoreBlacklist: true, Arguments: command.Arguments( - command.NewOptionalAutocompleteableArgument("lang", "Language for GDPR messages", interaction.OptionTypeString, i18n.GdprLanguageOption, c.LanguageAutoCompleteHandler), + command.NewOptionalAutocompleteableArgument("lang", "Language for GDPR messages", interaction.ApplicationCommandOptionTypeString, i18n.GdprLanguageOption, c.LanguageAutoCompleteHandler), ), } } diff --git a/bot/command/impl/settings/addadmin.go b/bot/command/impl/settings/addadmin.go index 5ac1d6e..cf5a1f1 100644 --- a/bot/command/impl/settings/addadmin.go +++ b/bot/command/impl/settings/addadmin.go @@ -27,7 +27,7 @@ func (AddAdminCommand) Properties() registry.Properties { Category: command.Settings, InteractionOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to apply the administrator permission to", interaction.OptionTypeMentionable, i18n.MessageAddAdminNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to apply the administrator permission to", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageAddAdminNoMembers), ), DefaultEphemeral: true, Timeout: time.Second * 3, diff --git a/bot/command/impl/settings/addsupport.go b/bot/command/impl/settings/addsupport.go index 62735c9..50dd311 100644 --- a/bot/command/impl/settings/addsupport.go +++ b/bot/command/impl/settings/addsupport.go @@ -28,7 +28,7 @@ func (AddSupportCommand) Properties() registry.Properties { Category: command.Settings, InteractionOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("role", "Role to apply the support representative permission to", interaction.OptionTypeMentionable, i18n.MessageAddSupportNoMembers), + command.NewRequiredArgument("role", "Role to apply the support representative permission to", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageAddSupportNoMembers), ), DefaultEphemeral: true, Timeout: time.Second * 3, diff --git a/bot/command/impl/settings/blacklist.go b/bot/command/impl/settings/blacklist.go index f15dc94..f12627f 100644 --- a/bot/command/impl/settings/blacklist.go +++ b/bot/command/impl/settings/blacklist.go @@ -29,7 +29,7 @@ func (BlacklistCommand) Properties() registry.Properties { PermissionLevel: permission.Support, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to blacklist or unblacklist", interaction.OptionTypeMentionable, i18n.MessageBlacklistNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to blacklist or unblacklist", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageBlacklistNoMembers), ), DefaultEphemeral: true, Timeout: time.Second * 5, diff --git a/bot/command/impl/settings/removeadmin.go b/bot/command/impl/settings/removeadmin.go index b6636e6..f79eff5 100644 --- a/bot/command/impl/settings/removeadmin.go +++ b/bot/command/impl/settings/removeadmin.go @@ -29,7 +29,7 @@ func (RemoveAdminCommand) Properties() registry.Properties { PermissionLevel: permcache.Admin, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to remove the administrator permission from", interaction.OptionTypeMentionable, i18n.MessageRemoveAdminNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to remove the administrator permission from", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageRemoveAdminNoMembers), ), DefaultEphemeral: true, Timeout: time.Second * 5, diff --git a/bot/command/impl/settings/removesupport.go b/bot/command/impl/settings/removesupport.go index 39b7345..e0c20f9 100644 --- a/bot/command/impl/settings/removesupport.go +++ b/bot/command/impl/settings/removesupport.go @@ -30,7 +30,7 @@ func (RemoveSupportCommand) Properties() registry.Properties { PermissionLevel: permcache.Admin, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to remove the support representative permission from", interaction.OptionTypeMentionable, i18n.MessageRemoveSupportNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to remove the support representative permission from", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageRemoveSupportNoMembers), ), DefaultEphemeral: true, Timeout: time.Second * 5, diff --git a/bot/command/impl/settings/setup/auto.go b/bot/command/impl/settings/setup/auto.go index b3a890c..ddb958a 100644 --- a/bot/command/impl/settings/setup/auto.go +++ b/bot/command/impl/settings/setup/auto.go @@ -173,7 +173,7 @@ func getTranscriptChannelData(guildId, supportRoleId, adminRoleId uint64) rest.C overwrites := []channel.PermissionOverwrite{ { // deny everyone else access to channel Id: guildId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: 0, Deny: allow, }, @@ -182,7 +182,7 @@ func getTranscriptChannelData(guildId, supportRoleId, adminRoleId uint64) rest.C if supportRoleId != 0 { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: supportRoleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: allow, Deny: 0, }) @@ -191,7 +191,7 @@ func getTranscriptChannelData(guildId, supportRoleId, adminRoleId uint64) rest.C if adminRoleId != 0 { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: adminRoleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: allow, Deny: 0, }) diff --git a/bot/command/impl/settings/setup/limit.go b/bot/command/impl/settings/setup/limit.go index 87cc61b..82b1d7d 100644 --- a/bot/command/impl/settings/setup/limit.go +++ b/bot/command/impl/settings/setup/limit.go @@ -22,7 +22,7 @@ func (LimitSetupCommand) Properties() registry.Properties { PermissionLevel: permission.Admin, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("limit", "The maximum amount of tickets a user can have open simultaneously", interaction.OptionTypeInteger, i18n.SetupLimitInvalid), + command.NewRequiredArgument("limit", "The maximum amount of tickets a user can have open simultaneously", interaction.ApplicationCommandOptionTypeInteger, i18n.SetupLimitInvalid), ), Timeout: time.Second * 3, } diff --git a/bot/command/impl/settings/setup/threads.go b/bot/command/impl/settings/setup/threads.go index eaaa29e..5baa943 100644 --- a/bot/command/impl/settings/setup/threads.go +++ b/bot/command/impl/settings/setup/threads.go @@ -23,8 +23,8 @@ func (ThreadsSetupCommand) Properties() registry.Properties { PermissionLevel: permission.Admin, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("use_threads", "Whether or not private threads should be used for ticket", interaction.OptionTypeBoolean, "infallible"), - command.NewOptionalArgument("ticket_notification_channel", "The channel that ticket open notifications should be sent to", interaction.OptionTypeChannel, "infallible"), + command.NewRequiredArgument("use_threads", "Whether or not private threads should be used for ticket", interaction.ApplicationCommandOptionTypeBoolean, "infallible"), + command.NewOptionalArgument("ticket_notification_channel", "The channel that ticket open notifications should be sent to", interaction.ApplicationCommandOptionTypeChannel, "infallible"), ), InteractionOnly: true, Timeout: time.Second * 5, diff --git a/bot/command/impl/settings/setup/transcripts.go b/bot/command/impl/settings/setup/transcripts.go index 576e1c3..e80016c 100644 --- a/bot/command/impl/settings/setup/transcripts.go +++ b/bot/command/impl/settings/setup/transcripts.go @@ -25,7 +25,7 @@ func (TranscriptsSetupCommand) Properties() registry.Properties { PermissionLevel: permission.Admin, Category: command.Settings, Arguments: command.Arguments( - command.NewRequiredArgument("channel", "The channel that ticket transcripts should be sent to", interaction.OptionTypeChannel, i18n.SetupTranscriptsInvalid), + command.NewRequiredArgument("channel", "The channel that ticket transcripts should be sent to", interaction.ApplicationCommandOptionTypeChannel, i18n.SetupTranscriptsInvalid), ), Timeout: time.Second * 5, } diff --git a/bot/command/impl/statistics/statsuser.go b/bot/command/impl/statistics/statsuser.go index c6689a4..49d6c1a 100644 --- a/bot/command/impl/statistics/statsuser.go +++ b/bot/command/impl/statistics/statsuser.go @@ -34,7 +34,7 @@ func (StatsUserCommand) Properties() registry.Properties { Category: command.Statistics, PremiumOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("user", "User whose statistics to retrieve", interaction.OptionTypeUser, i18n.MessageInvalidUser), + command.NewRequiredArgument("user", "User whose statistics to retrieve", interaction.ApplicationCommandOptionTypeUser, i18n.MessageInvalidUser), ), DefaultEphemeral: true, Timeout: time.Second * 30, diff --git a/bot/command/impl/tags/managetagsadd.go b/bot/command/impl/tags/managetagsadd.go index 340bcb9..6518558 100644 --- a/bot/command/impl/tags/managetagsadd.go +++ b/bot/command/impl/tags/managetagsadd.go @@ -29,8 +29,8 @@ func (ManageTagsAddCommand) Properties() registry.Properties { Category: command.Tags, InteractionOnly: true, Arguments: command.Arguments( - command.NewRequiredArgument("id", "Identifier for the tag", interaction.OptionTypeString, i18n.MessageTagCreateInvalidArguments), - command.NewRequiredArgument("content", "Tag contents to be sent when /tag is used", interaction.OptionTypeString, i18n.MessageTagCreateInvalidArguments), + command.NewRequiredArgument("id", "Identifier for the tag", interaction.ApplicationCommandOptionTypeString, i18n.MessageTagCreateInvalidArguments), + command.NewRequiredArgument("content", "Tag contents to be sent when /tag is used", interaction.ApplicationCommandOptionTypeString, i18n.MessageTagCreateInvalidArguments), ), DefaultEphemeral: true, Timeout: time.Second * 3, diff --git a/bot/command/impl/tags/managetagsdelete.go b/bot/command/impl/tags/managetagsdelete.go index 4dc4e39..ebc0352 100644 --- a/bot/command/impl/tags/managetagsdelete.go +++ b/bot/command/impl/tags/managetagsdelete.go @@ -24,7 +24,7 @@ func (ManageTagsDeleteCommand) Properties() registry.Properties { PermissionLevel: permission.Support, Category: command.Tags, Arguments: command.Arguments( - command.NewRequiredArgument("id", "ID of the tag to delete", interaction.OptionTypeString, i18n.MessageTagDeleteInvalidArguments), + command.NewRequiredArgument("id", "ID of the tag to delete", interaction.ApplicationCommandOptionTypeString, i18n.MessageTagDeleteInvalidArguments), ), DefaultEphemeral: true, Timeout: time.Second * 3, diff --git a/bot/command/impl/tags/tag.go b/bot/command/impl/tags/tag.go index 7e01eb9..09e435f 100644 --- a/bot/command/impl/tags/tag.go +++ b/bot/command/impl/tags/tag.go @@ -35,7 +35,7 @@ func (c TagCommand) Properties() registry.Properties { Category: command.Tags, DisableAutoDefer: true, Arguments: command.Arguments( - command.NewRequiredAutocompleteableArgument("id", "The ID of the tag to be sent to the channel", interaction.OptionTypeString, i18n.MessageTagInvalidArguments, c.AutoCompleteHandler), + command.NewRequiredAutocompleteableArgument("id", "The ID of the tag to be sent to the channel", interaction.ApplicationCommandOptionTypeString, i18n.MessageTagInvalidArguments, c.AutoCompleteHandler), ), Timeout: time.Second * 5, } @@ -86,9 +86,9 @@ func (TagCommand) Execute(ctx registry.CommandContext, tagId string) { Embeds: embeds, AllowedMentions: message.AllowedMention{ Parse: []message.AllowedMentionType{ - message.EVERYONE, - message.USERS, - message.ROLES, + message.AllowedMentionTypeRoles, + message.AllowedMentionTypeUsers, + message.AllowedMentionTypeEveryone, }, }, } diff --git a/bot/command/impl/tags/tagalias.go b/bot/command/impl/tags/tagalias.go index 3ad424d..1c14238 100644 --- a/bot/command/impl/tags/tagalias.go +++ b/bot/command/impl/tags/tagalias.go @@ -83,9 +83,9 @@ func (c TagAliasCommand) Execute(ctx registry.CommandContext) { Embeds: embeds, AllowedMentions: message.AllowedMention{ Parse: []message.AllowedMentionType{ - message.EVERYONE, - message.USERS, - message.ROLES, + message.AllowedMentionTypeRoles, + message.AllowedMentionTypeUsers, + message.AllowedMentionTypeEveryone, }, }, } diff --git a/bot/command/impl/tickets/add.go b/bot/command/impl/tickets/add.go index f7edfdc..69e845f 100644 --- a/bot/command/impl/tickets/add.go +++ b/bot/command/impl/tickets/add.go @@ -27,7 +27,7 @@ func (AddCommand) Properties() registry.Properties { PermissionLevel: permcache.Everyone, Category: command.Tickets, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to add to the ticket", interaction.OptionTypeMentionable, i18n.MessageAddNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to add to the ticket", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageAddNoMembers), ), Timeout: constants.TimeoutOpenTicket, } @@ -88,7 +88,7 @@ func (AddCommand) Execute(ctx registry.CommandContext, id uint64) { if ticket.IsThread { if err := ctx.Worker().AddThreadMember(*ticket.ChannelId, id); err != nil { if err, ok := err.(request.RestError); ok && (err.ApiError.Code == 50001 || err.ApiError.Code == 50013) { - ch, err := ctx.Channel() + ch, err := ctx.Worker().GetChannel(ctx.ChannelId()) if err != nil { ctx.HandleError(err) return diff --git a/bot/command/impl/tickets/close.go b/bot/command/impl/tickets/close.go index b7ff8ee..7fde49e 100644 --- a/bot/command/impl/tickets/close.go +++ b/bot/command/impl/tickets/close.go @@ -27,7 +27,7 @@ func (c CloseCommand) Properties() registry.Properties { PermissionLevel: permission.Everyone, Category: command.Tickets, Arguments: command.Arguments( - command.NewOptionalAutocompleteableArgument("reason", "The reason the ticket was closed", interaction.OptionTypeString, "infallible", c.AutoCompleteHandler), // should never fail + command.NewOptionalAutocompleteableArgument("reason", "The reason the ticket was closed", interaction.ApplicationCommandOptionTypeString, "infallible", c.AutoCompleteHandler), // should never fail ), Timeout: constants.TimeoutCloseTicket, } diff --git a/bot/command/impl/tickets/closerequest.go b/bot/command/impl/tickets/closerequest.go index 1c44679..382bf1f 100644 --- a/bot/command/impl/tickets/closerequest.go +++ b/bot/command/impl/tickets/closerequest.go @@ -35,8 +35,8 @@ func (c CloseRequestCommand) Properties() registry.Properties { InteractionOnly: true, DisableAutoDefer: true, Arguments: command.Arguments( - command.NewOptionalArgument("close_delay", "Hours to close the ticket in if the user does not respond", interaction.OptionTypeInteger, "infallible"), - command.NewOptionalAutocompleteableArgument("reason", "The reason the ticket was closed", interaction.OptionTypeString, "infallible", c.ReasonAutoCompleteHandler), + command.NewOptionalArgument("close_delay", "Hours to close the ticket in if the user does not respond", interaction.ApplicationCommandOptionTypeInteger, "infallible"), + command.NewOptionalAutocompleteableArgument("reason", "The reason the ticket was closed", interaction.ApplicationCommandOptionTypeString, "infallible", c.ReasonAutoCompleteHandler), ), Timeout: time.Second * 5, } diff --git a/bot/command/impl/tickets/edit.go b/bot/command/impl/tickets/edit.go index ffdeb1c..63c07b9 100644 --- a/bot/command/impl/tickets/edit.go +++ b/bot/command/impl/tickets/edit.go @@ -49,7 +49,7 @@ func (EditCommand) Execute(ctx registry.CommandContext) { } ctx.ReplyWith(command.MessageResponse{ - Flags: message.SumFlags(message.FlagComponentsV2), + Flags: message.SumFlags(message.FlagIsComponentsV2), Components: []component.Component{ component.BuildContainer(component.Container{ Components: []component.Component{ @@ -69,7 +69,7 @@ func (EditCommand) Execute(ctx registry.CommandContext) { }, Accessory: component.BuildButton(component.Button{ Emoji: &emoji.Emoji{ - Name: "⚙️", + Name: utils.Ptr("⚙️"), }, CustomId: "update-ticket-labels-button", Style: component.ButtonStyleSecondary, diff --git a/bot/command/impl/tickets/open.go b/bot/command/impl/tickets/open.go index 8ba0975..b34a6b0 100644 --- a/bot/command/impl/tickets/open.go +++ b/bot/command/impl/tickets/open.go @@ -24,7 +24,7 @@ func (OpenCommand) Properties() registry.Properties { PermissionLevel: permission.Everyone, Category: command.Tickets, Arguments: command.Arguments( - command.NewOptionalArgument("subject", "The subject of the ticket", interaction.OptionTypeString, "infallible"), + command.NewOptionalArgument("subject", "The subject of the ticket", interaction.ApplicationCommandOptionTypeString, "infallible"), ), DefaultEphemeral: true, Timeout: constants.TimeoutOpenTicket, diff --git a/bot/command/impl/tickets/remove.go b/bot/command/impl/tickets/remove.go index c21fe39..d002ade 100644 --- a/bot/command/impl/tickets/remove.go +++ b/bot/command/impl/tickets/remove.go @@ -30,7 +30,7 @@ func (RemoveCommand) Properties() registry.Properties { PermissionLevel: permcache.Everyone, Category: command.Tickets, Arguments: command.Arguments( - command.NewRequiredArgument("user_or_role", "User or role to remove from the current ticket", interaction.OptionTypeMentionable, i18n.MessageRemoveAdminNoMembers), + command.NewRequiredArgument("user_or_role", "User or role to remove from the current ticket", interaction.ApplicationCommandOptionTypeMentionable, i18n.MessageRemoveAdminNoMembers), ), Timeout: time.Second * 8, } @@ -236,7 +236,7 @@ func (RemoveCommand) Execute(ctx registry.CommandContext, id uint64) { } else { data := channel.PermissionOverwrite{ Id: id, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: 0, Deny: permission.BuildPermissions(logic.StandardPermissions[:]...), } @@ -320,7 +320,7 @@ func (RemoveCommand) Execute(ctx registry.CommandContext, id uint64) { // Handle role removal data := channel.PermissionOverwrite{ Id: id, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: 0, Deny: permission.BuildPermissions(logic.StandardPermissions[:]...), } diff --git a/bot/command/impl/tickets/rename.go b/bot/command/impl/tickets/rename.go index 01cfe95..ed64271 100644 --- a/bot/command/impl/tickets/rename.go +++ b/bot/command/impl/tickets/rename.go @@ -33,7 +33,7 @@ func (RenameCommand) Properties() registry.Properties { PermissionLevel: permission.Support, Category: command.Tickets, Arguments: command.Arguments( - command.NewRequiredArgument("name", "New name for the ticket", interaction.OptionTypeString, i18n.MessageRenameMissingName), + command.NewRequiredArgument("name", "New name for the ticket", interaction.ApplicationCommandOptionTypeString, i18n.MessageRenameMissingName), ), DefaultEphemeral: true, Timeout: time.Second * 5, @@ -117,10 +117,10 @@ func (RenameCommand) Execute(ctx registry.CommandContext, name string) { // %nickname% logic.NewSubstitutor("nickname", false, true, func(user user.User, member member.Member) string { nickname := member.Nick - if len(nickname) == 0 { - nickname = member.User.Username + if len(*nickname) == 0 { + nickname = &member.User.Username } - return nickname + return *nickname }), }, []logic.ParameterizedSubstitutor{ // %date% or %date:FORMAT% diff --git a/bot/command/impl/tickets/reopen.go b/bot/command/impl/tickets/reopen.go index f7bdcf7..c7fdced 100644 --- a/bot/command/impl/tickets/reopen.go +++ b/bot/command/impl/tickets/reopen.go @@ -26,7 +26,7 @@ func (c ReopenCommand) Properties() registry.Properties { PermissionLevel: permission.Everyone, Category: command.Tickets, Arguments: command.Arguments( - command.NewRequiredAutocompleteableArgument("ticket_id", "ID of the ticket to reopen", interaction.OptionTypeInteger, i18n.MessageInvalidArgument, c.AutoCompleteHandler), + command.NewRequiredAutocompleteableArgument("ticket_id", "ID of the ticket to reopen", interaction.ApplicationCommandOptionTypeInteger, i18n.MessageInvalidArgument, c.AutoCompleteHandler), ), DefaultEphemeral: true, Timeout: time.Second * 10, diff --git a/bot/command/impl/tickets/startticket.go b/bot/command/impl/tickets/startticket.go index b7a7c57..556c403 100644 --- a/bot/command/impl/tickets/startticket.go +++ b/bot/command/impl/tickets/startticket.go @@ -63,10 +63,14 @@ func (StartTicketCommand) Execute(ctx registry.CommandContext) { return } - messageId := interaction.Interaction.Data.TargetId + if interaction.Interaction.Data.TargetId == nil { + ctx.HandleError(errors.New("TargetId missing from interaction data")) + return + } + messageId := *interaction.Interaction.Data.TargetId msg, ok := interaction.ResolvedMessage(messageId) - if err != nil { + if !ok { ctx.HandleError(errors.New("Message missing from resolved data")) return } @@ -193,11 +197,14 @@ func addMessageSender(ctx registry.CommandContext, ticket database.Ticket, msg m } func sendMovedMessage(ctx registry.CommandContext, ticket database.Ticket, msg message.Message) { + channelId := ctx.ChannelId() + guildId := ctx.GuildId() + failIfNotExists := false reference := &message.MessageReference{ - MessageId: msg.Id, - ChannelId: ctx.ChannelId(), - GuildId: ctx.GuildId(), - FailIfNotExists: false, + MessageId: &msg.Id, + ChannelId: &channelId, + GuildId: &guildId, + FailIfNotExists: &failIfNotExists, } msgEmbed := utils.BuildEmbed(ctx, customisation.Green, i18n.Ticket, i18n.MessageMovedToTicket, nil, *ticket.ChannelId) diff --git a/bot/command/impl/tickets/switchpanel.go b/bot/command/impl/tickets/switchpanel.go index d001893..28fa3ea 100644 --- a/bot/command/impl/tickets/switchpanel.go +++ b/bot/command/impl/tickets/switchpanel.go @@ -38,7 +38,7 @@ func (c SwitchPanelCommand) Properties() registry.Properties { Category: command.Tickets, InteractionOnly: true, Arguments: command.Arguments( - command.NewRequiredAutocompleteableArgument("panel", "Ticket panel to switch the ticket to", interaction.OptionTypeInteger, i18n.MessageInvalidUser, c.AutoCompleteHandler), // TODO: Fix invalid message + command.NewRequiredAutocompleteableArgument("panel", "Ticket panel to switch the ticket to", interaction.ApplicationCommandOptionTypeInteger, i18n.MessageInvalidUser, c.AutoCompleteHandler), // TODO: Fix invalid message ), Timeout: constants.TimeoutOpenTicket, } @@ -129,7 +129,7 @@ func (SwitchPanelCommand) Execute(ctx *cmdcontext.SlashCommandContext, panelId i if oldPanel != nil { // But skip if the user has manually renamed the channel (doesn't match old panel's generated name) oldChannelName, _ := logic.GenerateChannelName(ctx.Context, ctx.Worker(), oldPanel, ticket.GuildId, ticket.Id, ticket.UserId, utils.NilIfZero(claimer)) - if currentChannel.Name != oldChannelName { + if currentChannel.Name == nil || *currentChannel.Name != oldChannelName { shouldUpdateName = false } } diff --git a/bot/command/impl/tickets/transfer.go b/bot/command/impl/tickets/transfer.go index 945e4be..80e3b8d 100644 --- a/bot/command/impl/tickets/transfer.go +++ b/bot/command/impl/tickets/transfer.go @@ -26,7 +26,7 @@ func (TransferCommand) Properties() registry.Properties { PermissionLevel: permission.Support, Category: command.Tickets, Arguments: command.Arguments( - command.NewRequiredArgument("user", "Support representative to transfer the ticket to", interaction.OptionTypeUser, i18n.MessageInvalidUser), + command.NewRequiredArgument("user", "Support representative to transfer the ticket to", interaction.ApplicationCommandOptionTypeUser, i18n.MessageInvalidUser), ), Timeout: constants.TimeoutOpenTicket, } diff --git a/bot/command/impl/tickets/unclaim.go b/bot/command/impl/tickets/unclaim.go index d29af20..a5ecb42 100644 --- a/bot/command/impl/tickets/unclaim.go +++ b/bot/command/impl/tickets/unclaim.go @@ -122,7 +122,7 @@ func (UnclaimCommand) Execute(ctx *context.SlashCommandContext) { // Always update the name to match the new panel's naming scheme shouldUpdateName := true claimedChannelName, _ := logic.GenerateChannelName(ctx.Context, ctx.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, &whoClaimed) - if ch.Name != claimedChannelName { + if ch.Name == nil || *ch.Name != claimedChannelName { shouldUpdateName = false } diff --git a/bot/command/manager/manager.go b/bot/command/manager/manager.go index f5f4e02..1fb7995 100644 --- a/bot/command/manager/manager.go +++ b/bot/command/manager/manager.go @@ -148,7 +148,6 @@ func buildOption(cmd registry.Command) interaction.ApplicationCommandOption { Type: argument.Type, Name: argument.Name, Description: argument.Description, - Default: false, Required: argument.Required, Choices: nil, Autocomplete: argument.AutoCompleteHandler != nil, @@ -165,16 +164,15 @@ func buildOption(cmd registry.Command) interaction.ApplicationCommandOption { options := append(required, optional...) // Determine the correct type based on whether this command has children - optionType := interaction.OptionTypeSubCommand + optionType := interaction.ApplicationCommandOptionTypeSubCommand if len(properties.Children) > 0 { - optionType = interaction.OptionTypeSubCommandGroup + optionType = interaction.ApplicationCommandOptionTypeSubCommandGroup } return interaction.ApplicationCommandOption{ Type: optionType, Name: properties.Name, Description: i18n.GetMessage(i18n.LocaleEnglish, properties.Description), - Default: false, Required: false, Choices: nil, Options: options, diff --git a/bot/command/messageresponse.go b/bot/command/messageresponse.go index ed8c3fe..a90dd2b 100644 --- a/bot/command/messageresponse.go +++ b/bot/command/messageresponse.go @@ -46,14 +46,14 @@ func NewEmbedMessageResponseWithComponents(e *embed.Embed, components []componen func NewMessageResponseWithComponents(components []component.Component) MessageResponse { return MessageResponse{ Components: components, - Flags: message.SumFlags(message.FlagComponentsV2), + Flags: message.SumFlags(message.FlagIsComponentsV2), } } func NewEphemeralMessageResponseWithComponents(components []component.Component) MessageResponse { return MessageResponse{ Components: components, - Flags: message.SumFlags(message.FlagEphemeral, message.FlagComponentsV2), + Flags: message.SumFlags(message.FlagEphemeral, message.FlagIsComponentsV2), } } diff --git a/bot/customisation/emoji.go b/bot/customisation/emoji.go index 1ab2833..7beb7f7 100644 --- a/bot/customisation/emoji.go +++ b/bot/customisation/emoji.go @@ -32,7 +32,7 @@ func (e CustomEmoji) String() string { func (e CustomEmoji) BuildEmoji() *emoji.Emoji { return &emoji.Emoji{ Id: objects.NewNullableSnowflake(e.Id), - Name: e.Name, + Name: &e.Name, Animated: e.Animated, } } diff --git a/bot/listeners/guildcreate.go b/bot/listeners/guildcreate.go index f07eec8..36248d6 100644 --- a/bot/listeners/guildcreate.go +++ b/bot/listeners/guildcreate.go @@ -3,6 +3,7 @@ package listeners import ( "context" "fmt" + "strconv" "time" "github.com/TicketsBot-cloud/common/sentry" @@ -92,7 +93,7 @@ func sendIntroMessage(ctx context.Context, worker *worker.Context, guild guild.G func getInviter(worker *worker.Context, guildId uint64) (userId uint64) { data := rest.GetGuildAuditLogData{ - ActionType: auditlog.EventBotAdd, + ActionType: auditlog.AuditLogEventBotAdd, Limit: 50, } @@ -102,12 +103,15 @@ func getInviter(worker *worker.Context, guildId uint64) (userId uint64) { return } + botIdStr := strconv.FormatUint(worker.BotId, 10) for _, entry := range auditLog.Entries { - if entry.ActionType != auditlog.EventBotAdd || entry.TargetId != worker.BotId { + if entry.ActionType != auditlog.AuditLogEventBotAdd || entry.TargetId == nil || *entry.TargetId != botIdStr { continue } - userId = entry.UserId + if entry.UserId != nil { + userId = *entry.UserId + } break } diff --git a/bot/listeners/message.go b/bot/listeners/message.go index 11f8eb1..7e709fd 100644 --- a/bot/listeners/message.go +++ b/bot/listeners/message.go @@ -28,14 +28,19 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) { span := sentry.StartTransaction(ctx, "OnMessage") defer span.Finish() - if e.GuildId != 0 { - span.SetTag("guild_id", strconv.FormatUint(e.GuildId, 10)) + var guildId uint64 + if e.GuildId != nil { + guildId = *e.GuildId + } + + if guildId != 0 { + span.SetTag("guild_id", strconv.FormatUint(guildId, 10)) } statsd.Client.IncrementKey(statsd.KeyMessages) // ignore DMs - if e.GuildId == 0 { + if guildId == 0 { return } @@ -56,7 +61,7 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) { if e.Author.Id != worker.BotId && !e.Author.Bot { // set participants, for logging sentry.WithSpan0(span.Context(), "Add participant", func(span *sentry.Span) { - if err := dbclient.Client.Participants.Set(ctx, e.GuildId, ticket.Id, e.Author.Id); err != nil { + if err := dbclient.Client.Participants.Set(ctx, guildId, ticket.Id, e.Author.Id); err != nil { sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e)) } }) @@ -81,7 +86,7 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) { if *isStaffCached { // check the user is staff // We don't have to check for previous responses due to ON CONFLICT DO NOTHING sentry.WithSpan0(span.Context(), "Set first response time", func(span *sentry.Span) { - if err := dbclient.Client.FirstResponseTime.Set(ctx, e.GuildId, e.Author.Id, ticket.Id, time.Now().Sub(ticket.OpenTime)); err != nil { + if err := dbclient.Client.FirstResponseTime.Set(ctx, guildId, e.Author.Id, ticket.Id, time.Now().Sub(ticket.OpenTime)); err != nil { sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e)) } }) @@ -90,7 +95,7 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) { } premiumTier, err := sentry.WithSpan2(span.Context(), "Get premium tier", func(span *sentry.Span) (premium.PremiumTier, error) { - return utils.PremiumClient.GetTierByGuildId(ctx, e.GuildId, true, worker.Token, worker.RateLimiter) + return utils.PremiumClient.GetTierByGuildId(ctx, guildId, true, worker.Token, worker.RateLimiter) }) if err != nil { sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e)) @@ -135,13 +140,13 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) { } if ticket.Status != newStatus { - if err := dbclient.Client.Tickets.SetStatus(ctx, e.GuildId, ticket.Id, newStatus); err != nil { + if err := dbclient.Client.Tickets.SetStatus(ctx, guildId, ticket.Id, newStatus); err != nil { sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e)) } if !ticket.IsThread { if err := sentry.WithSpan1(span.Context(), "Update status update queue", func(span *sentry.Span) error { - return dbclient.Client.CategoryUpdateQueue.Add(ctx, e.GuildId, ticket.Id, newStatus) + return dbclient.Client.CategoryUpdateQueue.Add(ctx, guildId, ticket.Id, newStatus) }); err != nil { sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e)) } diff --git a/bot/listeners/threadupdate.go b/bot/listeners/threadupdate.go index ae7894c..2f549b6 100644 --- a/bot/listeners/threadupdate.go +++ b/bot/listeners/threadupdate.go @@ -24,19 +24,24 @@ func OnThreadUpdate(worker *worker.Context, e events.ThreadUpdate) { return } - settings, err := dbclient.Client.Settings.Get(ctx, e.GuildId) + if e.GuildId == nil { + return + } + guildId := *e.GuildId + + settings, err := dbclient.Client.Settings.Get(ctx, guildId) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } - ticket, err := dbclient.Client.Tickets.GetByChannelAndGuild(ctx, e.Id, e.GuildId) + ticket, err := dbclient.Client.Tickets.GetByChannelAndGuild(ctx, e.Id, guildId) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } - if ticket.Id == 0 || ticket.GuildId != e.GuildId { + if ticket.Id == 0 || ticket.GuildId != guildId { return } @@ -50,32 +55,32 @@ func OnThreadUpdate(worker *worker.Context, e events.ThreadUpdate) { if ticket.PanelId != nil { tmp, err := dbclient.Client.Panel.GetById(ctx, *ticket.PanelId) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } - if tmp.PanelId != 0 && e.GuildId == tmp.GuildId { + if tmp.PanelId != 0 && guildId == tmp.GuildId { panel = &tmp } } - premiumTier, err := utils.PremiumClient.GetTierByGuildId(ctx, e.GuildId, true, worker.Token, worker.RateLimiter) + premiumTier, err := utils.PremiumClient.GetTierByGuildId(ctx, guildId, true, worker.Token, worker.RateLimiter) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } // Handle thread being unarchived if !ticket.Open && !e.ThreadMetadata.Archived { if err := dbclient.Client.Tickets.SetOpen(ctx, ticket.GuildId, ticket.Id); err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } if settings.TicketNotificationChannel != nil { staffCount, err := logic.GetStaffInThread(ctx, worker, ticket, e.Id) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } @@ -83,12 +88,12 @@ func OnThreadUpdate(worker *worker.Context, e events.ThreadUpdate) { data := logic.BuildThreadReopenMessage(ctx, worker, ticket.GuildId, ticket.UserId, name, ticket.Id, panel, staffCount, premiumTier) msg, err := worker.CreateMessageComplex(*settings.TicketNotificationChannel, data.IntoCreateMessageData()) if err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } if err := dbclient.Client.Tickets.SetJoinMessageId(ctx, ticket.GuildId, ticket.Id, &msg.Id); err != nil { - sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId}) + sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: guildId}) return } } diff --git a/bot/logic/claim.go b/bot/logic/claim.go index a580ad1..98daaf9 100644 --- a/bot/logic/claim.go +++ b/bot/logic/claim.go @@ -17,6 +17,7 @@ import ( "github.com/TicketsBot-cloud/worker/bot/command/registry" "github.com/TicketsBot-cloud/worker/bot/customisation" "github.com/TicketsBot-cloud/worker/bot/dbclient" + "github.com/TicketsBot-cloud/worker/bot/utils" "github.com/TicketsBot-cloud/worker/i18n" "golang.org/x/sync/errgroup" ) @@ -72,7 +73,7 @@ func ClaimTicket(ctx context.Context, cmd registry.CommandContext, ticket databa shouldUpdateName := true // But skip if the user has manually renamed the channel (doesn't match old unclaimed name) oldChannelName, _ := GenerateChannelName(ctx, cmd.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, nil) - if currentChannel.Name != oldChannelName { + if currentChannel.Name == nil || *currentChannel.Name != oldChannelName { shouldUpdateName = false } @@ -193,7 +194,7 @@ func overwritesCantView(claimer, selfId, openerId, guildId uint64, adminUsers, a overwrites = append(overwrites, BuildUserOverwrite(openerId, additionalPermissions), channel.PermissionOverwrite{ // @everyone Id: guildId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: 0, Deny: permission.BuildPermissions(permission.ViewChannel), }, @@ -218,7 +219,7 @@ func overwritesCantView(claimer, selfId, openerId, guildId uint64, adminUsers, a for _, userId := range adminUserTargets { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: userId, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(StandardPermissions[:]...), Deny: 0, }) @@ -227,7 +228,7 @@ func overwritesCantView(claimer, selfId, openerId, guildId uint64, adminUsers, a for _, roleId := range adminRoleTargets { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: roleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(StandardPermissions[:]...), Deny: 0, }) @@ -244,7 +245,7 @@ func overwritesCantType(claimerId, selfId, openerId, guildId uint64, supportUser overwrites = append(overwrites, BuildUserOverwrite(openerId, additionalPermissions), channel.PermissionOverwrite{ // @everyone Id: guildId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: 0, Deny: permission.BuildPermissions(permission.ViewChannel), }, @@ -268,7 +269,7 @@ func overwritesCantType(claimerId, selfId, openerId, guildId uint64, supportUser for _, userId := range adminUserTargets { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: userId, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(StandardPermissions[:]...), Deny: 0, }) @@ -277,7 +278,7 @@ func overwritesCantType(claimerId, selfId, openerId, guildId uint64, supportUser for _, roleId := range adminRoleTargets { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: roleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(StandardPermissions[:]...), Deny: 0, }) @@ -297,7 +298,7 @@ func overwritesCantType(claimerId, selfId, openerId, guildId uint64, supportUser overwrites = append(overwrites, channel.PermissionOverwrite{ Id: userId, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(readOnlyAllowed...), Deny: permission.BuildPermissions(readOnlyDenied...), }) @@ -317,7 +318,7 @@ func overwritesCantType(claimerId, selfId, openerId, guildId uint64, supportUser overwrites = append(overwrites, channel.PermissionOverwrite{ Id: roleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(readOnlyAllowed...), Deny: permission.BuildPermissions(readOnlyDenied...), }) @@ -360,7 +361,7 @@ func UpdateWelcomeMessageClaimButton(ctx context.Context, worker *worker.Context Label: cmd.GetMessage(i18n.TitleUnclaim), CustomId: "unclaim", Style: component.ButtonStyleSecondary, - Emoji: &emoji.Emoji{Name: "🙋‍♂️"}, + Emoji: &emoji.Emoji{Name: utils.Ptr("🙋‍♂️")}, }) updated = true break @@ -370,7 +371,7 @@ func UpdateWelcomeMessageClaimButton(ctx context.Context, worker *worker.Context Label: cmd.GetMessage(i18n.TitleClaim), CustomId: "claim", Style: component.ButtonStyleSuccess, - Emoji: &emoji.Emoji{Name: "🙋‍♂️"}, + Emoji: &emoji.Emoji{Name: utils.Ptr("🙋‍♂️")}, }) updated = true break diff --git a/bot/logic/close.go b/bot/logic/close.go index bc60c9b..81b4880 100644 --- a/bot/logic/close.go +++ b/bot/logic/close.go @@ -393,7 +393,7 @@ func sendCloseEmbed(ctx context.Context, cmd registry.CommandContext, errorConte } closeEmbed, closeComponents := BuildCloseEmbed(ctx, cmd.Worker(), ticket, member.User.Id, reason, nil, componentBuilders) - closeEmbed.SetAuthor(guild.Name, "", fmt.Sprintf("https://cdn.discordapp.com/icons/%d/%s.png", guild.Id, guild.Icon)) + closeEmbed.SetAuthor(guild.Name, "", guild.IconUrl()) // Use message content to tell users why they can't rate a ticket var content string diff --git a/bot/logic/closeembed.go b/bot/logic/closeembed.go index 6dd854f..44fd8a8 100644 --- a/bot/logic/closeembed.go +++ b/bot/logic/closeembed.go @@ -111,7 +111,7 @@ func FeedbackRowElement(condition bool) CloseEmbedElement { CustomId: fmt.Sprintf("rate_%d_%d_%d", ticket.GuildId, ticket.Id, i), Style: style, Emoji: &emoji.Emoji{ - Name: "⭐", + Name: utils.Ptr("⭐"), }, }) } diff --git a/bot/logic/discordpermissions.go b/bot/logic/discordpermissions.go index b551008..6ca550c 100644 --- a/bot/logic/discordpermissions.go +++ b/bot/logic/discordpermissions.go @@ -56,7 +56,7 @@ func BuildUserOverwrite(userId uint64, additionalPermissions database.TicketPerm return channel.PermissionOverwrite{ Id: userId, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(allow...), Deny: permission.BuildPermissions(deny...), } @@ -86,7 +86,7 @@ func BuildRoleOverwrite(roleId uint64, additionalPermissions database.TicketPerm return channel.PermissionOverwrite{ Id: roleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(allow...), Deny: permission.BuildPermissions(deny...), } diff --git a/bot/logic/open.go b/bot/logic/open.go index 7395962..3abf521 100644 --- a/bot/logic/open.go +++ b/bot/logic/open.go @@ -357,12 +357,12 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat data := rest.CreateChannelData{ Name: name, Type: channel.ChannelTypeGuildText, - Topic: subject, + Topic: &subject, PermissionOverwrites: overwrites, } if useCategory { - data.ParentId = category + data.ParentId = &category } span = sentry.StartSpan(rootSpan.Context(), "Create channel") @@ -566,9 +566,9 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat Content: content, AllowedMentions: message.AllowedMention{ Parse: []message.AllowedMentionType{ - message.EVERYONE, - message.USERS, - message.ROLES, + message.AllowedMentionTypeEveryone, + message.AllowedMentionTypeUsers, + message.AllowedMentionTypeRoles, }, }, }) @@ -649,7 +649,7 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat // Find and delete the system pin notification message for _, msg := range messages { // Pin notification has MessageReference pointing to the pinned message, but is not the pinned message itself - if msg.MessageReference.MessageId == welcomeMessageId && msg.Id != welcomeMessageId { + if msg.MessageReference != nil && msg.MessageReference.MessageId != nil && *msg.MessageReference.MessageId == welcomeMessageId && msg.Id != welcomeMessageId { _ = cmd.Worker().DeleteMessage(channelId, msg.Id) break } @@ -929,7 +929,7 @@ func CreateOverwrites(ctx context.Context, cmd registry.InteractionContext, user overwrites := []channel.PermissionOverwrite{ // @everyone { Id: cmd.GuildId(), - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: 0, Deny: permission.BuildPermissions(permission.ViewChannel), }, @@ -974,14 +974,14 @@ func CreateOverwrites(ctx context.Context, cmd registry.InteractionContext, user if integrationRoleId == nil { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: cmd.Worker().BotId, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(selfAllow[:]...), Deny: 0, }) } else { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: *integrationRoleId, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(selfAllow[:]...), Deny: 0, }) @@ -1003,7 +1003,7 @@ func CreateOverwrites(ctx context.Context, cmd registry.InteractionContext, user overwrites = append(overwrites, channel.PermissionOverwrite{ Id: member, - Type: channel.PermissionTypeMember, + Type: channel.PermissionOverwriteTypeMember, Allow: permission.BuildPermissions(allow...), Deny: 0, }) @@ -1012,7 +1012,7 @@ func CreateOverwrites(ctx context.Context, cmd registry.InteractionContext, user for _, role := range allowedRoles { overwrites = append(overwrites, channel.PermissionOverwrite{ Id: role, - Type: channel.PermissionTypeRole, + Type: channel.PermissionOverwriteTypeRole, Allow: permission.BuildPermissions(StandardPermissions[:]...), Deny: 0, }) @@ -1177,12 +1177,10 @@ func GenerateChannelName(ctx context.Context, worker *worker.Context, panel *dat }), // %nickname% NewSubstitutor("nickname", false, true, func(user user.User, member member.Member) string { - nickname := member.Nick - if len(nickname) == 0 { - nickname = member.User.Username + if member.Nick != nil && len(*member.Nick) > 0 { + return *member.Nick } - - return nickname + return user.Username }), }, []ParameterizedSubstitutor{ // %date% or %date:FORMAT% (e.g., %date:yyyy-mm-dd%) @@ -1325,7 +1323,7 @@ func countRealChannels(channels []channel.Channel, parentId uint64) int { for _, ch := range channels { // Ignore threads - if ch.Type == channel.ChannelTypeGuildPublicThread || ch.Type == channel.ChannelTypeGuildPrivateThread || ch.Type == channel.ChannelTypeGuildNewsThread { + if ch.Type == channel.ChannelTypePublicThread || ch.Type == channel.ChannelTypePrivateThread || ch.Type == channel.ChannelTypeAnnouncementThread { continue } diff --git a/bot/logic/permissions.go b/bot/logic/permissions.go index 8cbc3a8..8495a6a 100644 --- a/bot/logic/permissions.go +++ b/bot/logic/permissions.go @@ -233,7 +233,7 @@ func FilterStaffMembers( return err } - if excludeBots && member.User.Bot { + if excludeBots && member.User != nil && member.User.Bot { return nil } @@ -291,9 +291,11 @@ func GetStaffInThread(ctx context.Context, worker *worker.Context, ticket databa return nil, err } - memberIds := make([]uint64, len(members)) - for i, member := range members { - memberIds[i] = member.UserId + memberIds := make([]uint64, 0, len(members)) + for _, member := range members { + if member.UserId != nil { + memberIds = append(memberIds, *member.UserId) + } } staffIds, err := FilterStaffMembers(ctx, worker, ticket.GuildId, ticket, memberIds, true, true) diff --git a/bot/logic/welcomemessage.go b/bot/logic/welcomemessage.go index 9057cd4..87768f4 100644 --- a/bot/logic/welcomemessage.go +++ b/bot/logic/welcomemessage.go @@ -85,7 +85,7 @@ func SendWelcomeMessage( Label: cmd.GetMessage(i18n.TitleClose), CustomId: "close", Style: component.ButtonStyleDanger, - Emoji: &emoji.Emoji{Name: "🔒"}, + Emoji: &emoji.Emoji{Name: utils.Ptr("🔒")}, })) } if !hideCloseWithReason { @@ -93,7 +93,7 @@ func SendWelcomeMessage( Label: cmd.GetMessage(i18n.TitleCloseWithReason), CustomId: "close_with_reason", Style: component.ButtonStyleDanger, - Emoji: &emoji.Emoji{Name: "🔒"}, + Emoji: &emoji.Emoji{Name: utils.Ptr("🔒")}, })) } @@ -102,7 +102,7 @@ func SendWelcomeMessage( Label: cmd.GetMessage(i18n.TitleClaim), CustomId: "claim", Style: component.ButtonStyleSuccess, - Emoji: &emoji.Emoji{Name: "🙋‍♂️"}, + Emoji: &emoji.Emoji{Name: utils.Ptr("🙋‍♂️")}, })) } @@ -511,7 +511,13 @@ var substitutions = map[string]PlaceholderSubstitutionFunc{ }, "nickname": func(ctx context.Context, worker *worker.Context, ticket database.Ticket) string { member, _ := worker.GetGuildMember(ticket.GuildId, ticket.UserId) - return member.Nick + if member.Nick != nil && len(*member.Nick) > 0 { + return *member.Nick + } + if member.User != nil { + return member.User.Username + } + return "" }, "server": func(ctx context.Context, worker *worker.Context, ticket database.Ticket) string { guild, _ := worker.GetGuild(ticket.GuildId) diff --git a/bot/permissionwrapper/permission.go b/bot/permissionwrapper/permission.go index cf66095..bf56660 100644 --- a/bot/permissionwrapper/permission.go +++ b/bot/permissionwrapper/permission.go @@ -185,7 +185,7 @@ func getChannelMemberPermissions(ctx *worker.Context, userId, channelId uint64, } for _, overwrite := range ch.PermissionOverwrites { - if overwrite.Type == channel.PermissionTypeMember && overwrite.Id == userId { + if overwrite.Type == channel.PermissionOverwriteTypeMember && overwrite.Id == userId { initialPermissions &= ^overwrite.Deny initialPermissions |= overwrite.Allow } @@ -216,7 +216,7 @@ func getChannelTotalRolePermissions(ctx *worker.Context, guildId, userId, channe for _, role := range roles { if memberRole == role.Id { for _, overwrite := range ch.PermissionOverwrites { - if overwrite.Type == channel.PermissionTypeRole && overwrite.Id == role.Id { + if overwrite.Type == channel.PermissionOverwriteTypeRole && overwrite.Id == role.Id { allow |= overwrite.Allow deny |= overwrite.Deny break @@ -256,7 +256,7 @@ func getChannelBasePermissions(ctx *worker.Context, guildId, channelId uint64, i } for _, overwrite := range ch.PermissionOverwrites { - if overwrite.Type == channel.PermissionTypeRole && overwrite.Id == publicRole.Id { + if overwrite.Type == channel.PermissionOverwriteTypeRole && overwrite.Id == publicRole.Id { initialPermissions &= ^overwrite.Deny initialPermissions |= overwrite.Allow break diff --git a/bot/utils/errorutils.go b/bot/utils/errorutils.go index 497a3fa..ebf4542 100644 --- a/bot/utils/errorutils.go +++ b/bot/utils/errorutils.go @@ -6,8 +6,12 @@ import ( ) func MessageCreateErrorContext(e events.MessageCreate) errorcontext.WorkerErrorContext { + var guildId uint64 + if e.GuildId != nil { + guildId = *e.GuildId + } return errorcontext.WorkerErrorContext{ - Guild: e.GuildId, + Guild: guildId, User: e.Author.Id, Channel: e.ChannelId, } diff --git a/bot/utils/messageutils.go b/bot/utils/messageutils.go index 8ef9937..959e5d8 100644 --- a/bot/utils/messageutils.go +++ b/bot/utils/messageutils.go @@ -96,7 +96,7 @@ func EmbedField(guildId uint64, name string, value i18n.MessageId, inline bool, func BuildEmoji(emote string) *emoji.Emoji { return &emoji.Emoji{ - Name: emote, + Name: &emote, } } diff --git a/cmd/registercommands/main.go b/cmd/registercommands/main.go index 3ae3f23..01fa4b4 100644 --- a/cmd/registercommands/main.go +++ b/cmd/registercommands/main.go @@ -46,7 +46,7 @@ func main() { // Handle admin commands for a specific guild, merging if requested if *AdminCommandGuildId != 0 { if *MergeGuildCommands { - existingCmds := must(rest.GetGuildCommands(context.Background(), *Token, nil, applicationId, *AdminCommandGuildId)) + existingCmds := must(rest.GetGuildCommands(context.Background(), *Token, nil, applicationId, *AdminCommandGuildId, false)) for _, cmd := range existingCmds { var found bool for _, newCmd := range adminCommands { @@ -71,7 +71,7 @@ func main() { } // Output all global commands as JSON - cmds := must(rest.GetGlobalCommands(context.Background(), *Token, nil, applicationId)) + cmds := must(rest.GetGlobalCommands(context.Background(), *Token, nil, applicationId, false)) marshalled := must(json.MarshalIndent(cmds, "", " ")) fmt.Println(string(marshalled)) } diff --git a/event/errorcontext.go b/event/errorcontext.go index 3fa75fc..df84b92 100644 --- a/event/errorcontext.go +++ b/event/errorcontext.go @@ -48,7 +48,7 @@ func NewMessageComponentInteractionErrorContext(data interaction.InteractionMeta /* if data.Data.Type() == component.ComponentButton { m["custom_id"] = data.Data.AsButton().CustomId - } else if data.Data.Type() == component.ComponentSelectMenu { + } else if data.Data.Type() == component.ComponentStringSelect { m["custom_id"] = data.Data.AsSelectMenu().CustomId } */ diff --git a/go.mod b/go.mod index 01d2105..269c4a8 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ toolchain go1.24.2 //replace github.com/TicketsBot-cloud/common => ../common -//replace github.com/TicketsBot-cloud/gdl => ../gdl +replace github.com/TicketsBot-cloud/gdl => ../gdl //replace github.com/TicketsBot-cloud/archiverclient => ../archiverclient -//replace github.com/TicketsBot-cloud/logarchiver => ../logarchiver +replace github.com/TicketsBot-cloud/logarchiver => ../logarchiver require ( cloud.google.com/go/profiler v0.4.2 diff --git a/restwrapper.go b/restwrapper.go index a8118a6..31b69bd 100644 --- a/restwrapper.go +++ b/restwrapper.go @@ -6,15 +6,22 @@ import ( "github.com/TicketsBot-cloud/gdl/cache" "github.com/TicketsBot-cloud/gdl/objects/auditlog" + "github.com/TicketsBot-cloud/gdl/objects/automoderation" "github.com/TicketsBot-cloud/gdl/objects/channel" "github.com/TicketsBot-cloud/gdl/objects/channel/embed" "github.com/TicketsBot-cloud/gdl/objects/channel/message" "github.com/TicketsBot-cloud/gdl/objects/guild" "github.com/TicketsBot-cloud/gdl/objects/guild/emoji" + "github.com/TicketsBot-cloud/gdl/objects/guild/scheduledevent" + "github.com/TicketsBot-cloud/gdl/objects/guild/sticker" "github.com/TicketsBot-cloud/gdl/objects/integration" "github.com/TicketsBot-cloud/gdl/objects/interaction" "github.com/TicketsBot-cloud/gdl/objects/invite" "github.com/TicketsBot-cloud/gdl/objects/member" + "github.com/TicketsBot-cloud/gdl/objects/sku" + "github.com/TicketsBot-cloud/gdl/objects/guild/soundboard" + "github.com/TicketsBot-cloud/gdl/objects/guild/stage" + "github.com/TicketsBot-cloud/gdl/objects/subscription" "github.com/TicketsBot-cloud/gdl/objects/user" "github.com/TicketsBot-cloud/gdl/rest" ) @@ -180,7 +187,7 @@ func (ctx *Context) GetThreadMember(channelId, userId uint64) (channel.ThreadMem } func (ctx *Context) ListThreadMembers(channelId uint64) ([]channel.ThreadMember, error) { - return rest.ListThreadMembers(context.Background(), ctx.Token, ctx.RateLimiter, channelId) + return rest.ListThreadMembers(context.Background(), ctx.Token, ctx.RateLimiter, channelId, rest.ListThreadMembersData{}) } func (ctx *Context) ListActiveThreads(channelId uint64) (rest.ThreadsResponse, error) { @@ -211,7 +218,7 @@ func (ctx *Context) CreatePublicThread(channelId uint64, name string, autoArchiv data := rest.StartThreadWithoutMessageData{ Name: name, AutoArchiveDuration: autoArchiveDuration, - Type: channel.ChannelTypeGuildPublicThread, + Type: channel.ChannelTypePublicThread, } return rest.StartThreadWithoutMessage(context.Background(), ctx.Token, ctx.RateLimiter, channelId, data) @@ -221,7 +228,7 @@ func (ctx *Context) CreatePrivateThread(requestCtx context.Context, channelId ui data := rest.StartThreadWithoutMessageData{ Name: name, AutoArchiveDuration: autoArchiveDuration, - Type: channel.ChannelTypeGuildPrivateThread, + Type: channel.ChannelTypePrivateThread, Invitable: invitable, } @@ -461,8 +468,8 @@ func (ctx *Context) GetGuildPruneCount(guildId uint64, days int) (int, error) { } // computePruneCount = whether 'pruned' is returned, discouraged for large guilds -func (ctx *Context) BeginGuildPrune(guildId uint64, days int, computePruneCount bool) error { - return rest.BeginGuildPrune(context.Background(), ctx.Token, ctx.RateLimiter, guildId, days, computePruneCount) +func (ctx *Context) BeginGuildPrune(guildId uint64, data rest.BeginGuildPruneData) error { + return rest.BeginGuildPrune(context.Background(), ctx.Token, ctx.RateLimiter, guildId, data) } func (ctx *Context) GetGuildVoiceRegions(guildId uint64) ([]guild.VoiceRegion, error) { @@ -506,8 +513,8 @@ func (ctx *Context) GetGuildVanityUrl(guildId uint64) (invite.Invite, error) { return rest.GetGuildVanityURL(context.Background(), ctx.Token, ctx.RateLimiter, guildId) } -func (ctx *Context) GetInvite(inviteCode string, withCounts bool) (invite.Invite, error) { - return rest.GetInvite(context.Background(), ctx.Token, ctx.RateLimiter, inviteCode, withCounts) +func (ctx *Context) GetInvite(inviteCode string, withCounts bool, guildScheduledEventId *uint64) (invite.Invite, error) { + return rest.GetInvite(context.Background(), ctx.Token, ctx.RateLimiter, inviteCode, withCounts, guildScheduledEventId) } func (ctx *Context) DeleteInvite(inviteCode string) (invite.Invite, error) { @@ -611,7 +618,7 @@ func (ctx *Context) GetGuildAuditLog(guildId uint64, data rest.GetGuildAuditLogD } func (ctx *Context) GetGlobalCommands(applicationId uint64) ([]interaction.ApplicationCommand, error) { - return rest.GetGlobalCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId) + return rest.GetGlobalCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, false) } func (ctx *Context) CreateGlobalCommand(applicationId uint64, data rest.CreateCommandData) (interaction.ApplicationCommand, error) { @@ -627,7 +634,7 @@ func (ctx *Context) DeleteGlobalCommand(applicationId, commandId uint64) error { } func (ctx *Context) GetGuildCommands(applicationId, guildId uint64) ([]interaction.ApplicationCommand, error) { - return rest.GetGuildCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, guildId) + return rest.GetGuildCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, guildId, false) } func (ctx *Context) CreateGuildCommand(applicationId, guildId uint64, data rest.CreateCommandData) (interaction.ApplicationCommand, error) { @@ -657,3 +664,179 @@ func (ctx *Context) EditCommandPermissions(applicationId, guildId, commandId uin func (ctx *Context) EditBulkCommandPermissions(applicationId, guildId uint64, data []rest.CommandWithPermissionsData) ([]rest.CommandWithPermissionsData, error) { return rest.EditBulkCommandPermissions(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, guildId, data) } + +func (ctx *Context) ModifyGlobalCommands(applicationId uint64, data []rest.CreateCommandData) ([]interaction.ApplicationCommand, error) { + return rest.ModifyGlobalCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, data) +} + +func (ctx *Context) ModifyGuildCommands(applicationId, guildId uint64, data []rest.CreateCommandData) ([]interaction.ApplicationCommand, error) { + return rest.ModifyGuildCommands(context.Background(), ctx.Token, ctx.RateLimiter, applicationId, guildId, data) +} + +func (ctx *Context) EditWebhookMessage(webhookId uint64, webhookToken string, messageId uint64, data rest.WebhookEditBody) (message.Message, error) { + return rest.EditWebhookMessage(context.Background(), webhookToken, ctx.RateLimiter, webhookId, messageId, data) +} + +func (ctx *Context) AddGuildMember(guildId, userId uint64, data rest.AddGuildMemberData) (*member.Member, error) { + return rest.AddGuildMember(context.Background(), ctx.Token, ctx.RateLimiter, guildId, userId, data) +} + +func (ctx *Context) GetGuildWelcomeScreen(guildId uint64) (guild.WelcomeScreen, error) { + return rest.GetGuildWelcomeScreen(context.Background(), ctx.Token, ctx.RateLimiter, guildId) +} + +func (ctx *Context) ModifyGuildWelcomeScreen(guildId uint64, data rest.ModifyGuildWelcomeScreenData) (guild.WelcomeScreen, error) { + return rest.ModifyGuildWelcomeScreen(context.Background(), ctx.Token, ctx.RateLimiter, guildId, data) +} + +// Auto-moderation + +func (ctx *Context) ListAutoModerationRules(guildId uint64) ([]automoderation.Rule, error) { + return rest.ListAutoModerationRules(context.Background(), ctx.Token, ctx.RateLimiter, guildId) +} + +func (ctx *Context) GetAutoModerationRule(guildId, ruleId uint64) (automoderation.Rule, error) { + return rest.GetAutoModerationRule(context.Background(), ctx.Token, ctx.RateLimiter, guildId, ruleId) +} + +func (ctx *Context) CreateAutoModerationRule(guildId uint64, data rest.CreateAutoModerationRuleData) (automoderation.Rule, error) { + return rest.CreateAutoModerationRule(context.Background(), ctx.Token, ctx.RateLimiter, guildId, data) +} + +func (ctx *Context) ModifyAutoModerationRule(guildId, ruleId uint64, data rest.ModifyAutoModerationRuleData) (automoderation.Rule, error) { + return rest.ModifyAutoModerationRule(context.Background(), ctx.Token, ctx.RateLimiter, guildId, ruleId, data) +} + +func (ctx *Context) DeleteAutoModerationRule(guildId, ruleId uint64) error { + return rest.DeleteAutoModerationRule(context.Background(), ctx.Token, ctx.RateLimiter, guildId, ruleId) +} + +// Scheduled events + +func (ctx *Context) ListGuildScheduledEvents(guildId uint64, withUserCount bool) ([]scheduledevent.GuildScheduledEvent, error) { + return rest.ListGuildScheduledEvents(context.Background(), ctx.Token, ctx.RateLimiter, guildId, withUserCount) +} + +func (ctx *Context) GetGuildScheduledEvent(guildId, eventId uint64, withUserCount bool) (scheduledevent.GuildScheduledEvent, error) { + return rest.GetGuildScheduledEvent(context.Background(), ctx.Token, ctx.RateLimiter, guildId, eventId, withUserCount) +} + +func (ctx *Context) CreateGuildScheduledEvent(guildId uint64, data rest.CreateGuildScheduledEventData) (scheduledevent.GuildScheduledEvent, error) { + return rest.CreateGuildScheduledEvent(context.Background(), ctx.Token, ctx.RateLimiter, guildId, data) +} + +func (ctx *Context) ModifyGuildScheduledEvent(guildId, eventId uint64, data rest.ModifyGuildScheduledEventData) (scheduledevent.GuildScheduledEvent, error) { + return rest.ModifyGuildScheduledEvent(context.Background(), ctx.Token, ctx.RateLimiter, guildId, eventId, data) +} + +func (ctx *Context) DeleteGuildScheduledEvent(guildId, eventId uint64) error { + return rest.DeleteGuildScheduledEvent(context.Background(), ctx.Token, ctx.RateLimiter, guildId, eventId) +} + +func (ctx *Context) GetGuildScheduledEventUsers(guildId, eventId uint64, data rest.GetGuildScheduledEventUsersData) ([]rest.GuildScheduledEventUser, error) { + return rest.GetGuildScheduledEventUsers(context.Background(), ctx.Token, ctx.RateLimiter, guildId, eventId, data) +} + +// Stage instances + +func (ctx *Context) CreateStageInstance(data rest.CreateStageInstanceData) (stage.StageInstance, error) { + return rest.CreateStageInstance(context.Background(), ctx.Token, ctx.RateLimiter, data) +} + +func (ctx *Context) GetStageInstance(channelId uint64) (stage.StageInstance, error) { + return rest.GetStageInstance(context.Background(), ctx.Token, ctx.RateLimiter, channelId) +} + +func (ctx *Context) ModifyStageInstance(channelId uint64, data rest.ModifyStageInstanceData) (stage.StageInstance, error) { + return rest.ModifyStageInstance(context.Background(), ctx.Token, ctx.RateLimiter, channelId, data) +} + +func (ctx *Context) DeleteStageInstance(channelId uint64) error { + return rest.DeleteStageInstance(context.Background(), ctx.Token, ctx.RateLimiter, channelId) +} + +// Soundboard + +func (ctx *Context) SendSoundboardSound(channelId uint64, data rest.SendSoundboardSoundData) error { + return rest.SendSoundboardSound(context.Background(), ctx.Token, ctx.RateLimiter, channelId, data) +} + +func (ctx *Context) GetDefaultSoundboardSounds() ([]soundboard.SoundboardSound, error) { + return rest.GetDefaultSoundboardSounds(context.Background(), ctx.Token, ctx.RateLimiter) +} + +func (ctx *Context) ListGuildSoundboardSounds(guildId uint64) ([]soundboard.SoundboardSound, error) { + return rest.ListGuildSoundboardSounds(context.Background(), ctx.Token, ctx.RateLimiter, guildId) +} + +func (ctx *Context) GetGuildSoundboardSound(guildId, soundId uint64) (soundboard.SoundboardSound, error) { + return rest.GetGuildSoundboardSound(context.Background(), ctx.Token, ctx.RateLimiter, guildId, soundId) +} + +func (ctx *Context) CreateGuildSoundboardSound(guildId uint64, data rest.CreateGuildSoundboardSoundData) (soundboard.SoundboardSound, error) { + return rest.CreateGuildSoundboardSound(context.Background(), ctx.Token, ctx.RateLimiter, guildId, data) +} + +func (ctx *Context) ModifyGuildSoundboardSound(guildId, soundId uint64, data rest.ModifyGuildSoundboardSoundData) (soundboard.SoundboardSound, error) { + return rest.ModifyGuildSoundboardSound(context.Background(), ctx.Token, ctx.RateLimiter, guildId, soundId, data) +} + +func (ctx *Context) DeleteGuildSoundboardSound(guildId, soundId uint64) error { + return rest.DeleteGuildSoundboardSound(context.Background(), ctx.Token, ctx.RateLimiter, guildId, soundId) +} + +// Poll + +func (ctx *Context) GetPollAnswerVoters(channelId, messageId uint64, answerId int, data rest.GetPollAnswerVotersData) ([]user.User, error) { + return rest.GetPollAnswerVoters(context.Background(), ctx.Token, ctx.RateLimiter, channelId, messageId, answerId, data) +} + +func (ctx *Context) EndPoll(channelId, messageId uint64) (message.Message, error) { + return rest.EndPoll(context.Background(), ctx.Token, ctx.RateLimiter, channelId, messageId) +} + +// SKU + +func (ctx *Context) ListSKUs(applicationId uint64) ([]sku.SKU, error) { + return rest.ListSKUs(context.Background(), ctx.Token, ctx.RateLimiter, applicationId) +} + +// Subscriptions + +func (ctx *Context) ListSKUSubscriptions(skuId uint64, data rest.ListSKUSubscriptionsData) ([]subscription.Subscription, error) { + return rest.ListSKUSubscriptions(context.Background(), ctx.Token, ctx.RateLimiter, skuId, data) +} + +func (ctx *Context) GetSKUSubscription(skuId, subscriptionId uint64) (subscription.Subscription, error) { + return rest.GetSKUSubscription(context.Background(), ctx.Token, ctx.RateLimiter, skuId, subscriptionId) +} + +// Stickers + +func (ctx *Context) GetSticker(stickerId uint64) (sticker.Sticker, error) { + return rest.GetSticker(context.Background(), ctx.Token, ctx.RateLimiter, stickerId) +} + +func (ctx *Context) GetStickerPacks() ([]rest.StickerPack, error) { + return rest.GetStickerPacks(context.Background(), ctx.Token, ctx.RateLimiter) +} + +func (ctx *Context) GetStickerPack(packId uint64) (rest.StickerPack, error) { + return rest.GetStickerPack(context.Background(), ctx.Token, ctx.RateLimiter, packId) +} + +func (ctx *Context) ListGuildStickers(guildId uint64) ([]sticker.Sticker, error) { + return rest.ListGuildStickers(context.Background(), ctx.Token, ctx.RateLimiter, guildId) +} + +func (ctx *Context) GetGuildSticker(guildId, stickerId uint64) (sticker.Sticker, error) { + return rest.GetGuildSticker(context.Background(), ctx.Token, ctx.RateLimiter, guildId, stickerId) +} + +func (ctx *Context) ModifyGuildSticker(guildId, stickerId uint64, data rest.ModifyGuildStickerData) (sticker.Sticker, error) { + return rest.ModifyGuildSticker(context.Background(), ctx.Token, ctx.RateLimiter, guildId, stickerId, data) +} + +func (ctx *Context) DeleteGuildSticker(guildId, stickerId uint64) error { + return rest.DeleteGuildSticker(context.Background(), ctx.Token, ctx.RateLimiter, guildId, stickerId) +} diff --git a/tools/cmd/generatecmdcaller.go b/tools/cmd/generatecmdcaller.go index c422608..a219b17 100644 --- a/tools/cmd/generatecmdcaller.go +++ b/tools/cmd/generatecmdcaller.go @@ -27,15 +27,15 @@ type executorData struct { var callerTemplate string var typeMap = map[interaction.ApplicationCommandOptionType]reflect.Type{ - interaction.OptionTypeString: reflect.TypeOf(""), // string - interaction.OptionTypeInteger: reflect.TypeOf(int(0)), // int - interaction.OptionTypeBoolean: reflect.TypeOf(false), // bool - interaction.OptionTypeUser: reflect.TypeOf(uint64(0)), // snowflake - interaction.OptionTypeChannel: reflect.TypeOf(uint64(0)), // snowflake - interaction.OptionTypeRole: reflect.TypeOf(uint64(0)), // snowflake - interaction.OptionTypeMentionable: reflect.TypeOf(uint64(0)), // snowflake - interaction.OptionTypeNumber: reflect.TypeOf(float64(0)), // float64 - interaction.OptionTypeAttachment: reflect.TypeOf(channel.Attachment{}), // attachment + interaction.ApplicationCommandOptionTypeString: reflect.TypeOf(""), // string + interaction.ApplicationCommandOptionTypeInteger: reflect.TypeOf(int(0)), // int + interaction.ApplicationCommandOptionTypeBoolean: reflect.TypeOf(false), // bool + interaction.ApplicationCommandOptionTypeUser: reflect.TypeOf(uint64(0)), // snowflake + interaction.ApplicationCommandOptionTypeChannel: reflect.TypeOf(uint64(0)), // snowflake + interaction.ApplicationCommandOptionTypeRole: reflect.TypeOf(uint64(0)), // snowflake + interaction.ApplicationCommandOptionTypeMentionable: reflect.TypeOf(uint64(0)), // snowflake + interaction.ApplicationCommandOptionTypeNumber: reflect.TypeOf(float64(0)), // float64 + interaction.ApplicationCommandOptionTypeAttachment: reflect.TypeOf(channel.Attachment{}), // attachment } func main() {