added short command for get but needs some restructuring
This commit is contained in:
		| @@ -1,8 +1,6 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/bwmarrin/discordgo" | ||||
| ) | ||||
|  | ||||
| @@ -28,9 +26,22 @@ var tag_command Command = Command{ | ||||
| 		}, | ||||
| 	}} | ||||
|  | ||||
| func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||||
| 	switch i.ApplicationCommandData().Options[0].Name { | ||||
| 	case "get": | ||||
| 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) | ||||
| @@ -42,17 +53,24 @@ func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.Intera | ||||
| 		}) | ||||
| 	} | ||||
| 	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, | ||||
| 					Content: option.Value.(string), | ||||
| 				}, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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]) | ||||
| } | ||||
|   | ||||
							
								
								
									
										6
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								main.go
									
									
									
									
									
								
							| @@ -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) | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user