diff --git a/go.mod b/go.mod index de3a2e3..d92f177 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/TannerKvarfordt/Kard-bot go 1.18 require ( - github.com/TannerKvarfordt/gopenai v0.1.1-beta - github.com/TannerKvarfordt/hfapigo v0.0.4 - github.com/TannerKvarfordt/imgflipgo v1.0.5 - github.com/TannerKvarfordt/ubiquity v0.2.1 + github.com/TannerKvarfordt/gopenai v0.1.2-beta + github.com/TannerKvarfordt/hfapigo v0.0.5 + github.com/TannerKvarfordt/imgflipgo v1.0.6 + github.com/TannerKvarfordt/ubiquity v0.2.2 github.com/bwmarrin/discordgo v0.27.0 github.com/deadshot465/owoify-go v1.0.1 github.com/forPelevin/gomoji v1.1.8 diff --git a/go.sum b/go.sum index 43b3ca0..61a417d 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,12 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/TannerKvarfordt/gopenai v0.1.1-beta h1:aocEuxS6jLHLnoa1aH//18fuRbmeYTsFVhFSygmee3I= -github.com/TannerKvarfordt/gopenai v0.1.1-beta/go.mod h1:VJ5vqh+nTGVmZmeAWJBlMjaaFb/XLAO8vW/FzlWvN5U= -github.com/TannerKvarfordt/hfapigo v0.0.4 h1:HDuUoIotKm0hCg7piwc1kQIdGjgDMgFyanMRWPWIFJI= -github.com/TannerKvarfordt/hfapigo v0.0.4/go.mod h1:XKhHnldnhSZNCrRZclWr2D/A/UlEGaQ8OxpM7r8wQpE= -github.com/TannerKvarfordt/imgflipgo v1.0.5 h1:y9q6Vt4cq0bH3FvlDuEfqabZURtdcD7KYZ4EYdWDWIw= -github.com/TannerKvarfordt/imgflipgo v1.0.5/go.mod h1:wvuZ3+UAyCtKuvqn0Thcjhj31yetO8/baXPBYI5i9Ug= -github.com/TannerKvarfordt/ubiquity v0.2.1 h1:50UxqYBrWFuH47o0styX29/zC0PykfyHyqehFbAlkiU= -github.com/TannerKvarfordt/ubiquity v0.2.1/go.mod h1:TeemeL8b8YiXysB1BlOMwmA8nhwIKeg+ZiOJ6Yiwmlg= +github.com/TannerKvarfordt/gopenai v0.1.2-beta h1:Zy4AjMmyyLlwgC49nKWiAdojvYkHf9AT5hG+LMGzdGk= +github.com/TannerKvarfordt/gopenai v0.1.2-beta/go.mod h1:X42mdDQIih6TLzctpf8Wp/cIGpHaMiImMWZ+BQz7nT0= +github.com/TannerKvarfordt/hfapigo v0.0.5 h1:E8OZQxpfQEHRrXjHlc5vHBUMLqL1XvtdqDyNY27rUT4= +github.com/TannerKvarfordt/hfapigo v0.0.5/go.mod h1:s+zHgKdagSPlw8xPMokwQaS32BakBMOljQImxStboF0= +github.com/TannerKvarfordt/imgflipgo v1.0.6 h1:u7HRbGsTBE1VjrQuk2UUJTJEDf/jvbh0QVhGPF6m/zA= +github.com/TannerKvarfordt/imgflipgo v1.0.6/go.mod h1:wLVihMPHZAVEfAzU047L6tIxdm1WZ8KvZc71DrOrseY= +github.com/TannerKvarfordt/ubiquity v0.2.2 h1:SWbXc58MZjrdmJxk/WjdZKbfuHbWTAJ9ToxyDnhZAnQ= +github.com/TannerKvarfordt/ubiquity v0.2.2/go.mod h1:6X6j49wHJuqLF1OBq5hfdo25SZnJDGl59RRvIpnxw4Q= github.com/bwmarrin/discordgo v0.27.0 h1:4ZK9KN+rGIxZ0fdGTmgdCcliQeW8Zhu6MnlFI92nf0Q= github.com/bwmarrin/discordgo v0.27.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/kardbot/bot_info.go b/kardbot/bot_info.go index 47ce6ca..85f5e23 100644 --- a/kardbot/bot_info.go +++ b/kardbot/bot_info.go @@ -63,7 +63,7 @@ func botInfo(s *discordgo.Session, i *discordgo.InteractionCreate) { err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Embeds: []*discordgo.MessageEmbed{embed.Truncate().MessageEmbed}, Files: []*discordgo.File{ { diff --git a/kardbot/botdms.go b/kardbot/botdms.go index b06c138..7953679 100644 --- a/kardbot/botdms.go +++ b/kardbot/botdms.go @@ -36,7 +36,7 @@ func deleteBotDMs(s *discordgo.Session, i *discordgo.InteractionCreate) { err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -67,8 +67,9 @@ func deleteBotDMs(s *discordgo.Session, i *discordgo.InteractionCreate) { } time.Sleep(time.Millisecond * 100) + errMsg := fmt.Sprintf("looks like you tried to use `/%s` outside of our DMs. Run it from there instead! :)", delBotDMCmd) s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("looks like you tried to use `/%s` outside of our DMs. Run it from there instead! :)", delBotDMCmd), + Content: &errMsg, }) return } @@ -117,8 +118,9 @@ func deleteBotDMs(s *discordgo.Session, i *discordgo.InteractionCreate) { } } + errMsg := fmt.Sprintf("Deleted last %d bot DMs", mathutils.Min(msgsToDelete, msgLimit)) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("Deleted last %d bot DMs", mathutils.Min(msgsToDelete, msgLimit)), + Content: &errMsg, }) if err != nil { log.Error(err) diff --git a/kardbot/compliments.go b/kardbot/compliments.go index 5b32542..57dd163 100644 --- a/kardbot/compliments.go +++ b/kardbot/compliments.go @@ -150,7 +150,7 @@ func morningComplimentOptIn(s *discordgo.Session, i *discordgo.InteractionCreate Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s, you are subscribed to receive morning compliments as long as the bot is up, but there was an error persisting your subscription. Please try to opt-in again.", metadata.AuthorUsername), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -192,7 +192,7 @@ func morningComplimentOptOut(s *discordgo.Session, i *discordgo.InteractionCreat Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s, you are unsubscribed from morning compliments as long as the bot is up, but there was an error persisting your opt-out. Please try to opt-out again.", metadata.AuthorUsername), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -235,7 +235,7 @@ func eveningComplimentOptIn(s *discordgo.Session, i *discordgo.InteractionCreate Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s, you are subscribed to receive evening compliments as long as the bot is up, but there was an error persisting your subscription. Please try to opt-in again.", metadata.AuthorUsername), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -277,7 +277,7 @@ func eveningComplimentOptOut(s *discordgo.Session, i *discordgo.InteractionCreat Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s, you are unsubscribed from evening compliments as long as the bot is up, but there was an error persisting your opt-out. Please try to opt-out again.", metadata.AuthorUsername), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -319,7 +319,7 @@ func getCompliment(s *discordgo.Session, i *discordgo.InteractionCreate) { err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -339,8 +339,9 @@ func getCompliment(s *discordgo.Session, i *discordgo.InteractionCreate) { log.Infof("Told %s that '%s'", metadata.AuthorUsername, compliment) time.Sleep(time.Millisecond * 250) // give a bit for the initial response to be received + content := "Sent you a compliment! ๐Ÿ’›" _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: "Sent you a compliment! ๐Ÿ’›", + Content: &content, }) if err != nil { log.Error(err) diff --git a/kardbot/creepydm.go b/kardbot/creepydm.go index c2a8c6e..24e71a0 100644 --- a/kardbot/creepydm.go +++ b/kardbot/creepydm.go @@ -140,7 +140,7 @@ func creepyDMsOptIn(s *discordgo.Session, i *discordgo.InteractionCreate) error Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s, you are subscribed to creepy DMs as long as the bot remains up, but there was an error persisting your subscription. Please try to opt-in again.", metadata.AuthorUsername), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -231,7 +231,7 @@ func getCreepyDM(s *discordgo.Session, i *discordgo.InteractionCreate) error { Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "Sent you a creepy DM ๐Ÿ˜ˆ", - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) } diff --git a/kardbot/dalle2.go b/kardbot/dalle2.go index 43ca7b9..b4a99ec 100644 --- a/kardbot/dalle2.go +++ b/kardbot/dalle2.go @@ -101,8 +101,9 @@ func handleDalle2Cmd(s *discordgo.Session, i *discordgo.InteractionCreate) { return } + errMsg := fmt.Sprintf("> %s\n\nImage generated using [DALLยทE 2]().", prompt) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("> %s\n\nImage generated using [DALLยทE 2]().", prompt), + Content: &errMsg, Files: []*discordgo.File{ { Name: "Dalle-2-Output.png", diff --git a/kardbot/dg_helpers/embed.go b/kardbot/dg_helpers/embed.go index b5e8be8..d71975e 100644 --- a/kardbot/dg_helpers/embed.go +++ b/kardbot/dg_helpers/embed.go @@ -9,7 +9,7 @@ import ( "github.com/bwmarrin/discordgo" ) -//Embed ... +// Embed ... type Embed struct { *discordgo.MessageEmbed } @@ -25,12 +25,12 @@ const ( EmbedLimit = 4000 ) -//NewEmbed returns a new embed object +// NewEmbed returns a new embed object func NewEmbed() *Embed { return &Embed{&discordgo.MessageEmbed{}} } -//SetTitle ... +// SetTitle ... func (e *Embed) SetTitle(name string) *Embed { e.Title = name return e @@ -61,7 +61,7 @@ func (e *Embed) SetVideo(url string, args ...int) *Embed { return e } -//SetDescription [desc] +// SetDescription [desc] func (e *Embed) SetDescription(description string) *Embed { if len(description) > 2048 { description = description[:2048] @@ -70,7 +70,7 @@ func (e *Embed) SetDescription(description string) *Embed { return e } -//AddField [name] [value] +// AddField [name] [value] func (e *Embed) AddField(name, value string) *Embed { if len(value) > 1024 { value = value[:1024] @@ -89,7 +89,7 @@ func (e *Embed) AddField(name, value string) *Embed { } -//SetFooter [Text] [iconURL] +// SetFooter [Text] [iconURL] func (e *Embed) SetFooter(args ...string) *Embed { iconURL := "" text := "" @@ -117,7 +117,7 @@ func (e *Embed) SetFooter(args ...string) *Embed { return e } -//SetImage ... +// SetImage ... func (e *Embed) SetImage(args ...string) *Embed { var URL string var proxyURL string @@ -138,7 +138,7 @@ func (e *Embed) SetImage(args ...string) *Embed { return e } -//SetThumbnail ... +// SetThumbnail ... func (e *Embed) SetThumbnail(args ...string) *Embed { var URL string var proxyURL string @@ -159,7 +159,7 @@ func (e *Embed) SetThumbnail(args ...string) *Embed { return e } -//SetAuthor ... +// SetAuthor ... func (e *Embed) SetAuthor(args ...string) *Embed { var ( name string @@ -194,13 +194,13 @@ func (e *Embed) SetAuthor(args ...string) *Embed { return e } -//SetURL ... +// SetURL ... func (e *Embed) SetURL(URL string) *Embed { e.URL = URL return e } -//SetColor ... +// SetColor ... func (e *Embed) SetColor(clr int) *Embed { e.Color = clr return e diff --git a/kardbot/dnd.go b/kardbot/dnd.go index c290f9d..06dab74 100644 --- a/kardbot/dnd.go +++ b/kardbot/dnd.go @@ -311,9 +311,9 @@ func handleDnDButtonPress(s *discordgo.Session, i *discordgo.InteractionCreate) content += fmt.Sprintf("Total: %d", total) } - flags := uint64(0) + var flags discordgo.MessageFlags = 0 if cfg.Ephemeral { - flags = InteractionResponseFlagEphemeral + flags = discordgo.MessageFlagsEphemeral } if cfg.DM { diff --git a/kardbot/interactionErrHandling.go b/kardbot/interactionErrHandling.go index 27ad39d..c2601c7 100644 --- a/kardbot/interactionErrHandling.go +++ b/kardbot/interactionErrHandling.go @@ -119,7 +119,7 @@ func interactionRespondEphemeralError(s *discordgo.Session, i *discordgo.Interac Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprint(errResp), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -138,7 +138,7 @@ func interactionRespondEphemeralError(s *discordgo.Session, i *discordgo.Interac Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "Something went wrong while processing your command. ๐Ÿ˜”", - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Components: errReportMsgComponents(errUUID), }, }) @@ -183,7 +183,7 @@ func interactionFollowUpEphemeralError(s *discordgo.Session, i *discordgo.Intera if !notifyOwner { _, err = s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{ Content: fmt.Sprint(errResp), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }) if err != nil { log.Error(err) @@ -202,7 +202,7 @@ func followupWithError(s *discordgo.Session, i *discordgo.InteractionCreate, err errUUID := uuid.New() _, err := s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{ Content: "Something went wrong while processing your command. ๐Ÿ˜”", - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Components: errReportMsgComponents(errUUID), }) if err != nil { @@ -259,7 +259,7 @@ func handleErrorReportSelection(s *discordgo.Session, i *discordgo.InteractionCr Type: discordgo.InteractionResponseUpdateMessage, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s\nThanks for submitting an error report! %s has been notified of the problem.", i.Message.Content, ownerMention), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, AllowedMentions: &discordgo.MessageAllowedMentions{ Users: []string{getOwnerID()}, }, diff --git a/kardbot/interactionUtils.go b/kardbot/interactionUtils.go index e865b1f..b66cc32 100644 --- a/kardbot/interactionUtils.go +++ b/kardbot/interactionUtils.go @@ -7,8 +7,6 @@ import ( "github.com/bwmarrin/discordgo" ) -const InteractionResponseFlagEphemeral = uint64(1 << 6) - func authorIsSelf(s *discordgo.Session, i *discordgo.InteractionCreate) (bool, error) { if s == nil || i == nil { return false, fmt.Errorf("interaction or session is nil") diff --git a/kardbot/madlibs.go b/kardbot/madlibs.go index 9ea0706..ddfd818 100644 --- a/kardbot/madlibs.go +++ b/kardbot/madlibs.go @@ -56,7 +56,7 @@ func handleMadLibCmd(s *discordgo.Session, i *discordgo.InteractionCreate) { Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("No blanks provided. Provide a prompt string containing at least one of the following mask: `%s`.\nFor example: `The quick brown %s jumps over the lazy %s.`", madlibBlank, madlibBlank, madlibBlank), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) return @@ -101,7 +101,7 @@ func handleMadLibCmd(s *discordgo.Session, i *discordgo.InteractionCreate) { } _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: output, + Content: &output, }) if err != nil { log.Error(err) diff --git a/kardbot/memetools.go b/kardbot/memetools.go index 234d289..a312158 100644 --- a/kardbot/memetools.go +++ b/kardbot/memetools.go @@ -205,10 +205,10 @@ func buildMemeCommands() []*discordgo.ApplicationCommand { } func buildAMeme(s *discordgo.Session, i *discordgo.InteractionCreate) { - flags := uint64(0) + var flags discordgo.MessageFlags = 0 isPreview := i.ApplicationCommandData().Options[previewOptIdx].BoolValue() if isPreview { - flags = InteractionResponseFlagEphemeral + flags = discordgo.MessageFlagsEphemeral } err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, @@ -302,7 +302,7 @@ func buildAMeme(s *discordgo.Session, i *discordgo.InteractionCreate) { SetImage(resp.Data.URL) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Embeds: []*discordgo.MessageEmbed{embed.MessageEmbed}, + Embeds: &[]*discordgo.MessageEmbed{embed.MessageEmbed}, }) if err != nil { log.Error(err) diff --git a/kardbot/polls.go b/kardbot/polls.go index 1f6f441..a797864 100644 --- a/kardbot/polls.go +++ b/kardbot/polls.go @@ -30,7 +30,7 @@ type poll struct { // Maps user IDs to votes cast. // Key: Discord User ID // Val: []string - Votes cmap.ConcurrentMap[[]string] + Votes cmap.ConcurrentMap[string, []string] // The date the poll was opened Open time.Time @@ -54,7 +54,7 @@ func newPoll(messageID, channelID string) poll { // Tracks existing polls. // Key: MessageID // Val: poll -var polls cmap.ConcurrentMap[poll] = cmap.New[poll]() +var polls cmap.ConcurrentMap[string, poll] = cmap.New[poll]() const pollsStorageFilepath = "config/polls.json" @@ -316,7 +316,7 @@ func handlePollSubmission(s *discordgo.Session, i *discordgo.InteractionCreate) Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "Sorry, this poll is closed!", - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -329,7 +329,7 @@ func handlePollSubmission(s *discordgo.Session, i *discordgo.InteractionCreate) err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -346,8 +346,9 @@ func handlePollSubmission(s *discordgo.Session, i *discordgo.InteractionCreate) return } + responseRecordedMsg := "Your response has been recorded! ๐Ÿ—ณ๏ธ" _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: "Your response has been recorded! ๐Ÿ—ณ๏ธ", + Content: &responseRecordedMsg, }) if err != nil { log.Error(err) diff --git a/kardbot/reddit.go b/kardbot/reddit.go index 9d8244d..eed784f 100644 --- a/kardbot/reddit.go +++ b/kardbot/reddit.go @@ -96,8 +96,9 @@ func redditRoulette(s *discordgo.Session, i *discordgo.InteractionCreate) { interactionFollowUpEphemeralError(s, i, true, err) return } + content := fmt.Sprintf("%s tried to use `/reddit-roulette nsfw` in a SFW channel, that was naughty! :(", metadata.AuthorUsername) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("%s tried to use `/reddit-roulette nsfw` in a SFW channel, that was naughty! :(", metadata.AuthorUsername), + Content: &content, }) if err != nil { log.Error(err) @@ -137,7 +138,7 @@ func redditRoulette(s *discordgo.Session, i *discordgo.InteractionCreate) { } _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Embeds: []*discordgo.MessageEmbed{embed}, + Embeds: &[]*discordgo.MessageEmbed{embed}, }) if err != nil { log.Error(err) diff --git a/kardbot/role_select.go b/kardbot/role_select.go index a18fa6e..aae1669 100644 --- a/kardbot/role_select.go +++ b/kardbot/role_select.go @@ -458,7 +458,7 @@ func handleRoleSelectMenuUpdate(s *discordgo.Session, i *discordgo.InteractionCr err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -569,11 +569,9 @@ func handleRoleSelectMenuUpdateAdd(s *discordgo.Session, i *discordgo.Interactio return } if !newOptAdded { + content := fmt.Sprintf("You've reached the max number of buttons (%d) a Discord message can hold. You'll have to remove a menu option first or add a new role-select-menu.", maxDiscordActionRows) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf( - "You've reached the max number of buttons (%d) a Discord message can hold. You'll have to remove a menu option first or add a new role-select-menu.", - maxDiscordActionRows, - ), + Content: &content, }) if err != nil { interactionFollowUpEphemeralError(s, i, true, err) @@ -592,7 +590,7 @@ func handleRoleSelectMenuUpdateAdd(s *discordgo.Session, i *discordgo.Interactio } _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: content, + Content: &content, AllowedMentions: &discordgo.MessageAllowedMentions{ Parse: []discordgo.AllowedMentionType{discordgo.AllowedMentionTypeRoles}, }, @@ -633,8 +631,9 @@ func handleRoleSelectMenuUpdateDel(s *discordgo.Session, i *discordgo.Interactio interactionFollowUpEphemeralError(s, i, false, fmt.Errorf("provided message ID does not appear to contain a role select menu:\n\t%v", err)) return } else if !ok { + content := fmt.Sprintf("%s is not present in the menu, nothing to do.", roleToDel.Mention()) _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("%s is not present in the menu, nothing to do.", roleToDel.Mention()), + Content: &content, }) if err != nil { interactionFollowUpEphemeralError(s, i, true, err) @@ -725,8 +724,9 @@ func handleRoleSelectMenuUpdateDel(s *discordgo.Session, i *discordgo.Interactio return } + content := fmt.Sprintf("%s was removed from the menu", roleToDel.Mention()) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: fmt.Sprintf("%s was removed from the menu", roleToDel.Mention()), + Content: &content, }) if err != nil { interactionFollowUpEphemeralError(s, i, true, err) @@ -947,7 +947,7 @@ func handleRoleSelectMenuCreate(s *discordgo.Session, i *discordgo.InteractionCr Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprint(err), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -986,7 +986,7 @@ func handleRoleSelectMenuCreate(s *discordgo.Session, i *discordgo.InteractionCr } iEdit := &discordgo.WebhookEdit{ - Embeds: []*discordgo.MessageEmbed{e.Truncate().MessageEmbed}, + Embeds: &[]*discordgo.MessageEmbed{e.Truncate().MessageEmbed}, AllowedMentions: &discordgo.MessageAllowedMentions{ Parse: []discordgo.AllowedMentionType{ discordgo.AllowedMentionTypeEveryone, @@ -994,16 +994,17 @@ func handleRoleSelectMenuCreate(s *discordgo.Session, i *discordgo.InteractionCr discordgo.AllowedMentionTypeUsers, }, }, + Components: &[]discordgo.MessageComponent{}, } minSelections := 0 for _, m := range sMenus { m.MaxValues = len(m.Options) m.MinValues = &minSelections - iEdit.Components = append(iEdit.Components, discordgo.ActionsRow{ + *(iEdit.Components) = append(*(iEdit.Components), discordgo.ActionsRow{ Components: []discordgo.MessageComponent{m}, }) } - iEdit.Components = append(iEdit.Components, discordgo.ActionsRow{ + *(iEdit.Components) = append(*(iEdit.Components), discordgo.ActionsRow{ Components: []discordgo.MessageComponent{ discordgo.Button{ Label: roleSelectResetButtonLabel, @@ -1089,7 +1090,7 @@ func handleRoleSelection(s *discordgo.Session, i *discordgo.InteractionCreate) { s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) @@ -1141,7 +1142,10 @@ func handleRoleSelection(s *discordgo.Session, i *discordgo.InteractionCreate) { } } - err = s.GuildMemberEdit(metadata.GuildID, metadata.AuthorID, rolesToAddOrKeep) + _, err = s.GuildMemberEdit(metadata.GuildID, metadata.AuthorID, &discordgo.GuildMemberParams{ + Roles: &rolesToAddOrKeep, + }, func(cfg *discordgo.RequestConfig) { cfg.ShouldRetryOnRateLimit = true }) + if err != nil { interactionFollowUpEphemeralError(s, i, true, err) log.Error(err) @@ -1162,7 +1166,7 @@ func handleRoleSelection(s *discordgo.Session, i *discordgo.InteractionCreate) { embed.AddField("Removed Roles โŒ", "<@&"+strings.Join(rolesToRemove, ">\n<@&")+">") } _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Embeds: []*discordgo.MessageEmbed{embed.Truncate().MessageEmbed}, + Embeds: &[]*discordgo.MessageEmbed{embed.Truncate().MessageEmbed}, AllowedMentions: &discordgo.MessageAllowedMentions{ Parse: []discordgo.AllowedMentionType{discordgo.AllowedMentionTypeRoles}, }, @@ -1183,7 +1187,7 @@ func handleRoleSelectReset(s *discordgo.Session, i *discordgo.InteractionCreate) s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) @@ -1212,7 +1216,9 @@ func handleRoleSelectReset(s *discordgo.Session, i *discordgo.InteractionCreate) } } - err = s.GuildMemberEdit(metadata.GuildID, metadata.AuthorID, rolesToKeep) + _, err = s.GuildMemberEdit(metadata.GuildID, metadata.AuthorID, &discordgo.GuildMemberParams{ + Roles: &rolesToKeep, + }, func(cfg *discordgo.RequestConfig) { cfg.ShouldRetryOnRateLimit = true }) if err != nil { interactionFollowUpEphemeralError(s, i, true, err) log.Error(err) @@ -1233,7 +1239,7 @@ func handleRoleSelectReset(s *discordgo.Session, i *discordgo.InteractionCreate) } s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Embeds: []*discordgo.MessageEmbed{embed.Truncate().MessageEmbed}, + Embeds: &[]*discordgo.MessageEmbed{embed.Truncate().MessageEmbed}, AllowedMentions: &discordgo.MessageAllowedMentions{ Parse: []discordgo.AllowedMentionType{discordgo.AllowedMentionTypeRoles}, }, diff --git a/kardbot/slash_embed.go b/kardbot/slash_embed.go index 0413a05..e8ff571 100644 --- a/kardbot/slash_embed.go +++ b/kardbot/slash_embed.go @@ -231,12 +231,12 @@ func handleEmbedCmd(s *discordgo.Session, i *discordgo.InteractionCreate) { func handleEmbedSubCmdCreate(s *discordgo.Session, i *discordgo.InteractionCreate) (*discordgo.InteractionResponse, bool, error) { e := dg_helpers.NewEmbed() - flags := uint64(0) + var flags discordgo.MessageFlags = 0 for _, opt := range i.ApplicationCommandData().Options[0].Options { switch opt.Name { case embedSubCmdCreateOptPreview: if opt.BoolValue() { - flags = InteractionResponseFlagEphemeral + flags = discordgo.MessageFlagsEphemeral } case embedSubCmdOptURL: e.SetURL(opt.StringValue()) @@ -374,7 +374,7 @@ func handleEmbedSubCmdUpdate(s *discordgo.Session, i *discordgo.InteractionCreat return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: "The embed was successfully updated!", }, }, false, nil @@ -443,7 +443,7 @@ func handleEmbedSubCmdAddField(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: "The embed was successfully updated!", }, }, false, nil @@ -500,7 +500,7 @@ func handleEmbedSubCmdDelField(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: "The embed was successfully updated!", }, }, false, nil diff --git a/kardbot/storytime.go b/kardbot/storytime.go index 46b4fe7..9aa2513 100644 --- a/kardbot/storytime.go +++ b/kardbot/storytime.go @@ -135,7 +135,7 @@ func storyTime(s *discordgo.Session, i *discordgo.InteractionCreate) { Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{buildStoryTimeHelpEmbed()}, - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err != nil { @@ -154,7 +154,7 @@ func storyTime(s *discordgo.Session, i *discordgo.InteractionCreate) { Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: fmt.Sprintf("%s is not a valid model", model), - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, }, }) if err2 != nil { @@ -197,8 +197,9 @@ func storyTime(s *discordgo.Session, i *discordgo.InteractionCreate) { return } + content := stringutils.FirstN(textResps[0].GeneratedTexts[0], MaxDiscordMsgLen) _, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ - Content: stringutils.FirstN(textResps[0].GeneratedTexts[0], MaxDiscordMsgLen), + Content: &content, AllowedMentions: &discordgo.MessageAllowedMentions{ Parse: []discordgo.AllowedMentionType{ discordgo.AllowedMentionTypeUsers, diff --git a/kardbot/time.go b/kardbot/time.go index 35fe737..8f5d5e8 100644 --- a/kardbot/time.go +++ b/kardbot/time.go @@ -242,7 +242,7 @@ func handleTZSubCmd(s *discordgo.Session, i *discordgo.InteractionCreate) (*disc } func handleTZSubCmdHelp(s *discordgo.Session, i *discordgo.InteractionCreate) (*discordgo.InteractionResponse, bool, error) { - flags := InteractionResponseFlagEphemeral + flags := discordgo.MessageFlagsEphemeral for _, opt := range i.ApplicationCommandData().Options[0].Options[0].Options { switch opt.Name { case timeCmdOptEphemeral: @@ -288,7 +288,7 @@ func handleTZSubCmdHelp(s *discordgo.Session, i *discordgo.InteractionCreate) (* } func handleTZSubCmdInfo(s *discordgo.Session, i *discordgo.InteractionCreate) (*discordgo.InteractionResponse, bool, error) { - flags := InteractionResponseFlagEphemeral + flags := discordgo.MessageFlagsEphemeral tz := "" format := tzSubCmdFmtDflt for _, opt := range i.ApplicationCommandData().Options[0].Options[0].Options { @@ -311,7 +311,7 @@ func handleTZSubCmdInfo(s *discordgo.Session, i *discordgo.InteractionCreate) (* return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf(`For privacy reasons, this bot does not track user timezones. Please specify a specific IANA timezone rather than "%s".`, tz), }, }, false, nil @@ -322,7 +322,7 @@ func handleTZSubCmdInfo(s *discordgo.Session, i *discordgo.InteractionCreate) (* return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf(`"%s" is not a valid [IANA Timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).`, tz), }, }, false, nil @@ -443,7 +443,7 @@ func handleTZSubCmdServerClock(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: "You must run this command from a server where you have the Manage Channels permission.", }, }, false, nil @@ -459,7 +459,7 @@ func handleTZSubCmdServerClock(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf("This server already has a clock. To replace it, delete the <#%s> channel and re-issue this command.", clock.ChannelID), }, }, false, nil @@ -491,7 +491,7 @@ func handleTZSubCmdServerClock(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf("The following time zones are not valid: `%v`", invalidTZs), }, }, false, nil @@ -531,7 +531,7 @@ func handleTZSubCmdServerClock(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf("There was an error persisting your server clock. Please delete the %s channel if it was created, and reissue the command.", tzChan.Name), }, }, false, nil @@ -540,7 +540,7 @@ func handleTZSubCmdServerClock(s *discordgo.Session, i *discordgo.InteractionCre return &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ - Flags: InteractionResponseFlagEphemeral, + Flags: discordgo.MessageFlagsEphemeral, Content: fmt.Sprintf("Your server clock has been created! Check it out at %s. You may want to pin the clock message in that channel, or make it read-only.", tzChan.Mention()), }, }, false, nil