diff --git a/cmd_autojoinroles.go b/cmd_autojoinroles.go index 4315750..191ea79 100644 --- a/cmd_autojoinroles.go +++ b/cmd_autojoinroles.go @@ -53,13 +53,7 @@ var cmd_autojoinroles Command = Command{ } else if setAutoJoinRole(i.GuildID, option, role) { content = "Deleted auto join role for " + option + "s" } - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: content, - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, content) purgeUnusedAutoJoinRoles(i.GuildID) }, } diff --git a/cmd_autopublish.go b/cmd_autopublish.go index 33157aa..c295610 100644 --- a/cmd_autopublish.go +++ b/cmd_autopublish.go @@ -11,30 +11,12 @@ var cmd_autopublish Command = Command{ channel, _ := s.State.Channel(i.ChannelID) if channel.Type == discordgo.ChannelTypeGuildNews { if toggleAutoPublish(i.GuildID, i.ChannelID) { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Autopublishing is now disabled on <#" + i.ChannelID + ">", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Autopublishing is now disabled on <#"+i.ChannelID+">") } else { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Autopublishing is now enabled on <#" + i.ChannelID + ">", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Autopublishing is now enabled on <#"+i.ChannelID+">") } } else { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "This is not an announcement channel!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "This is not an announcement channel!") } }, } diff --git a/cmd_form.go b/cmd_form.go index 0870783..6912929 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -118,13 +118,7 @@ var cmd_form Command = Command{ }, }) case "custom": - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Feature not available yet use `/form add` instead", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Feature not available yet use `/form add` instead") case "add": var title, formID, overwriteTitle, acceptChannelID string var modsCanComment bool @@ -186,24 +180,12 @@ var cmd_form Command = Command{ }, }) addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, options.Options[0].ChannelValue(s).ID, overwriteTitle, acceptChannelID, modsCanComment) - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Successfully added form button!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Successfully added form button!") } }, ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) { if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")), - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:"))) } if i.Interaction.MessageComponentData().CustomID == "form_demo" { s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ @@ -247,13 +229,7 @@ var cmd_form Command = Command{ }, ModalIDs: getFormTypes(), ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "The form data would be send to a specified channel. 🤲", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "The form data would be send to a specified channel. 🤲") }, Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) { choices := []*discordgo.ApplicationCommandOptionChoice{ diff --git a/cmd_sticky.go b/cmd_sticky.go index 0ad1816..ac60c90 100644 --- a/cmd_sticky.go +++ b/cmd_sticky.go @@ -53,21 +53,9 @@ var cmd_sticky Command = Command{ if hasSticky(i.GuildID, i.ChannelID) { s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID)) removeSticky(i.GuildID, i.ChannelID) - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "The sticky message was removed from this channel!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "The sticky message was removed from this channel!") } else { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "This channel has no sticky message!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "This channel has no sticky message!") } } }, @@ -86,21 +74,9 @@ var cmd_sticky Command = Command{ log.Println(err) } if addSticky(i.GuildID, i.ChannelID, text, message.ID) { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Sticky message in this channel was updated!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Sticky message in this channel was updated!") } else { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Message sticked to the channel!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Message sticked to the channel!") } }, } diff --git a/cmd_tag.go b/cmd_tag.go index e5ca55f..b126b22 100644 --- a/cmd_tag.go +++ b/cmd_tag.go @@ -88,13 +88,7 @@ var cmd_tag Command = Command{ }) case "remove": removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue()) - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Tag removed!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Tag removed!") } }, ModalIDs: []string{"tag_add_modal"}, @@ -102,13 +96,7 @@ var cmd_tag Command = Command{ tagName := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value addTag(i.GuildID, tagName, tagContent) - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Tag \"" + tagName + "\" added!", - Flags: discordgo.MessageFlagsEphemeral, - }, - }) + respondEphemeral(s, i.Interaction, "Tag \""+tagName+"\" added!") }, Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) { AutocompleteTag(s, i) diff --git a/tool.go b/tool.go index e3a082c..20ea301 100644 --- a/tool.go +++ b/tool.go @@ -65,3 +65,13 @@ func hexToDecimal(hexColor string) int { } return int(decimal) } + +func respondEphemeral(s *discordgo.Session, interaction *discordgo.Interaction, content string) { + s.InteractionRespond(interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: content, + Flags: discordgo.MessageFlagsEphemeral, + }, + }) +}