From f6b843d1a72fbab978467a132d5d624b9e12609f Mon Sep 17 00:00:00 2001 From: vaporvee Date: Tue, 26 Mar 2024 23:13:06 +0100 Subject: [PATCH] added full ticket functionality to forms --- cmd_form.go | 381 ++++++++++++++++++++++++++++++++----- handlers.go | 24 ++- log2webhook/log2webhook.go | 9 +- manage_data.go | 133 ++++++++----- tool.go | 19 ++ 5 files changed, 462 insertions(+), 104 deletions(-) diff --git a/cmd_form.go b/cmd_form.go index 3a449c3..62ebdcd 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "strings" "github.com/bwmarrin/discordgo" @@ -43,7 +44,11 @@ var cmd_form Command = Command{ Name: "result_channel", Description: "Where the form results should appear", ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText}, - Required: true, + }, + { + Type: discordgo.ApplicationCommandOptionMentionable, + Name: "moderator", + Description: "Who can interact with moderating buttons.", }, { Type: discordgo.ApplicationCommandOptionString, @@ -56,17 +61,17 @@ var cmd_form Command = Command{ Name: "title", Description: "The title the form should have", }, - /*{ + { Type: discordgo.ApplicationCommandOptionChannel, - Name: "accept_channel", + Name: "approve_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}, }, { Type: discordgo.ApplicationCommandOptionBoolean, - Name: "mods_can_comment", + Name: "mods_can_answer", Description: "Moderators can open a new channel on the form result, which then pings the user who submitted it", - },*/ + }, }, }, }, @@ -118,19 +123,30 @@ var cmd_form Command = Command{ } case "add": var title, formID, overwriteTitle, acceptChannelID string - var modsCanComment bool - options := i.ApplicationCommandData().Options[0] - for _, opt := range options.Options { - switch opt.Name { - case "type": - formID = opt.StringValue() - case "title": - overwriteTitle = opt.StringValue() - title = overwriteTitle - case "accept_channel": - acceptChannelID = opt.ChannelValue(s).ID - case "mods_can_comment": - modsCanComment = opt.BoolValue() + var modsCanAnswer bool + var resultChannelID string + moderator := i.Member.User.ID + if i.ApplicationCommandData().Options != nil { + options := i.ApplicationCommandData().Options[0] + for _, opt := range options.Options { + switch opt.Name { + case "result_channel": + resultChannelID = opt.ChannelValue(s).ID + case "type": + formID = opt.StringValue() + case "title": + overwriteTitle = opt.StringValue() + title = overwriteTitle + case "approve_channel": + acceptChannelID = opt.ChannelValue(s).ID + case "mods_can_answer": + modsCanAnswer = opt.BoolValue() + case "moderator": + moderator = opt.RoleValue(s, i.GuildID).ID + if moderator == "" { + moderator = opt.UserValue(s).ID + } + } } } if formID == "" { @@ -180,23 +196,65 @@ var cmd_form Command = Command{ logrus.Error(err) return } - addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, options.Options[0].ChannelValue(s).ID, overwriteTitle, acceptChannelID, modsCanComment) + var category string + if modsCanAnswer { + c, err := s.GuildChannelCreate(i.GuildID, title+" mod answers", discordgo.ChannelTypeGuildCategory) + if err != nil { + logrus.Error(err) + } + category = c.ID + } + addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, resultChannelID, overwriteTitle, acceptChannelID, category, moderator) err = respond(i.Interaction, "Successfully added form button!", true) if err != nil { logrus.Error(err) } } }, + DynamicComponentIDs: func() []string { return getFormButtonIDs() }, + DynamicModalIDs: func() []string { return getFormButtonIDs() }, ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") { - var formManageID string = strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:") - jsonStringShowModal(i.Interaction, i.Interaction.MessageComponentData().CustomID, getFormType(formManageID), getFormOverwriteTitle(formManageID)) - } else if i.Interaction.MessageComponentData().CustomID == "form_demo" { - jsonStringShowModal(i.Interaction, "form_demo", "form_demo") + if strings.ContainsAny(i.MessageComponentData().CustomID, ";") { + var form_manage_id string = strings.TrimPrefix(strings.Split(i.MessageComponentData().CustomID, ";")[0], "form:") + switch strings.Split(i.MessageComponentData().CustomID, ";")[1] { + case "decline": + err := s.ChannelMessageDelete(i.ChannelID, i.Message.ID) + if err != nil { + logrus.Error(err) + } + respond(i.Interaction, "Submission declined!", true) + case "approve": + embed := i.Message.Embeds[0] + embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", i.Member.User.ID) + _, err := s.ChannelMessageSendComplex(getFormResultValues(form_manage_id).ResultChannelID, &discordgo.MessageSend{ + Embed: embed, + }) + if err != nil { + logrus.Error(err) + } + respond(i.Interaction, "Submission accepted!", true) + err = s.ChannelMessageDelete(i.ChannelID, i.Message.ID) + if err != nil { + logrus.Error(err) + } + + case "comment": + author := strings.TrimSuffix(strings.Split(i.Message.Embeds[0].Fields[len(i.Message.Embeds[0].Fields)-1].Value, "<@")[1], ">") + embed := i.Message.Embeds[0] + moderator := i.Member.User.ID + createFormComment(form_manage_id, author, moderator, "answer", embed, i) + } + } else { + if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") { + var formManageID string = strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:") + jsonStringShowModal(i.Interaction, i.Interaction.MessageComponentData().CustomID, getFormType(formManageID), getFormOverwriteTitle(formManageID)) + } else if i.Interaction.MessageComponentData().CustomID == "form_demo" { + jsonStringShowModal(i.Interaction, "form_demo", "form_demo") + } } }, ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - if i.ModalSubmitData().CustomID != "form_demo" { + if !strings.HasPrefix(i.ModalSubmitData().CustomID, "form_demo") { var form_manage_id string = strings.Split(i.ModalSubmitData().CustomID, ":")[1] var result FormResult = getFormResultValues(form_manage_id) var fields []*discordgo.MessageEmbedField @@ -213,10 +271,14 @@ var cmd_form Command = Command{ Inline: input.Style == discordgo.TextInputShort, }) } - if result.AcceptChannelID == "" { - channel, _ := s.Channel(i.ChannelID) - _, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{ - Embed: &discordgo.MessageEmbed{ + + channel, _ := s.Channel(i.ChannelID) + fields = append(fields, &discordgo.MessageEmbedField{ + Value: "From <#" + channel.ID + "> by <@" + i.Member.User.ID + ">", + }) + if result.ResultChannelID == "" { + if result.CommentCategoryID != "" { + createFormComment(form_manage_id, i.Member.User.ID, result.ModeratorID, "answer", &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: i.Member.User.Username, IconURL: i.Member.AvatarURL("256"), @@ -225,33 +287,122 @@ var cmd_form Command = Command{ Color: hexToDecimal(color["primary"]), Description: "This is the submitted result", Fields: fields, - Footer: &discordgo.MessageEmbedFooter{ - Text: "From #" + channel.Name, - }, - }, - }) - if err != nil { - logrus.Error(err) + }, i) } else { - err = respond(i.Interaction, "Submited!", true) - if err != nil { - logrus.Error(err) - } + respond(i.Interaction, "You need to provide either a `result_channel` or enable `mods_can_answer` to create a valid form.", true) } } else { - err := respond(i.Interaction, "The form data would be send to a specified channel. 🤲", true) - if err != nil { - logrus.Error(err) + if result.AcceptChannelID == "" { + var buttons []discordgo.MessageComponent + if result.CommentCategoryID != "" { + buttons = []discordgo.MessageComponent{ + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.Button{ + Style: discordgo.PrimaryButton, + Emoji: discordgo.ComponentEmoji{ + Name: "👥", + }, + Label: "Comment", + CustomID: "form:" + form_manage_id + ";comment", + }, + }, + }, + } + } + _, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{ + Embed: &discordgo.MessageEmbed{ + 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, + }, + Components: buttons, + }) + if err != nil { + logrus.Error(err) + } else { + err = respond(i.Interaction, "Submited!", true) + if err != nil { + logrus.Error(err) + } + } + } else { + var buttons []discordgo.MessageComponent + if result.CommentCategoryID != "" { + buttons = []discordgo.MessageComponent{ + discordgo.Button{ + Style: discordgo.PrimaryButton, + Emoji: discordgo.ComponentEmoji{ + Name: "👥", + }, + Label: "Comment", + CustomID: "form:" + form_manage_id + ";comment", + }, + } + } + buttons = append(buttons, + discordgo.Button{ + Style: discordgo.DangerButton, + Emoji: discordgo.ComponentEmoji{ + Name: "🛑", + }, + Label: "Decline", + CustomID: "form:" + form_manage_id + ";decline", + }, + discordgo.Button{ + Style: discordgo.SuccessButton, + Emoji: discordgo.ComponentEmoji{ + Name: "🎉", + }, + Label: "Approve", + CustomID: "form:" + form_manage_id + ";approve", + }) + _, err := s.ChannelMessageSendComplex(result.AcceptChannelID, &discordgo.MessageSend{ + Embed: &discordgo.MessageEmbed{ + Author: &discordgo.MessageEmbedAuthor{ + Name: i.Member.User.Username, + IconURL: i.Member.AvatarURL("256"), + }, + Title: "\"" + modal.Title + "\"", + Color: hexToDecimal(color["primary"]), + Description: "**This submission needs approval.**", + Fields: fields, + }, + Components: []discordgo.MessageComponent{ + discordgo.ActionsRow{ + Components: buttons, + }, + }}, + ) + if err != nil { + logrus.Error(err) + } else { + err = respond(i.Interaction, "Submited!", true) + if err != nil { + logrus.Error(err) + } + } } } + } else { + err := respond(i.Interaction, "The results would be submited...", true) + if err != nil { + logrus.Error(err) + } } + }, Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) { choices := []*discordgo.ApplicationCommandOptionChoice{ - /*{ + { Name: "Support Ticket", Value: "template_ticket", - },*/ + }, { Name: "Submit URL", Value: "template_url", @@ -273,6 +424,146 @@ var cmd_form Command = Command{ }, } +var cmd_ticket_form Command = Command{ + Definition: discordgo.ApplicationCommand{ + Name: "ticket", + DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageChannels), + Description: "A quick command to create Ticketpanels. (/form for more)", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionString, + Name: "title", + Description: "The title the ticket should have", + }, + { + Type: discordgo.ApplicationCommandOptionMentionable, + Name: "moderator", + Description: "Who can interact with moderating buttons.", + }, + }, + }, + Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + var title string = "Ticket" + var moderator string + if i.ApplicationCommandData().Options != nil { + for _, opt := range i.ApplicationCommandData().Options { + switch opt.Name { + case "title": + title = opt.StringValue() + case "moderator": + moderator = opt.RoleValue(s, i.GuildID).ID + if moderator == "" { + moderator = opt.UserValue(s).ID + } + } + } + } + if moderator == "" { + moderator = i.Member.User.ID + } + var exists bool = true + var formManageID uuid.UUID = uuid.New() + for exists { + formManageID = uuid.New() + exists = getFormManageIdExists(formManageID) + } + message, err := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{ + Embed: &discordgo.MessageEmbed{ + Color: hexToDecimal(color["primary"]), + Title: title, + Description: "Press the bottom button to open a form popup.", + }, + Components: []discordgo.MessageComponent{ + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.Button{ + CustomID: "form:" + formManageID.String(), + Style: discordgo.SuccessButton, + Label: "Submit", + Emoji: discordgo.ComponentEmoji{ + Name: "anim_rocket", + ID: "1215740398706757743", + Animated: true, + }, + }, + }, + }, + }, + }) + if err != nil { + logrus.Error(err) + return + } + if title == "" { + title = "Ticket" + } + var category string + c, err := s.GuildChannelCreate(i.GuildID, title+" mod answers", discordgo.ChannelTypeGuildCategory) + if err != nil { + logrus.Error(err) + } + category = c.ID + if title == "Ticket" { + title = "" + } + + addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), "template_ticket", "", title, "", category, moderator) + err = respond(i.Interaction, "Successfully added ticket panel!\n(`/form` for more options or custom ticket forms.)", true) + if err != nil { + logrus.Error(err) + } + }, +} + +// moderator can be userID as well as roleID +func createFormComment(form_manage_id string, author string, moderator string, commentName string, embed *discordgo.MessageEmbed, i *discordgo.InteractionCreate) { + category := getFormResultValues(form_manage_id).CommentCategoryID + _, err := bot.Channel(category) + if err != nil { + c, err := bot.GuildChannelCreate(i.GuildID, strings.Trim(embed.Title, "\"")+" mod "+commentName+"s", discordgo.ChannelTypeGuildCategory) + if err != nil { + logrus.Error(err) + } + category = c.ID + updateFormCommentCategory(form_manage_id, c.ID) + } + ch, err := bot.GuildChannelCreateComplex(i.GuildID, discordgo.GuildChannelCreateData{ + ParentID: category, + Name: strings.ToLower(embed.Author.Name) + "-" + commentName, + }) + if err != nil { + logrus.Error(err) + } + err = bot.ChannelPermissionSet(ch.ID, i.GuildID, discordgo.PermissionOverwriteTypeRole, 0, discordgo.PermissionViewChannel) + if err != nil { + logrus.Error(err) + } + modType := discordgo.PermissionOverwriteTypeMember + if isIDRole(i.GuildID, moderator) { + modType = discordgo.PermissionOverwriteTypeRole + } + err = bot.ChannelPermissionSet(ch.ID, moderator, modType, discordgo.PermissionViewChannel, 0) + if err != nil { + logrus.Error(err) + } + err = bot.ChannelPermissionSet(ch.ID, author, discordgo.PermissionOverwriteTypeMember, discordgo.PermissionViewChannel, 0) + if err != nil { + logrus.Error(err) + } + modTypeChar := "&" + if modType == discordgo.PermissionOverwriteTypeMember { + modTypeChar = "" + } + _, err = bot.ChannelMessageSendComplex(ch.ID, &discordgo.MessageSend{ + Content: "<@" + modTypeChar + moderator + "> <@" + author + ">", + Embed: embed, + }) + if err != nil { + logrus.Error(err) + } + respond(i.Interaction, "Created channel <#"+ch.ID+">", true) +} + func getFormButtonIDs() []string { var IDs []string = []string{"form_demo"} var formButtonIDs []string = getFormManageIDs() diff --git a/handlers.go b/handlers.go index 7da440b..2191268 100644 --- a/handlers.go +++ b/handlers.go @@ -22,7 +22,7 @@ type Command struct { AllowDM bool } -var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky, context_tag} +var commands []Command = []Command{cmd_form, cmd_ticket_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky, context_tag} func ready(s *discordgo.Session, event *discordgo.Ready) { logrus.Info("Starting up...") @@ -95,18 +95,17 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) { respond(i.Interaction, "This modal is not available in DMs.", true) } else { if command.ModalSubmit != nil { - // FIXME: Makes it dynamic i don't know why it isn't otherwise - if command.Definition.Name == "form" { - command.ModalIDs = getFormButtonIDs() - } var hasID bool = false - for _, modalID := range command.ModalIDs { + var modalIDs []string = append(command.ModalIDs, command.DynamicModalIDs()...) + for _, modalID := range modalIDs { if strings.HasPrefix(i.ModalSubmitData().CustomID, modalID) { hasID = true + break } } if hasID { command.ModalSubmit(s, i) + return // I have no idea why it crashes without that return } } } @@ -115,10 +114,15 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) { respond(i.Interaction, "This component is not available in DMs.", true) } else { if command.ComponentInteract != nil { - if command.Definition.Name == "form" { - command.ComponentIDs = getFormButtonIDs() - } // FIXME: Makes it dynamic i don't know why it isn't otherwise - if slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) { + if slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) || slices.ContainsFunc(command.DynamicComponentIDs(), func(id string) bool { + var customID string + if strings.ContainsAny(i.MessageComponentData().CustomID, ";") { + customID = strings.TrimSuffix(i.MessageComponentData().CustomID, ";"+strings.Split(i.MessageComponentData().CustomID, ";")[1]) + } else { + customID = i.MessageComponentData().CustomID + } + return id == customID + }) { command.ComponentInteract(s, i) } } diff --git a/log2webhook/log2webhook.go b/log2webhook/log2webhook.go index 8af0e20..77f5e1f 100644 --- a/log2webhook/log2webhook.go +++ b/log2webhook/log2webhook.go @@ -63,9 +63,14 @@ func webhook(p []byte) { var logJson Log json.Unmarshal(p, &logJson) var color string = "36314" - if logJson.Level == "error" { - color = "16739179" + formTitles := map[string]string{ + "error": "16739179", + "debug": "16111426", } + if val, ok := formTitles[logJson.Level]; ok { + color = val + } + fileArray := strings.Split(strings.TrimPrefix(logJson.File, RootDir()), ":") m := Message{ Embeds: []Embed{ diff --git a/manage_data.go b/manage_data.go index ae8c3d5..1a33fe3 100644 --- a/manage_data.go +++ b/manage_data.go @@ -2,6 +2,8 @@ package main import ( "log" + "os" + "slices" "github.com/google/uuid" "github.com/sirupsen/logrus" @@ -14,57 +16,71 @@ func initTables() { tag_content TEXT NOT NULL, guild_id TEXT NOT NULL, PRIMARY KEY (tag_id, guild_id) - ); - CREATE TABLE IF NOT EXISTS sticky ( - message_id TEXT NOT NULL, - channel_id TEXT NOT NULL, - message_content TEXT NOT NULL, - guild_id TEXT NOT NULL, - PRIMARY KEY (channel_id, guild_id) - ); - CREATE TABLE IF NOT EXISTS custom_forms ( - form_type TEXT NOT NULL, - title TEXT NOT NULL, - json JSON NOT NULL, - guild_id TEXT NOT NULL, - PRIMARY KEY (form_type, guild_id) - ); - CREATE TABLE IF NOT EXISTS form_manage ( - form_manage_id TEXT NOT NULL, - form_type TEXT NOT NULL, - overwrite_title TEXT, - message_id TEXT NOT NULL, - channel_id TEXT NOT NULL, - guild_id TEXT NOT NULL, - result_channel_id TEXT NOT NULL, - accept_channel_id TEXT, - mods_can_comment BOOL, - PRIMARY KEY (form_manage_id, form_type) - ); - CREATE TABLE IF NOT EXISTS autojoinroles ( - guild_id TEXT NOT NULL, - bot_role TEXT, - user_role TEXT, - PRIMARY KEY (guild_id) - ); - CREATE TABLE IF NOT EXISTS autopublish ( - guild_id TEXT NOT NULL, - news_channel_id TEXT NOT NULL, - PRIMARY KEY (guild_id, news_channel_id) - ) - ` - + ); + CREATE TABLE IF NOT EXISTS sticky ( + message_id TEXT NOT NULL, + channel_id TEXT NOT NULL, + message_content TEXT NOT NULL, + guild_id TEXT NOT NULL, + PRIMARY KEY (channel_id, guild_id) + ); + CREATE TABLE IF NOT EXISTS custom_forms ( + form_type TEXT NOT NULL, + title TEXT NOT NULL, + json JSON NOT NULL, + guild_id TEXT NOT NULL, + PRIMARY KEY (form_type, guild_id) + ); + CREATE TABLE IF NOT EXISTS form_manage ( + form_manage_id TEXT NOT NULL, + form_type TEXT NOT NULL, + overwrite_title TEXT, + message_id TEXT NOT NULL, + channel_id TEXT NOT NULL, + guild_id TEXT NOT NULL, + result_channel_id TEXT NOT NULL, + accept_channel_id TEXT, + comment_category TEXT, + moderator_id TEXT, + PRIMARY KEY (form_manage_id, form_type) + ); + CREATE TABLE IF NOT EXISTS autojoinroles ( + guild_id TEXT NOT NULL, + bot_role TEXT, + user_role TEXT, + PRIMARY KEY (guild_id) + ); + CREATE TABLE IF NOT EXISTS autopublish ( + guild_id TEXT NOT NULL, + news_channel_id TEXT NOT NULL, + PRIMARY KEY (guild_id, news_channel_id) + )` _, err := db.Exec(createTableQuery) if err != nil { log.Fatal(err) } + if slices.Contains(os.Args, "--form-db-update") { + _, err := db.Exec("ALTER TABLE form_manage ADD moderator_id TEXT;") + if err != nil { + log.Fatal(err) + } + _, err = db.Exec("ALTER TABLE form_manage ADD comment_category TEXT;") + if err != nil { + log.Fatal(err) + } + _, err = db.Exec("ALTER TABLE form_manage DROP COLUMN mods_can_comment;") + if err != nil { + log.Fatal(err) + } + } } type FormResult struct { - OverwriteTitle string - ResultChannelID string - AcceptChannelID string - ModsCanComment bool + OverwriteTitle string + ResultChannelID string + AcceptChannelID string + CommentCategoryID string + ModeratorID string } func addTag(guildID, tagName, tagContent string) bool { @@ -197,8 +213,20 @@ func getFormManageIdExists(id uuid.UUID) bool { return exists } -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) +func addFormButton(guildID string, channelID string, messageID string, formManageID string, formType string, resultChannelID string, overwriteTitle string, acceptChannelID string, commentCategory string, moderator_id string) { + _, 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, + comment_category, + moderator_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, + guildID, formManageID, channelID, messageID, formType, resultChannelID, overwriteTitle, acceptChannelID, commentCategory, moderator_id) if err != nil { logrus.Error(err) } @@ -255,7 +283,11 @@ func getFormResultValues(formManageID string) FormResult { if err != nil { logrus.Error(err) } - err = db.QueryRow("SELECT mods_can_comment FROM form_manage WHERE form_manage_id = $1", formManageID).Scan(&result.ModsCanComment) + err = db.QueryRow("SELECT comment_category FROM form_manage WHERE form_manage_id = $1", formManageID).Scan(&result.CommentCategoryID) + if err != nil { + logrus.Error(err) + } + err = db.QueryRow("SELECT moderator_id FROM form_manage WHERE form_manage_id = $1", formManageID).Scan(&result.ModeratorID) if err != nil { logrus.Error(err) } @@ -271,6 +303,13 @@ func getFormOverwriteTitle(formManageID string) string { return overwriteTitle } +func updateFormCommentCategory(formManageID string, comment_category string) { + _, err := db.Exec("UPDATE form_manage SET comment_category = $1 WHERE form_manage_id = $2", comment_category, formManageID) + if err != nil { + logrus.Error(err) + } +} + func setAutoJoinRole(guildID string, option string, roleID string) bool { var role_exists bool var autojoinroles_exists bool diff --git a/tool.go b/tool.go index 003f84b..ca42c3e 100644 --- a/tool.go +++ b/tool.go @@ -215,3 +215,22 @@ func findAndDeleteUnusedMessages() { } } } + +func isIDRole(guildID, id string) bool { + _, err1 := bot.GuildMember(guildID, id) + if err1 == nil { + return false + } + roles, err2 := bot.GuildRoles(guildID) + if err2 == nil { + for _, role := range roles { + if role.ID == id { + return true + } + } + } + + logrus.Error(err1) + logrus.Error(err2) + return false +}