added full ticket functionality to forms
This commit is contained in:
381
cmd_form.go
381
cmd_form.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@@ -43,7 +44,11 @@ var cmd_form Command = Command{
|
|||||||
Name: "result_channel",
|
Name: "result_channel",
|
||||||
Description: "Where the form results should appear",
|
Description: "Where the form results should appear",
|
||||||
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
|
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
|
||||||
Required: true,
|
},
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionMentionable,
|
||||||
|
Name: "moderator",
|
||||||
|
Description: "Who can interact with moderating buttons.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
@@ -56,17 +61,17 @@ var cmd_form Command = Command{
|
|||||||
Name: "title",
|
Name: "title",
|
||||||
Description: "The title the form should have",
|
Description: "The title the form should have",
|
||||||
},
|
},
|
||||||
/*{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionChannel,
|
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",
|
Description: "Channel for results that need to be accepted by a moderator before sending it to the result channel",
|
||||||
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
|
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionBoolean,
|
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",
|
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":
|
case "add":
|
||||||
var title, formID, overwriteTitle, acceptChannelID string
|
var title, formID, overwriteTitle, acceptChannelID string
|
||||||
var modsCanComment bool
|
var modsCanAnswer bool
|
||||||
options := i.ApplicationCommandData().Options[0]
|
var resultChannelID string
|
||||||
for _, opt := range options.Options {
|
moderator := i.Member.User.ID
|
||||||
switch opt.Name {
|
if i.ApplicationCommandData().Options != nil {
|
||||||
case "type":
|
options := i.ApplicationCommandData().Options[0]
|
||||||
formID = opt.StringValue()
|
for _, opt := range options.Options {
|
||||||
case "title":
|
switch opt.Name {
|
||||||
overwriteTitle = opt.StringValue()
|
case "result_channel":
|
||||||
title = overwriteTitle
|
resultChannelID = opt.ChannelValue(s).ID
|
||||||
case "accept_channel":
|
case "type":
|
||||||
acceptChannelID = opt.ChannelValue(s).ID
|
formID = opt.StringValue()
|
||||||
case "mods_can_comment":
|
case "title":
|
||||||
modsCanComment = opt.BoolValue()
|
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 == "" {
|
if formID == "" {
|
||||||
@@ -180,23 +196,65 @@ var cmd_form Command = Command{
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return
|
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)
|
err = respond(i.Interaction, "Successfully added form button!", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
DynamicComponentIDs: func() []string { return getFormButtonIDs() },
|
||||||
|
DynamicModalIDs: func() []string { return getFormButtonIDs() },
|
||||||
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
|
if strings.ContainsAny(i.MessageComponentData().CustomID, ";") {
|
||||||
var formManageID string = strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")
|
var form_manage_id string = strings.TrimPrefix(strings.Split(i.MessageComponentData().CustomID, ";")[0], "form:")
|
||||||
jsonStringShowModal(i.Interaction, i.Interaction.MessageComponentData().CustomID, getFormType(formManageID), getFormOverwriteTitle(formManageID))
|
switch strings.Split(i.MessageComponentData().CustomID, ";")[1] {
|
||||||
} else if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
case "decline":
|
||||||
jsonStringShowModal(i.Interaction, "form_demo", "form_demo")
|
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) {
|
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 form_manage_id string = strings.Split(i.ModalSubmitData().CustomID, ":")[1]
|
||||||
var result FormResult = getFormResultValues(form_manage_id)
|
var result FormResult = getFormResultValues(form_manage_id)
|
||||||
var fields []*discordgo.MessageEmbedField
|
var fields []*discordgo.MessageEmbedField
|
||||||
@@ -213,10 +271,14 @@ var cmd_form Command = Command{
|
|||||||
Inline: input.Style == discordgo.TextInputShort,
|
Inline: input.Style == discordgo.TextInputShort,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if result.AcceptChannelID == "" {
|
|
||||||
channel, _ := s.Channel(i.ChannelID)
|
channel, _ := s.Channel(i.ChannelID)
|
||||||
_, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
|
fields = append(fields, &discordgo.MessageEmbedField{
|
||||||
Embed: &discordgo.MessageEmbed{
|
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{
|
Author: &discordgo.MessageEmbedAuthor{
|
||||||
Name: i.Member.User.Username,
|
Name: i.Member.User.Username,
|
||||||
IconURL: i.Member.AvatarURL("256"),
|
IconURL: i.Member.AvatarURL("256"),
|
||||||
@@ -225,33 +287,122 @@ var cmd_form Command = Command{
|
|||||||
Color: hexToDecimal(color["primary"]),
|
Color: hexToDecimal(color["primary"]),
|
||||||
Description: "This is the submitted result",
|
Description: "This is the submitted result",
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
Footer: &discordgo.MessageEmbedFooter{
|
}, i)
|
||||||
Text: "From #" + channel.Name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
} else {
|
} else {
|
||||||
err = respond(i.Interaction, "Submited!", true)
|
respond(i.Interaction, "You need to provide either a `result_channel` or enable `mods_can_answer` to create a valid form.", true)
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := respond(i.Interaction, "The form data would be send to a specified channel. 🤲", true)
|
if result.AcceptChannelID == "" {
|
||||||
if err != nil {
|
var buttons []discordgo.MessageComponent
|
||||||
logrus.Error(err)
|
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) {
|
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
choices := []*discordgo.ApplicationCommandOptionChoice{
|
choices := []*discordgo.ApplicationCommandOptionChoice{
|
||||||
/*{
|
{
|
||||||
Name: "Support Ticket",
|
Name: "Support Ticket",
|
||||||
Value: "template_ticket",
|
Value: "template_ticket",
|
||||||
},*/
|
},
|
||||||
{
|
{
|
||||||
Name: "Submit URL",
|
Name: "Submit URL",
|
||||||
Value: "template_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 {
|
func getFormButtonIDs() []string {
|
||||||
var IDs []string = []string{"form_demo"}
|
var IDs []string = []string{"form_demo"}
|
||||||
var formButtonIDs []string = getFormManageIDs()
|
var formButtonIDs []string = getFormManageIDs()
|
||||||
|
24
handlers.go
24
handlers.go
@@ -22,7 +22,7 @@ type Command struct {
|
|||||||
AllowDM bool
|
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) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
logrus.Info("Starting up...")
|
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)
|
respond(i.Interaction, "This modal is not available in DMs.", true)
|
||||||
} else {
|
} else {
|
||||||
if command.ModalSubmit != nil {
|
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
|
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) {
|
if strings.HasPrefix(i.ModalSubmitData().CustomID, modalID) {
|
||||||
hasID = true
|
hasID = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasID {
|
if hasID {
|
||||||
command.ModalSubmit(s, i)
|
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)
|
respond(i.Interaction, "This component is not available in DMs.", true)
|
||||||
} else {
|
} else {
|
||||||
if command.ComponentInteract != nil {
|
if command.ComponentInteract != nil {
|
||||||
if command.Definition.Name == "form" {
|
if slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) || slices.ContainsFunc(command.DynamicComponentIDs(), func(id string) bool {
|
||||||
command.ComponentIDs = getFormButtonIDs()
|
var customID string
|
||||||
} // FIXME: Makes it dynamic i don't know why it isn't otherwise
|
if strings.ContainsAny(i.MessageComponentData().CustomID, ";") {
|
||||||
if slices.Contains(command.ComponentIDs, 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)
|
command.ComponentInteract(s, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,9 +63,14 @@ func webhook(p []byte) {
|
|||||||
var logJson Log
|
var logJson Log
|
||||||
json.Unmarshal(p, &logJson)
|
json.Unmarshal(p, &logJson)
|
||||||
var color string = "36314"
|
var color string = "36314"
|
||||||
if logJson.Level == "error" {
|
formTitles := map[string]string{
|
||||||
color = "16739179"
|
"error": "16739179",
|
||||||
|
"debug": "16111426",
|
||||||
}
|
}
|
||||||
|
if val, ok := formTitles[logJson.Level]; ok {
|
||||||
|
color = val
|
||||||
|
}
|
||||||
|
|
||||||
fileArray := strings.Split(strings.TrimPrefix(logJson.File, RootDir()), ":")
|
fileArray := strings.Split(strings.TrimPrefix(logJson.File, RootDir()), ":")
|
||||||
m := Message{
|
m := Message{
|
||||||
Embeds: []Embed{
|
Embeds: []Embed{
|
||||||
|
133
manage_data.go
133
manage_data.go
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -14,57 +16,71 @@ func initTables() {
|
|||||||
tag_content TEXT NOT NULL,
|
tag_content TEXT NOT NULL,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
PRIMARY KEY (tag_id, guild_id)
|
PRIMARY KEY (tag_id, guild_id)
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS sticky (
|
CREATE TABLE IF NOT EXISTS sticky (
|
||||||
message_id TEXT NOT NULL,
|
message_id TEXT NOT NULL,
|
||||||
channel_id TEXT NOT NULL,
|
channel_id TEXT NOT NULL,
|
||||||
message_content TEXT NOT NULL,
|
message_content TEXT NOT NULL,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
PRIMARY KEY (channel_id, guild_id)
|
PRIMARY KEY (channel_id, guild_id)
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS custom_forms (
|
CREATE TABLE IF NOT EXISTS custom_forms (
|
||||||
form_type TEXT NOT NULL,
|
form_type TEXT NOT NULL,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
json JSON NOT NULL,
|
json JSON NOT NULL,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
PRIMARY KEY (form_type, guild_id)
|
PRIMARY KEY (form_type, guild_id)
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS form_manage (
|
CREATE TABLE IF NOT EXISTS form_manage (
|
||||||
form_manage_id TEXT NOT NULL,
|
form_manage_id TEXT NOT NULL,
|
||||||
form_type TEXT NOT NULL,
|
form_type TEXT NOT NULL,
|
||||||
overwrite_title TEXT,
|
overwrite_title TEXT,
|
||||||
message_id TEXT NOT NULL,
|
message_id TEXT NOT NULL,
|
||||||
channel_id TEXT NOT NULL,
|
channel_id TEXT NOT NULL,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
result_channel_id TEXT NOT NULL,
|
result_channel_id TEXT NOT NULL,
|
||||||
accept_channel_id TEXT,
|
accept_channel_id TEXT,
|
||||||
mods_can_comment BOOL,
|
comment_category TEXT,
|
||||||
PRIMARY KEY (form_manage_id, form_type)
|
moderator_id TEXT,
|
||||||
);
|
PRIMARY KEY (form_manage_id, form_type)
|
||||||
CREATE TABLE IF NOT EXISTS autojoinroles (
|
);
|
||||||
guild_id TEXT NOT NULL,
|
CREATE TABLE IF NOT EXISTS autojoinroles (
|
||||||
bot_role TEXT,
|
guild_id TEXT NOT NULL,
|
||||||
user_role TEXT,
|
bot_role TEXT,
|
||||||
PRIMARY KEY (guild_id)
|
user_role TEXT,
|
||||||
);
|
PRIMARY KEY (guild_id)
|
||||||
CREATE TABLE IF NOT EXISTS autopublish (
|
);
|
||||||
guild_id TEXT NOT NULL,
|
CREATE TABLE IF NOT EXISTS autopublish (
|
||||||
news_channel_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
PRIMARY KEY (guild_id, news_channel_id)
|
news_channel_id TEXT NOT NULL,
|
||||||
)
|
PRIMARY KEY (guild_id, news_channel_id)
|
||||||
`
|
)`
|
||||||
|
|
||||||
_, err := db.Exec(createTableQuery)
|
_, err := db.Exec(createTableQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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 {
|
type FormResult struct {
|
||||||
OverwriteTitle string
|
OverwriteTitle string
|
||||||
ResultChannelID string
|
ResultChannelID string
|
||||||
AcceptChannelID string
|
AcceptChannelID string
|
||||||
ModsCanComment bool
|
CommentCategoryID string
|
||||||
|
ModeratorID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTag(guildID, tagName, tagContent string) bool {
|
func addTag(guildID, tagName, tagContent string) bool {
|
||||||
@@ -197,8 +213,20 @@ func getFormManageIdExists(id uuid.UUID) bool {
|
|||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFormButton(guildID string, channelID string, messageID string, formManageID string, formType string, resultChannelID string, overwriteTitle string, acceptChannelID string, modsCanComment bool) {
|
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, mods_can_comment) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", guildID, formManageID, channelID, messageID, formType, resultChannelID, overwriteTitle, acceptChannelID, modsCanComment)
|
_, 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 {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
@@ -255,7 +283,11 @@ func getFormResultValues(formManageID string) FormResult {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
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 {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
@@ -271,6 +303,13 @@ func getFormOverwriteTitle(formManageID string) string {
|
|||||||
return overwriteTitle
|
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 {
|
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
|
||||||
|
19
tool.go
19
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user