small fixes

This commit is contained in:
2024-03-11 14:53:23 +01:00
parent 357557c023
commit 0adf6504ad
7 changed files with 29 additions and 37 deletions

View File

@@ -2,7 +2,7 @@ package main
import (
"bytes"
"fmt"
"log"
"os"
"strings"
@@ -28,24 +28,12 @@ var cmd_form Command = Command{
Name: "custom",
Description: "Create a new custom form right inside Discord",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "title",
Description: "The title inside the form window",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionAttachment,
Name: "json",
Description: "Your edited form file",
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 fields []*discordgo.MessageEmbedField
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 {
fmt.Print(component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput))
var input *discordgo.TextInput = component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput)
fields = append(fields, &discordgo.MessageEmbedField{
Name: modal.Form[index].Label,
@@ -211,12 +202,27 @@ var cmd_form Command = Command{
})
}
if result.AcceptChannelID == "" {
s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
channel, _ := s.Channel(i.ChannelID)
_, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
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 {
respond(i.Interaction, "The form data would be send to a specified channel. 🤲", true)
}

View File

@@ -18,7 +18,7 @@
"value": "We already have some input here",
"required": false,
"min_length": 0,
"max_length": 2000
"max_length": 1024
}
]
}

View File

@@ -12,7 +12,7 @@
"label": "Text",
"is_paragraph": true,
"required": true,
"max_length": 2000
"max_length": 1024
}
]
}

View File

@@ -14,7 +14,7 @@
"is_paragraph": true,
"placeholder": "Fill in for what you need help or have issues with and a moderator will reply.",
"required": true,
"max_length": 2000
"max_length": 1024
}
]
}

View File

@@ -5,7 +5,7 @@
{
"label": "URL",
"is_paragraph": false,
"placeholder": "https://example.com",
"placeholder": "https://",
"value": "",
"required": true,
"min_length": 0,

View File

@@ -278,13 +278,6 @@ func getFormOverwriteTitle(formManageID string) string {
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 {
var role_exists bool
var autojoinroles_exists bool

11
tool.go
View File

@@ -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() {
for _, message := range getAllSavedMessages() {
if checkMessageNotExists(message.ChannelID, message.ID) {
_, err := bot.ChannelMessage(message.ChannelID, message.ID)
if err != nil {
tryDeleteUnusedMessage(message.ID)
}
}