diff --git a/cmd_tag.go b/cmd_tag.go index 576d3ca..1ea9db3 100644 --- a/cmd_tag.go +++ b/cmd_tag.go @@ -51,43 +51,7 @@ var cmd_tag Command = Command{ case "get": GetTagCommand(i, i.ApplicationCommandData().Options[0].Options[0]) case "add": - err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseModal, - Data: &discordgo.InteractionResponseData{ - CustomID: "tag_add_modal" + i.Interaction.Member.User.ID, - Title: "Add a custom tag command", - Components: []discordgo.MessageComponent{ - discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.TextInput{ - CustomID: "tag_add_modal_name", - Label: "Name", - Style: discordgo.TextInputShort, - Required: true, - MaxLength: 20, - Value: "", - }, - }, - }, - discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.TextInput{ - CustomID: "tag_add_modal_content", - Label: "Content", - Placeholder: "Content that gets returned when the tag will be run", - Style: discordgo.TextInputParagraph, - Required: true, - MaxLength: 2000, - Value: "", - }, - }, - }, - }, - }, - }) - if err != nil { - logrus.Error(err) - } + AddTagCommand(i, "") case "remove": removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue()) err := respond(i.Interaction, "Tag removed!", true) @@ -133,6 +97,17 @@ var cmd_tag_short Command = Command{ }, } +var context_tag Command = Command{ + Definition: discordgo.ApplicationCommand{ + Type: discordgo.MessageApplicationCommand, + Name: "Save as tag", + DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageServer), + }, + Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + AddTagCommand(i, i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content) + }, +} + func GetTagCommand(i *discordgo.InteractionCreate, option *discordgo.ApplicationCommandInteractionDataOption) { err := respond(i.Interaction, getTagContent(i.GuildID, option.Value.(string)), false) if err != nil { @@ -140,6 +115,46 @@ func GetTagCommand(i *discordgo.InteractionCreate, option *discordgo.Application } } +func AddTagCommand(i *discordgo.InteractionCreate, prevalue string) { + err := bot.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseModal, + Data: &discordgo.InteractionResponseData{ + CustomID: "tag_add_modal" + i.Interaction.Member.User.ID, + Title: "Add a custom tag command", + Components: []discordgo.MessageComponent{ + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.TextInput{ + CustomID: "tag_add_modal_name", + Label: "Name", + Style: discordgo.TextInputShort, + Required: true, + MaxLength: 20, + Value: "", + }, + }, + }, + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.TextInput{ + CustomID: "tag_add_modal_content", + Label: "Content", + Placeholder: "Content that gets returned when the tag will be run", + Style: discordgo.TextInputParagraph, + Required: true, + MaxLength: 2000, + Value: prevalue, + }, + }, + }, + }, + }, + }) + if err != nil { + logrus.Error(err) + } +} + func AutocompleteTag(i *discordgo.InteractionCreate) { err := bot.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionApplicationCommandAutocompleteResult, diff --git a/handlers.go b/handlers.go index 252afc0..940172d 100644 --- a/handlers.go +++ b/handlers.go @@ -21,7 +21,7 @@ type Command struct { DynamicModalIDs func() []string } -var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky} +var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky, context_tag} func ready(s *discordgo.Session, event *discordgo.Ready) { logrus.Info("Starting up...")