continued forms
This commit is contained in:
57
cmd_form.go
57
cmd_form.go
@@ -71,7 +71,7 @@ var form_command Command = Command{
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionChannel,
|
||||
Name: "accept_channel_id",
|
||||
Name: "accept_channel",
|
||||
Description: "Channel for results that need to be accepted by a moderator before sending it to the result channel",
|
||||
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
|
||||
},
|
||||
@@ -92,7 +92,7 @@ var form_command Command = Command{
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Get the example file edit it (make sure to have a unique \"form_id\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.",
|
||||
Content: "Get the example file edit it (make sure to have a unique \"form_type\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
Files: []*discordgo.File{
|
||||
{
|
||||
@@ -130,39 +130,40 @@ var form_command Command = Command{
|
||||
var modsCanComment bool
|
||||
options := i.ApplicationCommandData().Options[0]
|
||||
|
||||
if len(options.Options) <= 1 {
|
||||
formID = "template_general"
|
||||
} else {
|
||||
for _, opt := range options.Options {
|
||||
switch opt.Name {
|
||||
case "type":
|
||||
formID = options.Options[1].StringValue()
|
||||
case "title":
|
||||
overwriteTitle = opt.StringValue()
|
||||
title = overwriteTitle
|
||||
case "accept_channel":
|
||||
acceptChannelID = opt.ChannelValue(s).ID
|
||||
case "mods_can_comment":
|
||||
modsCanComment = opt.BoolValue()
|
||||
}
|
||||
switch formID {
|
||||
case "template_feedback":
|
||||
title = "Submit Feedback"
|
||||
case "template_ticket":
|
||||
title = "Make a new ticket"
|
||||
case "template_url":
|
||||
title = "Add your URL"
|
||||
case "template_general":
|
||||
title = "Form"
|
||||
}
|
||||
if formID == "" {
|
||||
formID = "template_general"
|
||||
}
|
||||
|
||||
formTitles := map[string]string{
|
||||
"template_feedback": "Submit Feedback",
|
||||
"template_ticket": "Make a new ticket",
|
||||
"template_url": "Add your URL",
|
||||
"template_general": "Form",
|
||||
}
|
||||
if val, ok := formTitles[formID]; ok {
|
||||
title = val
|
||||
}
|
||||
|
||||
var exists bool = true
|
||||
var formManageID uuid.UUID = uuid.New()
|
||||
for exists {
|
||||
formManageID = uuid.New()
|
||||
exists = getFormManageIdExists(i.GuildID, formManageID)
|
||||
exists = getFormManageIdExists(formManageID)
|
||||
}
|
||||
|
||||
if !(len(options.Options) <= 2) {
|
||||
overwriteTitle = options.Options[2].StringValue()
|
||||
title = overwriteTitle
|
||||
}
|
||||
if !(len(options.Options) <= 3) {
|
||||
acceptChannelID = options.Options[3].ChannelValue(s).ID
|
||||
}
|
||||
if !(len(options.Options) <= 4) {
|
||||
modsCanComment = options.Options[4].BoolValue()
|
||||
}
|
||||
message, _ := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
|
||||
Embed: &discordgo.MessageEmbed{
|
||||
Color: hexToDecimal(color["primary"]),
|
||||
@@ -199,7 +200,7 @@ var form_command Command = Command{
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: i.Interaction.MessageComponentData().CustomID,
|
||||
Content: getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")),
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
@@ -244,7 +245,7 @@ var form_command Command = Command{
|
||||
})
|
||||
}
|
||||
},
|
||||
ModalIDs: getFormIDs(),
|
||||
ModalIDs: getFormTypes(),
|
||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
@@ -282,7 +283,7 @@ var form_command Command = Command{
|
||||
},
|
||||
}
|
||||
|
||||
func getFormIDs() []string {
|
||||
func getFormTypes() []string {
|
||||
//needs custom IDs from databank
|
||||
return []string{"form_demo", "template_ticket", "template_url", "template_general"}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"form_id": "form_demo",
|
||||
"form_type": "form_demo",
|
||||
"title": "Demo form",
|
||||
"form": [
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"form_id": "template_general",
|
||||
"form_type": "template_general",
|
||||
"title": "Form",
|
||||
"form": [
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"form_id": "template_ticket",
|
||||
"form_type": "template_ticket",
|
||||
"title": "Submit your Ticket",
|
||||
"mods_can_comment": true,
|
||||
"form": [
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"form_id": "template_url",
|
||||
"form_type": "template_url",
|
||||
"title": "Submit URL",
|
||||
"form": [
|
||||
{
|
||||
|
@@ -22,15 +22,15 @@ func initTables() {
|
||||
PRIMARY KEY (channel_id, guild_id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS custom_forms (
|
||||
form_id TEXT NOT NULL,
|
||||
form_type TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
json JSON NOT NULL,
|
||||
guild_id TEXT NOT NULL,
|
||||
PRIMARY KEY (form_id, guild_id)
|
||||
PRIMARY KEY (form_type, guild_id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS form_buttons (
|
||||
CREATE TABLE IF NOT EXISTS form_manage (
|
||||
form_manage_id TEXT NOT NULL,
|
||||
form_id TEXT NOT NULL,
|
||||
form_type TEXT NOT NULL,
|
||||
overwrite_title TEXT,
|
||||
message_id TEXT NOT NULL,
|
||||
channel_id TEXT NOT NULL,
|
||||
@@ -38,7 +38,7 @@ func initTables() {
|
||||
result_channel_id TEXT NOT NULL,
|
||||
accept_channel_id TEXT,
|
||||
mods_can_comment BOOL,
|
||||
PRIMARY KEY (form_manage_id, form_id)
|
||||
PRIMARY KEY (form_manage_id, form_type)
|
||||
);
|
||||
`
|
||||
|
||||
@@ -177,17 +177,17 @@ func removeSticky(guildID string, channelID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func getFormManageIdExists(guildID string, id uuid.UUID) bool {
|
||||
func getFormManageIdExists(id uuid.UUID) bool {
|
||||
var exists bool
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM form_buttons WHERE form_manage_id = $1)", id).Scan(&exists)
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM form_manage WHERE form_manage_id = $1)", id).Scan(&exists)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return exists
|
||||
}
|
||||
|
||||
func addFormButton(guildID string, channelID string, messageID string, formManageID string, formID string, resultChannelID string, overwriteTitle string, acceptChannelID string, modsCanComment bool) {
|
||||
_, err := db.Exec("INSERT INTO form_buttons (guild_id, form_manage_id, channel_id, message_id, form_id, result_channel_id, overwrite_title, accept_channel_id, mods_can_comment) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", guildID, formManageID, channelID, messageID, formID, resultChannelID, overwriteTitle, acceptChannelID, modsCanComment)
|
||||
func addFormButton(guildID string, channelID string, messageID string, formManageID string, formType string, resultChannelID string, overwriteTitle string, acceptChannelID string, modsCanComment bool) {
|
||||
_, err := db.Exec("INSERT INTO form_manage (guild_id, form_manage_id, channel_id, message_id, form_type, result_channel_id, overwrite_title, accept_channel_id, mods_can_comment) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", guildID, formManageID, channelID, messageID, formType, resultChannelID, overwriteTitle, acceptChannelID, modsCanComment)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func getFormManageIDs() []string {
|
||||
return nil
|
||||
}
|
||||
var IDs []string
|
||||
rows, err := db.Query("SELECT form_manage_id FROM form_buttons")
|
||||
rows, err := db.Query("SELECT form_manage_id FROM form_manage")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
@@ -220,3 +220,12 @@ func getFormManageIDs() []string {
|
||||
}
|
||||
return IDs
|
||||
}
|
||||
|
||||
func getFormType(formManageID string) string {
|
||||
var formType string
|
||||
err := db.QueryRow("SELECT form_type FROM form_manage WHERE form_manage_id = $1", formManageID).Scan(&formType)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return formType
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ type Command struct {
|
||||
var commands []Command = []Command{form_command, tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command}
|
||||
|
||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||
fmt.Print("\nStarting up... (May take longer when Discord rate limits the bot)")
|
||||
fmt.Print("\nStarting up...")
|
||||
removeOldCommandFromAllGuilds(s)
|
||||
var existingCommandNames []string
|
||||
for _, guild := range event.Guilds {
|
||||
|
Reference in New Issue
Block a user