added short command for get but needs some restructuring

This commit is contained in:
2024-02-15 14:31:22 +01:00
parent a3d894cfb5
commit 5a2e182453
3 changed files with 46 additions and 26 deletions

View File

@@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
@@ -28,31 +26,51 @@ var tag_command Command = Command{
},
}}
func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name {
case "get":
if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
commandUseCount++
choices := generateDynamicChoices(commandUseCount)
var short_get_tag_command Command = Command{
Definition: discordgo.ApplicationCommand{
Name: "g",
Description: "A short command to get presaved messages.",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "tag",
Description: "Your predefined tag for the saved message",
Required: true,
Autocomplete: true,
},
},
}}
func GetTagCommand(s *discordgo.Session, i *discordgo.InteractionCreate, option *discordgo.ApplicationCommandInteractionDataOption) {
if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
commandUseCount++
choices := generateDynamicChoices(commandUseCount)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
Data: &discordgo.InteractionResponseData{
Choices: choices,
},
})
}
if i.Type == discordgo.InteractionApplicationCommand {
if option.Name == "tag" {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Choices: choices,
Content: option.Value.(string),
},
})
}
if i.Type == discordgo.InteractionApplicationCommand {
option := i.ApplicationCommandData().Options[0].Options[0]
if option.Name == "tag" {
value := option.Value.(string)
response := fmt.Sprintf("You provided the tag: %s", value)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: response,
},
})
}
}
}
}
func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name {
case "get":
GetTagCommand(s, i, i.ApplicationCommandData().Options[0].Options[0])
}
}
func (short_get_tag_command Command) tInteraction(s *discordgo.Session, i *discordgo.InteractionCreate) {
GetTagCommand(s, i, i.ApplicationCommandData().Options[0])
}

View File

@@ -46,6 +46,7 @@ func main() {
func ready(s *discordgo.Session, event *discordgo.Ready) {
commands := []*discordgo.ApplicationCommand{
&tag_command.Definition,
&short_get_tag_command.Definition,
}
for _, guild := range event.Guilds {
@@ -73,8 +74,11 @@ func generateDynamicChoices(count int) []*discordgo.ApplicationCommandOptionChoi
var commandUseCount int
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
if i.ApplicationCommandData().Name == "tag" {
switch i.ApplicationCommandData().Name {
case "tag":
tag_command.Interaction(s, i)
case "g":
short_get_tag_command.tInteraction(s, i)
}
}

View File

@@ -62,8 +62,6 @@ func debugTags() {
}
addTag(tags, "new_command", "a new command description")
removeTag(tags, "test_command")
modifyTag(tags, "another_test_command", "updated command description")
err = writeTags("data.json", tags)
if err != nil {