got forms half way working with disgo
This commit is contained in:
348
cmd_form.go
348
cmd_form.go
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/disgoorg/disgo/bot"
|
||||||
"github.com/disgoorg/disgo/discord"
|
"github.com/disgoorg/disgo/discord"
|
||||||
"github.com/disgoorg/disgo/events"
|
"github.com/disgoorg/disgo/events"
|
||||||
"github.com/disgoorg/json"
|
"github.com/disgoorg/json"
|
||||||
@@ -98,19 +98,22 @@ var cmd_form Command = Command{
|
|||||||
var title, formID, overwriteTitle, acceptChannelID string
|
var title, formID, overwriteTitle, acceptChannelID string
|
||||||
var modsCanAnswer bool
|
var modsCanAnswer bool
|
||||||
var resultChannelID string
|
var resultChannelID string
|
||||||
moderator := e.Member().User.ID.String()
|
|
||||||
data := e.SlashCommandInteractionData()
|
data := e.SlashCommandInteractionData()
|
||||||
resultChannelID = data.Channel("result_channel").ID.String()
|
if data.Channel("result_channel").ID.String() != "0" {
|
||||||
moderator = data.Role("moderator").ID.String()
|
resultChannelID = data.Channel("result_channel").ID.String()
|
||||||
if moderator == "" {
|
}
|
||||||
moderator = data.User("moderator").ID.String()
|
moderator := data.Role("moderator").ID.String()
|
||||||
|
if moderator == "0" {
|
||||||
|
moderator = e.User().ID.String()
|
||||||
}
|
}
|
||||||
formID = data.String("type")
|
formID = data.String("type")
|
||||||
overwriteTitle = data.String("title")
|
overwriteTitle = data.String("title")
|
||||||
if overwriteTitle != "" {
|
if overwriteTitle != "" {
|
||||||
title = overwriteTitle
|
title = overwriteTitle
|
||||||
}
|
}
|
||||||
acceptChannelID = data.Channel("accept_channel").ID.String()
|
if data.Channel("accept_channel").ID.String() != "0" {
|
||||||
|
acceptChannelID = data.Channel("accept_channel").ID.String()
|
||||||
|
}
|
||||||
modsCanAnswer = data.Bool("mods_can_answer")
|
modsCanAnswer = data.Bool("mods_can_answer")
|
||||||
|
|
||||||
if formID == "" {
|
if formID == "" {
|
||||||
@@ -153,6 +156,7 @@ var cmd_form Command = Command{
|
|||||||
}
|
}
|
||||||
category = c.ID().String()
|
category = c.ID().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
addFormButton(e.GuildID().String(), e.Channel().ID().String(), message.ID.String(), formManageID.String(), formID, resultChannelID, overwriteTitle, acceptChannelID, category, moderator)
|
addFormButton(e.GuildID().String(), e.Channel().ID().String(), message.ID.String(), formManageID.String(), formID, resultChannelID, overwriteTitle, acceptChannelID, category, moderator)
|
||||||
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Successfully added form button!").SetEphemeral(true).Build())
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Successfully added form button!").SetEphemeral(true).Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -175,7 +179,7 @@ var cmd_form Command = Command{
|
|||||||
e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission declined!").SetEphemeral(true).Build())
|
e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission declined!").SetEphemeral(true).Build())
|
||||||
case "approve":
|
case "approve":
|
||||||
embed := e.Message.Embeds[0]
|
embed := e.Message.Embeds[0]
|
||||||
embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", e.Member().User.ID)
|
embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", e.User().ID)
|
||||||
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(getFormResultValues(form_manage_id).ResultChannelID), discord.NewMessageCreateBuilder().
|
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(getFormResultValues(form_manage_id).ResultChannelID), discord.NewMessageCreateBuilder().
|
||||||
SetEmbeds(embed).
|
SetEmbeds(embed).
|
||||||
Build())
|
Build())
|
||||||
@@ -190,149 +194,117 @@ var cmd_form Command = Command{
|
|||||||
case "comment":
|
case "comment":
|
||||||
author := strings.TrimSuffix(strings.Split(e.Message.Embeds[0].Fields[len(e.Message.Embeds[0].Fields)-1].Value, "<@")[1], ">")
|
author := strings.TrimSuffix(strings.Split(e.Message.Embeds[0].Fields[len(e.Message.Embeds[0].Fields)-1].Value, "<@")[1], ">")
|
||||||
embed := e.Message.Embeds[0]
|
embed := e.Message.Embeds[0]
|
||||||
moderator := e.Member().User.ID
|
moderator := e.User().ID
|
||||||
createFormComment(form_manage_id, author, moderator, "answer", embed, e)
|
channel := createFormComment(form_manage_id, snowflake.MustParse(author), moderator, "answer", embed, *e.GuildID(), e.Client())
|
||||||
|
e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Created channel " + discord.ChannelMention(channel.ID())).SetEphemeral(true).Build())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
|
if strings.HasPrefix(e.ButtonInteractionData().CustomID(), "form:") {
|
||||||
var formManageID string = strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")
|
var formManageID string = strings.TrimPrefix(e.ButtonInteractionData().CustomID(), "form:")
|
||||||
jsonStringShowModal(i.Interaction, i.Interaction.MessageComponentData().CustomID, getFormType(formManageID), getFormOverwriteTitle(formManageID))
|
e.Modal(jsonStringBuildModal(e.User().ID.String(), formManageID, getFormType(formManageID), getFormOverwriteTitle(formManageID)))
|
||||||
} else if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
} else if e.ButtonInteractionData().CustomID() == "form_demo" {
|
||||||
jsonStringShowModal(i.Interaction, "form_demo", "form_demo")
|
e.Modal(jsonStringBuildModal(e.User().ID.String(), "form_demo", "form_demo"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ModalSubmit: func(e *events.ModalSubmitInteractionCreate) {
|
||||||
if !strings.HasPrefix(i.ModalSubmitData().CustomID, "form_demo") {
|
if !strings.HasPrefix(e.Data.CustomID, "form_demo") {
|
||||||
var form_manage_id string = strings.Split(i.ModalSubmitData().CustomID, ":")[1]
|
var form_manage_id string = strings.Split(e.Data.CustomID, ":")[1]
|
||||||
var result FormResult = getFormResultValues(form_manage_id)
|
var result FormResult = getFormResultValues(form_manage_id)
|
||||||
var fields []*discordgo.MessageEmbedField
|
var fields []discord.EmbedField
|
||||||
var modal ModalJson = getModalByFormID(getFormType(form_manage_id))
|
var modal ModalJson = getModalByFormID(getFormType(form_manage_id))
|
||||||
var overwrite_title string = getFormOverwriteTitle(form_manage_id)
|
var overwrite_title string = getFormOverwriteTitle(form_manage_id)
|
||||||
if overwrite_title != "" {
|
if overwrite_title != "" {
|
||||||
modal.Title = overwrite_title
|
modal.Title = overwrite_title
|
||||||
}
|
}
|
||||||
for index, component := range i.ModalSubmitData().Components {
|
var inline bool
|
||||||
var input *discordgo.TextInput = component.(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput)
|
var index int = 0
|
||||||
fields = append(fields, &discordgo.MessageEmbedField{
|
for _, component := range e.Data.Components {
|
||||||
|
var input discord.TextInputComponent = component.(discord.TextInputComponent)
|
||||||
|
inline = input.Style == discord.TextInputStyleShort
|
||||||
|
fields = append(fields, discord.EmbedField{
|
||||||
Name: modal.Form[index].Label,
|
Name: modal.Form[index].Label,
|
||||||
Value: input.Value,
|
Value: input.Value,
|
||||||
Inline: input.Style == discordgo.TextInputShort,
|
Inline: &inline,
|
||||||
})
|
})
|
||||||
|
index++
|
||||||
}
|
}
|
||||||
|
|
||||||
channel, _ := s.Channel(i.ChannelID)
|
fields = append(fields, discord.EmbedField{
|
||||||
fields = append(fields, &discordgo.MessageEmbedField{
|
Value: "From <#" + e.Channel().ID().String() + "> by " + e.User().Mention(),
|
||||||
Value: "From <#" + channel.ID + "> by <@" + i.Member.User.ID + ">",
|
|
||||||
})
|
})
|
||||||
if result.ResultChannelID == "" {
|
if result.ResultChannelID == "" {
|
||||||
if result.CommentCategoryID != "" {
|
if result.CommentCategoryID != "" {
|
||||||
createFormComment(form_manage_id, i.Member.User.ID, result.ModeratorID, "answer", &discordgo.MessageEmbed{
|
channel := createFormComment(form_manage_id, e.User().ID, snowflake.MustParse(result.ModeratorID), "answer", discord.NewEmbedBuilder().
|
||||||
Author: &discordgo.MessageEmbedAuthor{
|
SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("This is the submitted result").
|
||||||
Name: i.Member.User.Username,
|
SetColor(hexToDecimal(color["primary"])).SetFields(fields...).
|
||||||
IconURL: i.Member.AvatarURL("256"),
|
Build(), *e.GuildID(), e.Client())
|
||||||
},
|
err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Created channel " + discord.ChannelMention(channel.ID())).SetEphemeral(true).Build())
|
||||||
Title: "\"" + modal.Title + "\"",
|
if err != nil {
|
||||||
Color: hexToDecimal(color["primary"]),
|
logrus.Error(err)
|
||||||
Description: "This is the submitted result",
|
}
|
||||||
Fields: fields,
|
|
||||||
}, i)
|
|
||||||
} else {
|
} else {
|
||||||
respond(i.Interaction, "You need to provide either a `result_channel` or enable `mods_can_answer` to create a valid form.", true)
|
e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||||
|
SetContent("You need to provide either a `result_channel` or enable `mods_can_answer` to create a valid form.").SetEphemeral(true).
|
||||||
|
Build())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if result.AcceptChannelID == "" {
|
if result.AcceptChannelID == "" {
|
||||||
var buttons []discordgo.MessageComponent
|
var buttons []discord.ButtonComponent
|
||||||
|
var components []discord.ContainerComponent
|
||||||
if result.CommentCategoryID != "" {
|
if result.CommentCategoryID != "" {
|
||||||
buttons = []discordgo.MessageComponent{
|
buttons = []discord.ButtonComponent{discord.
|
||||||
discordgo.ActionsRow{
|
NewButton(discord.ButtonStylePrimary, "Comment", "form:"+form_manage_id+";comment", "").
|
||||||
Components: []discordgo.MessageComponent{
|
WithEmoji(discord.ComponentEmoji{Name: "👥"})}
|
||||||
discordgo.Button{
|
for _, button := range buttons {
|
||||||
Style: discordgo.PrimaryButton,
|
components = append(components, discord.NewActionRow(button))
|
||||||
Emoji: discordgo.ComponentEmoji{
|
|
||||||
Name: "👥",
|
|
||||||
},
|
|
||||||
Label: "Comment",
|
|
||||||
CustomID: "form:" + form_manage_id + ";comment",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := s.ChannelMessageSendComplex(result.ResultChannelID, &discordgo.MessageSend{
|
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.ResultChannelID), discord.NewMessageCreateBuilder().
|
||||||
Embed: &discordgo.MessageEmbed{
|
SetEmbeds(discord.NewEmbedBuilder().
|
||||||
Author: &discordgo.MessageEmbedAuthor{
|
SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("This is the submitted result").
|
||||||
Name: i.Member.User.Username,
|
SetColor(hexToDecimal(color["primary"])).SetFields(fields...).
|
||||||
IconURL: i.Member.AvatarURL("256"),
|
Build()).
|
||||||
},
|
SetContainerComponents(components...).
|
||||||
Title: "\"" + modal.Title + "\"",
|
Build())
|
||||||
Color: hexToDecimal(color["primary"]),
|
|
||||||
Description: "This is the submitted result",
|
|
||||||
Fields: fields,
|
|
||||||
},
|
|
||||||
Components: buttons,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
} else {
|
} else {
|
||||||
err = respond(i.Interaction, "Submited!", true)
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submitted!").SetEphemeral(true).Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var buttons []discordgo.MessageComponent
|
var buttons []discord.ButtonComponent
|
||||||
if result.CommentCategoryID != "" {
|
if result.CommentCategoryID != "" {
|
||||||
buttons = []discordgo.MessageComponent{
|
buttons = []discord.ButtonComponent{discord.
|
||||||
discordgo.Button{
|
NewButton(discord.ButtonStylePrimary, "Comment", "form:"+form_manage_id+";comment", "").
|
||||||
Style: discordgo.PrimaryButton,
|
WithEmoji(discord.ComponentEmoji{Name: "👥"})}
|
||||||
Emoji: discordgo.ComponentEmoji{
|
|
||||||
Name: "👥",
|
|
||||||
},
|
|
||||||
Label: "Comment",
|
|
||||||
CustomID: "form:" + form_manage_id + ";comment",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buttons = append(buttons,
|
buttons = append(buttons, discord.
|
||||||
discordgo.Button{
|
NewButton(discord.ButtonStylePrimary, "Decline", "form:"+form_manage_id+";decline", "").
|
||||||
Style: discordgo.DangerButton,
|
WithEmoji(discord.ComponentEmoji{Name: "🛑"}),
|
||||||
Emoji: discordgo.ComponentEmoji{
|
discord.
|
||||||
Name: "🛑",
|
NewButton(discord.ButtonStylePrimary, "Approve", "form:"+form_manage_id+";approve", "").
|
||||||
},
|
WithEmoji(discord.ComponentEmoji{Name: "🎉"}))
|
||||||
Label: "Decline",
|
var components []discord.ContainerComponent
|
||||||
CustomID: "form:" + form_manage_id + ";decline",
|
for _, button := range buttons {
|
||||||
},
|
components = append(components, discord.NewActionRow(button))
|
||||||
discordgo.Button{
|
}
|
||||||
Style: discordgo.SuccessButton,
|
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.AcceptChannelID), discord.NewMessageCreateBuilder().
|
||||||
Emoji: discordgo.ComponentEmoji{
|
SetEmbeds(discord.NewEmbedBuilder().
|
||||||
Name: "🎉",
|
SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("**This submission needs approval.**").
|
||||||
},
|
SetColor(hexToDecimal(color["primary"])).SetFields(fields...).
|
||||||
Label: "Approve",
|
Build()).
|
||||||
CustomID: "form:" + form_manage_id + ";approve",
|
SetContainerComponents(components...).
|
||||||
})
|
Build())
|
||||||
_, 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 {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
} else {
|
} else {
|
||||||
err = respond(i.Interaction, "Submited!", true)
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submitted!").SetEphemeral(true).Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
@@ -340,33 +312,27 @@ var cmd_form Command = Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := respond(i.Interaction, "The results would be submited...", true)
|
err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("The results would be submited...").SetEphemeral(true).Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Autocomplete: func(e *events.AutocompleteInteractionCreate) {
|
||||||
choices := []*discordgo.ApplicationCommandOptionChoice{
|
err := e.AutocompleteResult([]discord.AutocompleteChoice{
|
||||||
{
|
&discord.AutocompleteChoiceString{
|
||||||
Name: "Support Ticket",
|
Name: "Support Ticket",
|
||||||
Value: "template_ticket",
|
Value: "template_ticket",
|
||||||
},
|
},
|
||||||
{
|
&discord.AutocompleteChoiceString{
|
||||||
Name: "Submit URL",
|
Name: "Submit URL",
|
||||||
Value: "template_url",
|
Value: "template_url",
|
||||||
},
|
},
|
||||||
{
|
&discord.AutocompleteChoiceString{
|
||||||
Name: "General",
|
Name: "General",
|
||||||
Value: "template_general",
|
Value: "template_general",
|
||||||
},
|
},
|
||||||
}
|
|
||||||
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionApplicationCommandAutocompleteResult,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Choices: choices,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@@ -375,41 +341,31 @@ var cmd_form Command = Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cmd_ticket_form Command = Command{
|
var cmd_ticket_form Command = Command{
|
||||||
Definition: discordgo.ApplicationCommand{
|
Definition: discord.SlashCommandCreate{
|
||||||
Name: "ticket",
|
Name: "ticket",
|
||||||
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageChannels),
|
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels),
|
||||||
Description: "A quick command to create Ticketpanels. (/form for more)",
|
Description: "A quick command to create Ticketpanels. (/form for more)",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
Options: []discord.ApplicationCommandOption{
|
||||||
{
|
&discord.ApplicationCommandOptionString{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
|
||||||
Name: "title",
|
Name: "title",
|
||||||
Description: "The title the ticket should have",
|
Description: "The title the ticket should have",
|
||||||
},
|
},
|
||||||
{
|
&discord.ApplicationCommandOptionMentionable{
|
||||||
Type: discordgo.ApplicationCommandOptionMentionable,
|
|
||||||
Name: "moderator",
|
Name: "moderator",
|
||||||
Description: "Who can interact with moderating buttons.",
|
Description: "Who can interact with moderating buttons.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||||
var title string = "Ticket"
|
var title string = "Ticket"
|
||||||
var moderator string
|
var moderator string
|
||||||
if i.ApplicationCommandData().Options != nil {
|
data := e.SlashCommandInteractionData()
|
||||||
for _, opt := range i.ApplicationCommandData().Options {
|
if data.String("title") != "" {
|
||||||
switch opt.Name {
|
title = data.String("title")
|
||||||
case "title":
|
|
||||||
title = opt.StringValue()
|
|
||||||
case "moderator":
|
|
||||||
moderator = opt.RoleValue(s, i.GuildID).ID
|
|
||||||
if moderator == "" {
|
|
||||||
moderator = opt.UserValue(s).ID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
moderator = data.Role("moderator").ID.String()
|
||||||
if moderator == "" {
|
if moderator == "" {
|
||||||
moderator = i.Member.User.ID
|
moderator = data.User("moderator").ID.String()
|
||||||
}
|
}
|
||||||
var exists bool = true
|
var exists bool = true
|
||||||
var formManageID uuid.UUID = uuid.New()
|
var formManageID uuid.UUID = uuid.New()
|
||||||
@@ -417,29 +373,16 @@ var cmd_ticket_form Command = Command{
|
|||||||
formManageID = uuid.New()
|
formManageID = uuid.New()
|
||||||
exists = getFormManageIdExists(formManageID)
|
exists = getFormManageIdExists(formManageID)
|
||||||
}
|
}
|
||||||
message, err := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
|
messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder().
|
||||||
Embed: &discordgo.MessageEmbed{
|
SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(hexToDecimal(color["primary"])).
|
||||||
Color: hexToDecimal(color["primary"]),
|
Build()).SetContainerComponents(discord.ActionRowComponent{
|
||||||
Title: title,
|
discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{
|
||||||
Description: "Press the bottom button to open a form popup.",
|
Name: "anim_rocket",
|
||||||
},
|
ID: snowflake.MustParse("1215740398706757743"),
|
||||||
Components: []discordgo.MessageComponent{
|
Animated: true,
|
||||||
discordgo.ActionsRow{
|
})}).
|
||||||
Components: []discordgo.MessageComponent{
|
Build()
|
||||||
discordgo.Button{
|
message, err := e.Client().Rest().CreateMessage(e.Channel().ID(), messagebuild)
|
||||||
CustomID: "form:" + formManageID.String(),
|
|
||||||
Style: discordgo.SuccessButton,
|
|
||||||
Label: "Submit",
|
|
||||||
Emoji: discordgo.ComponentEmoji{
|
|
||||||
Name: "anim_rocket",
|
|
||||||
ID: "1215740398706757743",
|
|
||||||
Animated: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return
|
return
|
||||||
@@ -448,17 +391,17 @@ var cmd_ticket_form Command = Command{
|
|||||||
title = "Ticket"
|
title = "Ticket"
|
||||||
}
|
}
|
||||||
var category string
|
var category string
|
||||||
c, err := s.GuildChannelCreate(i.GuildID, title+" mod answers", discordgo.ChannelTypeGuildCategory)
|
c, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildCategoryChannelCreate{Name: title + " mod answers"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
category = c.ID
|
category = c.ID().String()
|
||||||
if title == "Ticket" {
|
if title == "Ticket" {
|
||||||
title = ""
|
title = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), "template_ticket", "", title, "", category, moderator)
|
addFormButton(e.GuildID().String(), e.Channel().ID().String(), message.ID.String(), 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)
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Successfully added ticket panel!\n(`/form` for more options or custom ticket forms.)").SetEphemeral(true).Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
@@ -466,53 +409,60 @@ var cmd_ticket_form Command = Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// moderator can be userID as well as roleID
|
// moderator can be userID as well as roleID
|
||||||
func createFormComment(form_manage_id string, author string, moderator snowflake.ID, commentName string, embed discord.Embed, e *events.ComponentInteractionCreate) {
|
func createFormComment(form_manage_id string, author snowflake.ID, moderator snowflake.ID, commentName string, embed discord.Embed, guildID snowflake.ID, client bot.Client) discord.Channel {
|
||||||
var category snowflake.ID
|
var category snowflake.ID
|
||||||
_, err := e.Client().Rest().GetChannel(snowflake.MustParse(getFormResultValues(form_manage_id).CommentCategoryID))
|
_, err := client.Rest().GetChannel(snowflake.MustParse(getFormResultValues(form_manage_id).CommentCategoryID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildCategoryChannelCreate{Name: strings.Trim(embed.Title, "\"") + " mod " + commentName + "s"})
|
c, err := client.Rest().CreateGuildChannel(guildID, discord.GuildCategoryChannelCreate{Name: strings.Trim(embed.Title, "\"") + " mod " + commentName + "s"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
category = c.ID()
|
category = c.ID()
|
||||||
updateFormCommentCategory(form_manage_id, category.String())
|
updateFormCommentCategory(form_manage_id, category.String())
|
||||||
}
|
}
|
||||||
ch, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildTextChannelCreate{
|
ch, err := client.Rest().CreateGuildChannel(guildID, discord.GuildTextChannelCreate{
|
||||||
ParentID: category,
|
ParentID: category,
|
||||||
Name: strings.ToLower(embed.Author.Name) + "-" + commentName,
|
Name: strings.ToLower(embed.Author.Name) + "-" + commentName,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
err = bot.ChannelPermissionSet(ch.ID, i.GuildID, discordgo.PermissionOverwriteTypeRole, 0, discordgo.PermissionViewChannel)
|
var permissionOverwrites []discord.PermissionOverwrite = []discord.PermissionOverwrite{
|
||||||
_, err = e.Client().Rest().UpdateChannel(ch.ID(), discord.GuildTextChannelUpdate{PermissionOverwrites: &[]discord.PermissionOverwrite{}})
|
discord.RolePermissionOverwrite{
|
||||||
if err != nil {
|
RoleID: guildID,
|
||||||
logrus.Error(err)
|
Deny: discord.PermissionViewChannel,
|
||||||
|
}}
|
||||||
|
|
||||||
|
if isIDRole(client, guildID, moderator) {
|
||||||
|
permissionOverwrites = append(permissionOverwrites, discord.RolePermissionOverwrite{
|
||||||
|
RoleID: moderator,
|
||||||
|
Allow: discord.PermissionViewChannel,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
permissionOverwrites = append(permissionOverwrites, discord.MemberPermissionOverwrite{
|
||||||
|
UserID: moderator,
|
||||||
|
Allow: discord.PermissionViewChannel,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
modType := discordgo.PermissionOverwriteTypeMember
|
permissionOverwrites = append(permissionOverwrites, discord.RolePermissionOverwrite{
|
||||||
if isIDRole(i.GuildID, moderator) {
|
RoleID: author,
|
||||||
modType = discordgo.PermissionOverwriteTypeRole
|
Allow: discord.PermissionViewChannel,
|
||||||
}
|
|
||||||
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,
|
|
||||||
})
|
})
|
||||||
|
_, err = client.Rest().UpdateChannel(ch.ID(), discord.GuildTextChannelUpdate{PermissionOverwrites: &permissionOverwrites})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
respond(i.Interaction, "Created channel <#"+ch.ID+">", true)
|
modTypeChar := ""
|
||||||
|
if isIDRole(client, guildID, moderator) {
|
||||||
|
modTypeChar = "&"
|
||||||
|
}
|
||||||
|
_, err = client.Rest().CreateMessage(ch.ID(), discord.NewMessageCreateBuilder().
|
||||||
|
SetContent("<@"+modTypeChar+moderator.String()+"> <@"+author.String()+">").SetEmbeds(embed).
|
||||||
|
Build())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFormButtonIDs() []string {
|
func getFormButtonIDs() []string {
|
||||||
|
29
cmd_info.go
29
cmd_info.go
@@ -92,14 +92,15 @@ var cmd_userinfo Command = Command{
|
|||||||
embedBuilder.AddField("Accent color", strconv.Itoa(*user.AccentColor), true)
|
embedBuilder.AddField("Accent color", strconv.Itoa(*user.AccentColor), true)
|
||||||
}
|
}
|
||||||
if user.AvatarDecorationURL() != nil {
|
if user.AvatarDecorationURL() != nil {
|
||||||
decoration := strings.TrimSuffix(*user.AvatarDecorationURL(), ".gif")
|
value := fmt.Sprintf("[PNG (animated)](%s)\n[PNG](%s)", *user.AvatarDecorationURL(), *user.AvatarDecorationURL()+"?passthrough=false")
|
||||||
value := fmt.Sprintf("[PNG (animated)](%s)\n[PNG](%s)", decoration, decoration+"?passthrough=false")
|
|
||||||
embedBuilder.AddField("Avatar decoration", value, true)
|
embedBuilder.AddField("Avatar decoration", value, true)
|
||||||
}
|
}
|
||||||
creation := "<:discord_member:1224717530078253166> " + discord.TimestampStyleLongDateTime.FormatTime(user.CreatedAt()) + "-" + discord.TimestampStyleRelative.FormatTime(user.CreatedAt())
|
creation := "<:discord_member:1224717530078253166> " + discord.TimestampStyleLongDateTime.FormatTime(user.CreatedAt()) + "-" + discord.TimestampStyleRelative.FormatTime(user.CreatedAt())
|
||||||
embedBuilder.AddField("Created at", creation, false)
|
embedBuilder.AddField("Created at", creation, false)
|
||||||
|
|
||||||
if user.BannerURL() != nil {
|
if user.BannerURL() != nil {
|
||||||
embedBuilder.SetImage(*user.BannerURL())
|
value := fmt.Sprint(*user.BannerURL())
|
||||||
|
embedBuilder.SetImage(value)
|
||||||
}
|
}
|
||||||
embedBuilder.SetTitle("User info")
|
embedBuilder.SetTitle("User info")
|
||||||
embedBuilder.SetDescription(user.Mention())
|
embedBuilder.SetDescription(user.Mention())
|
||||||
@@ -134,22 +135,22 @@ func fetchFlagStrings(user discord.User) string {
|
|||||||
userHasFlagsString += flagName + ", "
|
userHasFlagsString += flagName + ", "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if noNullString(user.AvatarDecorationData.Asset) == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
|
if user.AvatarDecorationData != nil && user.AvatarDecorationData.Asset == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
|
||||||
userHasFlagsString += "<:Limited_Lootbox_Clown:1224714172705804300>[`Lootbox Clown`](https://discord.com/settings/Lootboxes)"
|
userHasFlagsString += "<:Limited_Lootbox_Clown:1224714172705804300>[`Lootbox Clown`](https://discord.com/settings/Lootboxes)"
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if user.PremiumType > 0 {
|
if user.PremiumType > 0 {
|
||||||
userHasFlagsString += "<:Nitro:1224708672492666943>[`Nitro`](https://discord.com/settings/premium), "
|
userHasFlagsString += "<:Nitro:1224708672492666943>[`Nitro`](https://discord.com/settings/premium), "
|
||||||
}
|
}
|
||||||
if user.Bot {
|
if user.Bot {
|
||||||
appuser := bot.State.Application
|
appuser := bot.State.Application
|
||||||
if appuser.Flags&1<<23 != 0 {
|
if appuser.Flags&1<<23 != 0 {
|
||||||
userHasFlagsString += "<:Supports_Commands:1224848976201646100>[`Supports Commands`](https://discord.com/blog/welcome-to-the-new-era-of-discord-apps?ref=badge)"
|
userHasFlagsString += "<:Supports_Commands:1224848976201646100>[`Supports Commands`](https://discord.com/blog/welcome-to-the-new-era-of-discord-apps?ref=badge)"
|
||||||
}
|
}
|
||||||
if appuser.Flags&1<<6 != 0 {
|
if appuser.Flags&1<<6 != 0 {
|
||||||
userHasFlagsString += "<:Uses_Automod:1224862880982106202>`Uses Automod`"
|
userHasFlagsString += "<:Uses_Automod:1224862880982106202>`Uses Automod`"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
returnString := strings.TrimSuffix(userHasFlagsString, ", ")
|
returnString := strings.TrimSuffix(userHasFlagsString, ", ")
|
||||||
return returnString
|
return returnString
|
||||||
|
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/vaporvee/acecore
|
|||||||
go 1.21.6
|
go 1.21.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/disgoorg/disgo v0.18.0
|
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86
|
||||||
github.com/disgoorg/json v1.1.0
|
github.com/disgoorg/json v1.1.0
|
||||||
github.com/disgoorg/snowflake/v2 v2.0.1
|
github.com/disgoorg/snowflake/v2 v2.0.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
2
go.sum
2
go.sum
@@ -5,6 +5,8 @@ github.com/disgoorg/disgo v0.17.2 h1:RxiLq8guMtk+9tArFwve02iya2APQ9yZVtV30ySKNtw
|
|||||||
github.com/disgoorg/disgo v0.17.2/go.mod h1:8r3h9fXSz7BbACxLPsPbtB6LX8gaQFUETgPKV/0gAKQ=
|
github.com/disgoorg/disgo v0.17.2/go.mod h1:8r3h9fXSz7BbACxLPsPbtB6LX8gaQFUETgPKV/0gAKQ=
|
||||||
github.com/disgoorg/disgo v0.18.0 h1:EviKy/OiGofYW2X4kLjgxAUYrqjmBEMpVp/MMXHP1pY=
|
github.com/disgoorg/disgo v0.18.0 h1:EviKy/OiGofYW2X4kLjgxAUYrqjmBEMpVp/MMXHP1pY=
|
||||||
github.com/disgoorg/disgo v0.18.0/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
github.com/disgoorg/disgo v0.18.0/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
||||||
|
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86 h1:hSRIjnKWL07TYxvZRxdSBpS78gJNf+JkAuzXY3O1Kos=
|
||||||
|
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
||||||
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
|
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
|
||||||
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
||||||
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
||||||
|
@@ -26,7 +26,7 @@ type Command struct {
|
|||||||
AllowDM bool
|
AllowDM bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke /*, cmd_ticket_form, cmd_autojoinroles, cmd_autopublish*/}
|
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form /*, cmd_autojoinroles, cmd_autopublish*/}
|
||||||
|
|
||||||
func ready(e *events.Ready) {
|
func ready(e *events.Ready) {
|
||||||
logrus.Info("Starting up...")
|
logrus.Info("Starting up...")
|
||||||
|
2
main.go
2
main.go
@@ -49,8 +49,8 @@ func main() {
|
|||||||
bot.WithEventListenerFunc(componentInteractionCreate),
|
bot.WithEventListenerFunc(componentInteractionCreate),
|
||||||
bot.WithEventListenerFunc(modalSubmitInteractionCreate),
|
bot.WithEventListenerFunc(modalSubmitInteractionCreate),
|
||||||
bot.WithEventListenerFunc(messageCreate),
|
bot.WithEventListenerFunc(messageCreate),
|
||||||
|
bot.WithEventListenerFunc(messageDelete),
|
||||||
/*
|
/*
|
||||||
bot.WithEventListenerFunc(messageDelete),
|
|
||||||
bot.WithEventListenerFunc(guildMemberJoin),
|
bot.WithEventListenerFunc(guildMemberJoin),
|
||||||
*/
|
*/
|
||||||
)
|
)
|
||||||
|
16
tool.go
16
tool.go
@@ -51,7 +51,7 @@ func noNullString(in interface{}) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonStringShowModal(userID string, manageID string, formID string, overwrite ...string) discord.InteractionResponse {
|
func jsonStringBuildModal(userID string, manageID string, formID string, overwrite ...string) discord.ModalCreate {
|
||||||
var modal ModalJson = getModalByFormID(formID)
|
var modal ModalJson = getModalByFormID(formID)
|
||||||
var components []discord.ContainerComponent
|
var components []discord.ContainerComponent
|
||||||
for index, component := range modal.Form {
|
for index, component := range modal.Form {
|
||||||
@@ -76,13 +76,10 @@ func jsonStringShowModal(userID string, manageID string, formID string, overwrit
|
|||||||
modal.Title = overwrite[0]
|
modal.Title = overwrite[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return discord.InteractionResponse{
|
return discord.ModalCreate{
|
||||||
Type: discord.InteractionResponseTypeModal,
|
CustomID: "form:" + manageID + ":" + userID,
|
||||||
Data: &discord.ModalCreate{
|
Title: modal.Title,
|
||||||
CustomID: manageID + ":" + userID,
|
Components: components,
|
||||||
Title: modal.Title,
|
|
||||||
Components: components,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -94,6 +91,9 @@ var formTemplates embed.FS
|
|||||||
|
|
||||||
func getModalByFormID(formID string) ModalJson {
|
func getModalByFormID(formID string) ModalJson {
|
||||||
var modal ModalJson
|
var modal ModalJson
|
||||||
|
if formID == "" {
|
||||||
|
return modal
|
||||||
|
}
|
||||||
entries, err := formTemplates.ReadDir("form_templates")
|
entries, err := formTemplates.ReadDir("form_templates")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
|
Reference in New Issue
Block a user