small fixes
This commit is contained in:
40
cmd_form.go
40
cmd_form.go
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -28,24 +28,12 @@ var cmd_form Command = Command{
|
|||||||
Name: "custom",
|
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{
|
||||||
{
|
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
|
||||||
Name: "title",
|
|
||||||
Description: "The title inside the form window",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionAttachment,
|
Type: discordgo.ApplicationCommandOptionAttachment,
|
||||||
Name: "json",
|
Name: "json",
|
||||||
Description: "Your edited form file",
|
Description: "Your edited form file",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Type: discordgo.ApplicationCommandOptionChannel,
|
|
||||||
Name: "results_channel",
|
|
||||||
Description: "The channel where the form results should be posted",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -201,8 +189,11 @@ var cmd_form Command = Command{
|
|||||||
var result FormResult = getFormResultValues(form_manage_id)
|
var result FormResult = getFormResultValues(form_manage_id)
|
||||||
var fields []*discordgo.MessageEmbedField
|
var fields []*discordgo.MessageEmbedField
|
||||||
var modal ModalJson = getModalByFormID(getFormType(form_manage_id))
|
var modal ModalJson = getModalByFormID(getFormType(form_manage_id))
|
||||||
|
var overwrite_title string = getFormOverwriteTitle(form_manage_id)
|
||||||
|
if overwrite_title != "" {
|
||||||
|
modal.Title = overwrite_title
|
||||||
|
}
|
||||||
for index, component := range i.ModalSubmitData().Components {
|
for index, component := range i.ModalSubmitData().Components {
|
||||||
fmt.Print(component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput))
|
|
||||||
var input *discordgo.TextInput = component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput)
|
var input *discordgo.TextInput = component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput)
|
||||||
fields = append(fields, &discordgo.MessageEmbedField{
|
fields = append(fields, &discordgo.MessageEmbedField{
|
||||||
Name: modal.Form[index].Label,
|
Name: modal.Form[index].Label,
|
||||||
@@ -211,12 +202,27 @@ var cmd_form Command = Command{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if result.AcceptChannelID == "" {
|
if result.AcceptChannelID == "" {
|
||||||
s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
|
channel, _ := s.Channel(i.ChannelID)
|
||||||
|
_, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
|
||||||
Embed: &discordgo.MessageEmbed{
|
Embed: &discordgo.MessageEmbed{
|
||||||
Fields: fields,
|
Author: &discordgo.MessageEmbedAuthor{
|
||||||
|
Name: i.Member.User.Username,
|
||||||
|
IconURL: i.Member.AvatarURL("256"),
|
||||||
|
},
|
||||||
|
Title: "\"" + modal.Title + "\"",
|
||||||
|
Color: hexToDecimal(color["primary"]),
|
||||||
|
Description: "This is the submitted result",
|
||||||
|
Fields: fields,
|
||||||
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
|
Text: "From #" + channel.Name,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
respond(i.Interaction, "Submited!", true)
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
respond(i.Interaction, "Submited!", true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
respond(i.Interaction, "The form data would be send to a specified channel. 🤲", true)
|
respond(i.Interaction, "The form data would be send to a specified channel. 🤲", true)
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
"value": "We already have some input here",
|
"value": "We already have some input here",
|
||||||
"required": false,
|
"required": false,
|
||||||
"min_length": 0,
|
"min_length": 0,
|
||||||
"max_length": 2000
|
"max_length": 1024
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
"label": "Text",
|
"label": "Text",
|
||||||
"is_paragraph": true,
|
"is_paragraph": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"max_length": 2000
|
"max_length": 1024
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
"is_paragraph": true,
|
"is_paragraph": true,
|
||||||
"placeholder": "Fill in for what you need help or have issues with and a moderator will reply.",
|
"placeholder": "Fill in for what you need help or have issues with and a moderator will reply.",
|
||||||
"required": true,
|
"required": true,
|
||||||
"max_length": 2000
|
"max_length": 1024
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"label": "URL",
|
"label": "URL",
|
||||||
"is_paragraph": false,
|
"is_paragraph": false,
|
||||||
"placeholder": "https://example.com",
|
"placeholder": "https://",
|
||||||
"value": "",
|
"value": "",
|
||||||
"required": true,
|
"required": true,
|
||||||
"min_length": 0,
|
"min_length": 0,
|
||||||
|
@@ -278,13 +278,6 @@ func getFormOverwriteTitle(formManageID string) string {
|
|||||||
return overwriteTitle
|
return overwriteTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeForm(formManageID string) {
|
|
||||||
_, err := db.Exec("DELETE FROM form_manage WHERE form_manage_id = $1", formManageID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setAutoJoinRole(guildID string, option string, roleID string) bool {
|
func setAutoJoinRole(guildID string, option string, roleID string) bool {
|
||||||
var role_exists bool
|
var role_exists bool
|
||||||
var autojoinroles_exists bool
|
var autojoinroles_exists bool
|
||||||
|
11
tool.go
11
tool.go
@@ -158,17 +158,10 @@ func respondEmbed(interaction *discordgo.Interaction, embed discordgo.MessageEmb
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMessageNotExists(channelID, messageID string) bool {
|
|
||||||
_, err := bot.ChannelMessage(channelID, messageID)
|
|
||||||
if err != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func findAndDeleteUnusedMessages() {
|
func findAndDeleteUnusedMessages() {
|
||||||
for _, message := range getAllSavedMessages() {
|
for _, message := range getAllSavedMessages() {
|
||||||
if checkMessageNotExists(message.ChannelID, message.ID) {
|
_, err := bot.ChannelMessage(message.ChannelID, message.ID)
|
||||||
|
if err != nil {
|
||||||
tryDeleteUnusedMessage(message.ID)
|
tryDeleteUnusedMessage(message.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user