started adding form functionality
This commit is contained in:
84
cmd_form.go
84
cmd_form.go
@@ -21,7 +21,7 @@ var form_command Command = Command{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||||
Name: "create",
|
Name: "custom",
|
||||||
Description: "Create a new custom form right inside Discord",
|
Description: "Create a new custom form right inside Discord",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
{
|
{
|
||||||
@@ -44,6 +44,19 @@ var form_command Command = Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||||
|
Name: "add",
|
||||||
|
Description: "Adds existing forms to this channel",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
|
Name: "type",
|
||||||
|
Description: "Which type of form you want to add",
|
||||||
|
Autocomplete: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
@@ -79,22 +92,49 @@ var form_command Command = Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
case "create":
|
case "custom":
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Content: "Placeholder",
|
Content: "Feature not available yet use `/form add` instead",
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
case "add":
|
||||||
|
var optionName string = i.ApplicationCommandData().Options[0].Options[0].Name
|
||||||
|
var optionValue string = i.ApplicationCommandData().Options[0].Options[0].StringValue()
|
||||||
|
if optionName == "" { // handling optional empty
|
||||||
|
optionName = "General"
|
||||||
|
}
|
||||||
|
s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
|
||||||
|
Embed: &discordgo.MessageEmbed{
|
||||||
|
Color: hexToDecimal(color["primary"]),
|
||||||
|
Title: optionName,
|
||||||
|
Description: "Press the bottom button to open a form popup.",
|
||||||
|
},
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.Button{
|
||||||
|
CustomID: "form:" + optionValue,
|
||||||
|
Label: "Submit",
|
||||||
|
Emoji: discordgo.ComponentEmoji{
|
||||||
|
Name: "📥",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ComponentIDs: []string{"form_demo"},
|
ComponentIDs: getFormIDs(),
|
||||||
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseModal,
|
Type: discordgo.InteractionResponseModal,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
CustomID: "form_demo_modal" + i.Interaction.Member.User.ID,
|
CustomID: "form_demo" + i.Interaction.Member.User.ID,
|
||||||
Title: "Demo form",
|
Title: "Demo form",
|
||||||
Components: []discordgo.MessageComponent{
|
Components: []discordgo.MessageComponent{
|
||||||
discordgo.ActionsRow{
|
discordgo.ActionsRow{
|
||||||
@@ -128,8 +168,9 @@ var form_command Command = Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ModalID: "form_demo_modal",
|
ModalIDs: getFormIDs(),
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
@@ -139,4 +180,35 @@ var form_command Command = Command{
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
choices := []*discordgo.ApplicationCommandOptionChoice{
|
||||||
|
{
|
||||||
|
Name: "Feedback",
|
||||||
|
Value: "template_feedback",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Support Ticket",
|
||||||
|
Value: "template_ticket",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Submit URL",
|
||||||
|
Value: "template_url",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "General",
|
||||||
|
Value: "template_general",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Choices: choices,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFormIDs() []string {
|
||||||
|
//needs databank support
|
||||||
|
return []string{"form_demo"}
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ var sticky_command Command = Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ModalID: "sticky_modal",
|
ModalIDs: []string{"sticky_modal"},
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
text := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
text := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
||||||
message, err := s.ChannelMessageSendEmbed(i.ChannelID, &discordgo.MessageEmbed{
|
message, err := s.ChannelMessageSendEmbed(i.ChannelID, &discordgo.MessageEmbed{
|
||||||
|
@@ -97,7 +97,7 @@ var tag_command Command = Command{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ModalID: "tag_add_modal",
|
ModalIDs: []string{"tag_add_modal"},
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
tagName := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
tagName := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
||||||
tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
||||||
|
@@ -21,6 +21,20 @@ func initTables() {
|
|||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
PRIMARY KEY (channel_id, guild_id)
|
PRIMARY KEY (channel_id, guild_id)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS forms (
|
||||||
|
form_id TEXT NOT NULL,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
json TEXT NOT NULL,
|
||||||
|
guild_id TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (form_id, guild_id)
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS formbuttons (
|
||||||
|
form_id TEXT NOT NULL,
|
||||||
|
message_id TEXT NOT NULL,
|
||||||
|
channel_id TEXT NOT NULL,
|
||||||
|
guild_id TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (form_id, guild_id, channel_id)
|
||||||
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
_, err := db.Exec(createTableQuery)
|
_, err := db.Exec(createTableQuery)
|
||||||
|
@@ -16,7 +16,7 @@ type Command struct {
|
|||||||
ComponentIDs []string
|
ComponentIDs []string
|
||||||
Autocomplete func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
Autocomplete func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
||||||
ModalSubmit func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
ModalSubmit func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
||||||
ModalID string
|
ModalIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var commands []Command = []Command{tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command, form_command}
|
var commands []Command = []Command{tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command, form_command}
|
||||||
@@ -60,9 +60,17 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||||||
command.Autocomplete(s, i)
|
command.Autocomplete(s, i)
|
||||||
}
|
}
|
||||||
case discordgo.InteractionModalSubmit:
|
case discordgo.InteractionModalSubmit:
|
||||||
if command.ModalSubmit != nil && strings.HasPrefix(i.ModalSubmitData().CustomID, command.ModalID) {
|
var hasID bool = false
|
||||||
|
if command.ModalSubmit != nil {
|
||||||
|
for _, modalID := range command.ModalIDs {
|
||||||
|
if strings.HasPrefix(i.ModalSubmitData().CustomID, modalID) {
|
||||||
|
hasID = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasID {
|
||||||
command.ModalSubmit(s, i)
|
command.ModalSubmit(s, i)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case discordgo.InteractionMessageComponent:
|
case discordgo.InteractionMessageComponent:
|
||||||
if command.ComponentInteract != nil && slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) {
|
if command.ComponentInteract != nil && slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) {
|
||||||
command.ComponentInteract(s, i)
|
command.ComponentInteract(s, i)
|
||||||
|
Reference in New Issue
Block a user