From 328d2594ea5bccd5649aa0fbbaa01acf56612041 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 17 Mar 2024 13:31:07 +0100 Subject: [PATCH] fixed /form help crashing the bot --- cmd_form.go | 10 +++++++--- log2webhook/log2webhook.go | 2 +- tool.go | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd_form.go b/cmd_form.go index 7c26776..9dba00a 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "os" "strings" "github.com/bwmarrin/discordgo" @@ -77,9 +76,13 @@ var cmd_form Command = Command{ Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { switch i.ApplicationCommandData().Options[0].Name { case "help": - fileData, _ = os.ReadFile("./form_templates/form_demo.json") + fileData, err := formTemplates.ReadFile("form_templates/form_demo.json") + if err != nil { + logrus.Error(err) + return + } fileReader := bytes.NewReader(fileData) - err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "NOT SUPPORTED YET!(use `/form add` instead)\n\nGet 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.", @@ -177,6 +180,7 @@ var cmd_form Command = Command{ }) if err != nil { logrus.Error(err) + return } addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, options.Options[0].ChannelValue(s).ID, overwriteTitle, acceptChannelID, modsCanComment) err = respond(i.Interaction, "Successfully added form button!", true) diff --git a/log2webhook/log2webhook.go b/log2webhook/log2webhook.go index a04f65e..0447e16 100644 --- a/log2webhook/log2webhook.go +++ b/log2webhook/log2webhook.go @@ -51,7 +51,7 @@ func webhook(p []byte) { var logJson Log json.Unmarshal(p, &logJson) var color string = "36314" - if logJson.Level == "Error" { + if logJson.Level == "error" { color = "16739179" } m := Message{ diff --git a/tool.go b/tool.go index 9cb3b12..003f84b 100644 --- a/tool.go +++ b/tool.go @@ -57,11 +57,11 @@ func jsonStringShowModal(interaction *discordgo.Interaction, manageID string, fo }, }) } - if overwrite[0] != "" { + if overwrite != nil && overwrite[0] != "" { modal.Title = overwrite[0] } var err error - if components != nil { + if modal.Title != "" && components != nil { err = bot.InteractionRespond(interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseModal, Data: &discordgo.InteractionResponseData{