continued porting to disgo...

This commit is contained in:
2024-04-09 23:21:08 +02:00
parent 01ac1ec363
commit b7f126efba
10 changed files with 284 additions and 379 deletions

View File

@@ -1,35 +1,30 @@
package main package main
/*
import ( import (
"github.com/bwmarrin/discordgo" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var cmd_ask Command = Command{ var cmd_ask = Command{
Definition: discordgo.ApplicationCommand{ Definition: discord.SlashCommandCreate{
Name: "ask", Name: "ask",
Description: "Ask anything and get a gif as response!", Description: "Ask anything and get a gif as response!",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionString{
Type: discordgo.ApplicationCommandOptionString,
Name: "question", Name: "question",
Description: "The question you want to ask", Description: "The question you want to ask",
Required: true, Required: true,
}, },
}, },
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
err := respondEmbed(i.Interaction, discordgo.MessageEmbed{ err := e.CreateMessage(discord.NewMessageCreateBuilder().
Type: discordgo.EmbedTypeImage, AddEmbeds(discord.NewEmbedBuilder().SetImage(simpleGetFromAPI("image", "https://yesno.wtf/api").(string)).SetColor(hexToDecimal(color["primary"])).Build()).
Color: hexToDecimal(color["primary"]), Build())
Image: &discordgo.MessageEmbedImage{
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
}}, false)
if err != nil { if err != nil {
logrus.Error("Failed to respond with embed: ", err) logrus.Error(err)
} }
}, },
AllowDM: true, AllowDM: true,
} }
*/

View File

@@ -1,25 +1,29 @@
package main package main
/* import (
var cmd_cat Command = Command{ "encoding/json"
Definition: discordgo.ApplicationCommand{ "io"
"net/http"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_cat = Command{
Definition: discord.SlashCommandCreate{
Name: "cat", Name: "cat",
Description: "Random cat pictures", Description: "Random cat pictures",
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
cat, err := GetCatImageURL() cat, err := GetCatImageURL()
if err == nil { if err == nil {
err := respondEmbed(i.Interaction, discordgo.MessageEmbed{ err = e.CreateMessage(discord.NewMessageCreateBuilder().
Type: discordgo.EmbedTypeImage, AddEmbeds(discord.NewEmbedBuilder().SetImage(cat).SetColor(hexToDecimal(color["primary"])).Build()).
Color: hexToDecimal(color["primary"]), Build())
Image: &discordgo.MessageEmbedImage{
URL: cat,
}}, false)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
} else {
logrus.Error(err)
} }
}, },
AllowDM: true, AllowDM: true,
@@ -44,4 +48,3 @@ func GetCatImageURL() (string, error) {
return "https://cataas.com/cat/" + images.ID, err return "https://cataas.com/cat/" + images.ID, err
} }
*/

View File

@@ -1,22 +1,24 @@
package main package main
/*
import ( import (
"github.com/bwmarrin/discordgo" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var cmd_dadjoke Command = Command{ var cmd_dadjoke = Command{
Definition: discordgo.ApplicationCommand{ Definition: discord.SlashCommandCreate{
Name: "dadjoke", Name: "dadjoke",
Description: "Gives you a random joke that is as bad as your dad would tell them", Description: "Gives you a random joke that is as bad as your dad would tell them",
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
err := respond(i.Interaction, simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string), false) joke := simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string)
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent(joke).
Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
}, },
AllowDM: true, AllowDM: true,
} }
*/

View File

@@ -1,65 +1,68 @@
package main package main
/* import (
"bytes"
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
var cmd_form Command = Command{ var cmd_form Command = Command{
Definition: discordgo.ApplicationCommand{ Definition: discord.SlashCommandCreate{
Name: "form", Name: "form",
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageChannels), DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels),
Description: "Create custom forms right inside Discord", Description: "Create custom forms right inside Discord",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionSubCommand{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "help", Name: "help",
Description: "Gives you a example file and demo for creating custom forms", Description: "Gives you an example file and demo for creating custom forms",
}, },
{ &discord.ApplicationCommandOptionSubCommand{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "custom", Name: "custom",
Description: "Create a new custom form right inside Discord", Description: "Create a new custom form right inside Discord",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionAttachment{
Type: discordgo.ApplicationCommandOptionAttachment,
Name: "json", Name: "json",
Description: "Your edited form file", Description: "Your edited form file",
Required: true, Required: true,
}, },
}, },
}, },
{ &discord.ApplicationCommandOptionSubCommand{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "add", Name: "add",
Description: "Adds existing forms to this channel", Description: "Adds existing forms to this channel",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionChannel{
Type: discordgo.ApplicationCommandOptionChannel,
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: []discord.ChannelType{discord.ChannelTypeGuildText},
}, },
{ &discord.ApplicationCommandOptionMentionable{
Type: discordgo.ApplicationCommandOptionMentionable,
Name: "moderator", Name: "moderator",
Description: "Who can interact with moderating buttons.", Description: "Who can interact with moderating buttons.",
}, },
{ &discord.ApplicationCommandOptionString{
Type: discordgo.ApplicationCommandOptionString,
Name: "type", Name: "type",
Description: "Which type of form you want to add", Description: "Which type of form you want to add",
Autocomplete: true, Autocomplete: true,
}, },
{ &discord.ApplicationCommandOptionString{
Type: discordgo.ApplicationCommandOptionString,
Name: "title", Name: "title",
Description: "The title the form should have", Description: "The title the form should have",
}, },
{ &discord.ApplicationCommandOptionChannel{
Type: discordgo.ApplicationCommandOptionChannel,
Name: "approve_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: []discord.ChannelType{discord.ChannelTypeGuildText},
}, },
{ &discord.ApplicationCommandOptionBool{
Type: discordgo.ApplicationCommandOptionBoolean,
Name: "mods_can_answer", 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",
}, },
@@ -67,8 +70,8 @@ var cmd_form Command = Command{
}, },
}, },
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name { switch *e.SlashCommandInteractionData().SubCommandName {
case "help": case "help":
fileData, err := formTemplates.ReadFile("form_templates/form_demo.json") fileData, err := formTemplates.ReadFile("form_templates/form_demo.json")
if err != nil { if err != nil {
@@ -76,39 +79,18 @@ var cmd_form Command = Command{
return return
} }
fileReader := bytes.NewReader(fileData) fileReader := bytes.NewReader(fileData)
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ err = e.CreateMessage(discord.NewMessageCreateBuilder().
Type: discordgo.InteractionResponseChannelMessageWithSource, SetContent("NOT SUPPORTED YET!(use `/form add` instead)\n\nGet the example file edit it (make sure to have a unique \"form_type\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.").
Data: &discordgo.InteractionResponseData{ SetFiles(discord.NewFile("example.json", "json", fileReader)).
Content: "NOT SUPPORTED YET!(use `/form add` instead)\n\nGet the example file edit it (make sure to have a unique \"form_type\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.", SetContainerComponents(discord.ActionRowComponent{discord.NewPrimaryButton("Demo", "form_demo").WithEmoji(discord.ComponentEmoji{Name: "📑"})}).SetEphemeral(true).
Flags: discordgo.MessageFlagsEphemeral, Build())
Files: []*discordgo.File{
{
Name: "example.json",
ContentType: "json",
Reader: fileReader,
},
},
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
Emoji: discordgo.ComponentEmoji{
Name: "📑",
},
CustomID: "form_demo",
Label: "Demo",
Style: discordgo.PrimaryButton,
},
},
},
},
},
})
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
case "custom": case "custom":
err := respond(i.Interaction, "Feature not available yet use `/form add` instead", true) err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent("Feature not available yet use `/form add` instead").SetEphemeral(true).
Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
@@ -116,30 +98,21 @@ 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 := i.Member.User.ID moderator := e.Member().User.ID.String()
if i.ApplicationCommandData().Options != nil { data := e.SlashCommandInteractionData()
options := i.ApplicationCommandData().Options[0] resultChannelID = data.Channel("result_channel").ID.String()
for _, opt := range options.Options { moderator = data.Role("moderator").ID.String()
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 == "" { if moderator == "" {
moderator = opt.UserValue(s).ID moderator = data.User("moderator").ID.String()
}
}
} }
formID = data.String("type")
overwriteTitle = data.String("title")
if overwriteTitle != "" {
title = overwriteTitle
} }
acceptChannelID = data.Channel("accept_channel").ID.String()
modsCanAnswer = data.Bool("mods_can_answer")
if formID == "" { if formID == "" {
formID = "template_general" formID = "template_general"
} }
@@ -159,44 +132,29 @@ var cmd_form Command = Command{
formManageID = uuid.New() formManageID = uuid.New()
exists = getFormManageIdExists(formManageID) exists = getFormManageIdExists(formManageID)
} }
messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder().
message, err := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{ SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(hexToDecimal(color["primary"])).
Embed: &discordgo.MessageEmbed{ Build()).SetContainerComponents(discord.ActionRowComponent{
Color: hexToDecimal(color["primary"]), discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{
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", Name: "anim_rocket",
ID: "1215740398706757743", ID: snowflake.MustParse("1215740398706757743"),
Animated: true, Animated: true,
}, })}).
}, Build()
}, message, err := e.Client().Rest().CreateMessage(e.Channel().ID(), messagebuild)
},
},
})
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return
} }
var category string var category string
if modsCanAnswer { if modsCanAnswer {
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()
} }
addFormButton(i.GuildID, i.ChannelID, message.ID, 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 = respond(i.Interaction, "Successfully added form button!", true) err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Successfully added form button!").SetEphemeral(true).Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
@@ -204,36 +162,36 @@ var cmd_form Command = Command{
}, },
DynamicComponentIDs: func() []string { return getFormButtonIDs() }, DynamicComponentIDs: func() []string { return getFormButtonIDs() },
DynamicModalIDs: func() []string { return getFormButtonIDs() }, DynamicModalIDs: func() []string { return getFormButtonIDs() },
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) { ComponentInteract: func(e *events.ComponentInteractionCreate) {
if strings.ContainsAny(i.MessageComponentData().CustomID, ";") { if e.Data.Type() == discord.ComponentTypeButton {
var form_manage_id string = strings.TrimPrefix(strings.Split(i.MessageComponentData().CustomID, ";")[0], "form:") if strings.ContainsAny(e.ButtonInteractionData().CustomID(), ";") {
switch strings.Split(i.MessageComponentData().CustomID, ";")[1] { var form_manage_id string = strings.TrimPrefix(strings.Split(e.ButtonInteractionData().CustomID(), ";")[0], "form:")
switch strings.Split(e.ButtonInteractionData().CustomID(), ";")[1] {
case "decline": case "decline":
err := s.ChannelMessageDelete(i.ChannelID, i.Message.ID) err := e.Client().Rest().DeleteMessage(e.Channel().ID(), e.Message.ID)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
respond(i.Interaction, "Submission declined!", true) e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission declined!").SetEphemeral(true).Build())
case "approve": case "approve":
embed := i.Message.Embeds[0] embed := e.Message.Embeds[0]
embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", i.Member.User.ID) embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", e.Member().User.ID)
_, err := s.ChannelMessageSendComplex(getFormResultValues(form_manage_id).ResultChannelID, &discordgo.MessageSend{ _, err := e.Client().Rest().CreateMessage(snowflake.MustParse(getFormResultValues(form_manage_id).ResultChannelID), discord.NewMessageCreateBuilder().
Embed: embed, SetEmbeds(embed).
}) Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
respond(i.Interaction, "Submission accepted!", true) e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission accepted!").SetEphemeral(true).Build())
err = s.ChannelMessageDelete(i.ChannelID, i.Message.ID) err = e.Client().Rest().DeleteMessage(e.Channel().ID(), e.Message.ID)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
case "comment": case "comment":
author := strings.TrimSuffix(strings.Split(i.Message.Embeds[0].Fields[len(i.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 := i.Message.Embeds[0] embed := e.Message.Embeds[0]
moderator := i.Member.User.ID moderator := e.Member().User.ID
createFormComment(form_manage_id, author, moderator, "answer", embed, i) createFormComment(form_manage_id, author, moderator, "answer", embed, e)
} }
} else { } else {
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") { if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
@@ -243,6 +201,7 @@ var cmd_form Command = Command{
jsonStringShowModal(i.Interaction, "form_demo", "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 !strings.HasPrefix(i.ModalSubmitData().CustomID, "form_demo") { if !strings.HasPrefix(i.ModalSubmitData().CustomID, "form_demo") {
@@ -507,18 +466,18 @@ 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 string, commentName string, embed *discordgo.MessageEmbed, i *discordgo.InteractionCreate) { func createFormComment(form_manage_id string, author string, moderator snowflake.ID, commentName string, embed discord.Embed, e *events.ComponentInteractionCreate) {
category := getFormResultValues(form_manage_id).CommentCategoryID var category snowflake.ID
_, err := bot.Channel(category) _, err := e.Client().Rest().GetChannel(snowflake.MustParse(getFormResultValues(form_manage_id).CommentCategoryID))
if err != nil { if err != nil {
c, err := bot.GuildChannelCreate(i.GuildID, strings.Trim(embed.Title, "\"")+" mod "+commentName+"s", discordgo.ChannelTypeGuildCategory) c, err := e.Client().Rest().CreateGuildChannel(*e.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, c.ID) updateFormCommentCategory(form_manage_id, category.String())
} }
ch, err := bot.GuildChannelCreateComplex(i.GuildID, discordgo.GuildChannelCreateData{ ch, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildTextChannelCreate{
ParentID: category, ParentID: category,
Name: strings.ToLower(embed.Author.Name) + "-" + commentName, Name: strings.ToLower(embed.Author.Name) + "-" + commentName,
}) })
@@ -526,6 +485,7 @@ func createFormComment(form_manage_id string, author string, moderator string, c
logrus.Error(err) logrus.Error(err)
} }
err = bot.ChannelPermissionSet(ch.ID, i.GuildID, discordgo.PermissionOverwriteTypeRole, 0, discordgo.PermissionViewChannel) err = bot.ChannelPermissionSet(ch.ID, i.GuildID, discordgo.PermissionOverwriteTypeRole, 0, discordgo.PermissionViewChannel)
_, err = e.Client().Rest().UpdateChannel(ch.ID(), discord.GuildTextChannelUpdate{PermissionOverwrites: &[]discord.PermissionOverwrite{}})
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
@@ -563,4 +523,3 @@ func getFormButtonIDs() []string {
} }
return IDs return IDs
} }
*/

View File

@@ -1,17 +1,12 @@
package main package main
/*
import ( import (
"encoding/json"
"fmt" "fmt"
"io"
"net/http"
"os"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/bwmarrin/discordgo" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@@ -25,128 +20,98 @@ type AvatarDecoration struct {
URL string URL string
} }
var userFlagsString map[discordgo.UserFlags]string = map[discordgo.UserFlags]string{ var userFlagsString map[discord.UserFlags]string = map[discord.UserFlags]string{
discordgo.UserFlagDiscordEmployee: "<:Discord_Employee:1224708831419043942>[`Discord Employee`](https://discord.com/company)", discord.UserFlagDiscordEmployee: "<:Discord_Employee:1224708831419043942>[`Discord Employee`](https://discord.com/company)",
discordgo.UserFlagDiscordPartner: "<:Discord_Partner:1224708689190060092>[`Discord Partner`](https://discord.com/partners)", discord.UserFlagPartneredServerOwner: "<:Discord_Partner:1224708689190060092>[`Discord Partner`](https://discord.com/partners)",
discordgo.UserFlagHypeSquadEvents: "<:Hypesquad_Events:1224708685494747237>[`HypeSquad Events`](https://discord.com/hypesquad)", discord.UserFlagHypeSquadEvents: "<:Hypesquad_Events:1224708685494747237>[`HypeSquad Events`](https://discord.com/hypesquad)",
discordgo.UserFlagBugHunterLevel1: "<:Bug_Hunter_Level_1:1224708828415918231>[`Bug Hunter Level 1`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)", discord.UserFlagBugHunterLevel1: "<:Bug_Hunter_Level_1:1224708828415918231>[`Bug Hunter Level 1`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discordgo.UserFlagHouseBravery: "<:Hypesquad_Bravery:1224708678905630801>[`HypeSquad Bravery`](https://discord.com/settings/hypesquad-online)", discord.UserFlagHouseBravery: "<:Hypesquad_Bravery:1224708678905630801>[`HypeSquad Bravery`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagHouseBrilliance: "<:Hypesquad_Brilliance:1224708677584424961>[`HypeSquad Brilliance`](https://discord.com/settings/hypesquad-online)", discord.UserFlagHouseBrilliance: "<:Hypesquad_Brilliance:1224708677584424961>[`HypeSquad Brilliance`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagHouseBalance: "<:Hypequad_Balance:1224708826901516309>[`HypeSquad Balance`](https://discord.com/settings/hypesquad-online)", discord.UserFlagHouseBalance: "<:Hypequad_Balance:1224708826901516309>[`HypeSquad Balance`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagEarlySupporter: "<:Early_Supporter:1224708674065272873>[`Early Supporter`](https://discord.com/settings/premium)", discord.UserFlagEarlySupporter: "<:Early_Supporter:1224708674065272873>[`Early Supporter`](https://discord.com/settings/premium)",
discordgo.UserFlagTeamUser: "`TeamUser`", discord.UserFlagTeamUser: "`TeamUser`",
discordgo.UserFlagSystem: "", discord.UserFlagBugHunterLevel2: "<:Bug_Hunter_Level_2:1224708682378383461>[`Bug Hunter Level 2`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discordgo.UserFlagBugHunterLevel2: "<:Bug_Hunter_Level_2:1224708682378383461>[`Bug Hunter Level 2`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)", discord.UserFlagVerifiedBot: "",
discordgo.UserFlagVerifiedBot: "", discord.UserFlagEarlyVerifiedBotDeveloper: "<:Early_Verified_Bot_Developer:1224708675294203934>`Early Verified Bot Developer`",
discordgo.UserFlagVerifiedBotDeveloper: "<:Early_Verified_Bot_Developer:1224708675294203934>`Early Verified Bot Developer`", discord.UserFlagDiscordCertifiedModerator: "<:Discord_Certified_Moderator:1224708830223532124>[`Discord Certified Moderator`](https://discord.com/safety)",
discordgo.UserFlagDiscordCertifiedModerator: "<:Discord_Certified_Moderator:1224708830223532124>[`Discord Certified Moderator`](https://discord.com/safety)", discord.UserFlagBotHTTPInteractions: "`BotHTTPInteractions`",
1 << 19: "`BotHTTPInteractions`", discord.UserFlagActiveDeveloper: "<:Active_Developer:1224708676611215380>[`Active Developer`](https://support-dev.discord.com/hc/en-us/articles/10113997751447?ref=badge)",
1 << 22: "<:Active_Developer:1224708676611215380>[`Active Developer`](https://support-dev.discord.com/hc/en-us/articles/10113997751447?ref=badge)",
} }
var cmd_userinfo Command = Command{ var cmd_userinfo Command = Command{
Definition: discordgo.ApplicationCommand{ Definition: discord.SlashCommandCreate{
Name: "info", Name: "info",
Description: "Gives you information about a user or this bot.", Description: "Gives you information about a user or this bot.",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionSubCommand{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "user", Name: "user",
Description: "Gives you information about a user and its profile images.", Description: "Gives you information about a user and its profile images.",
Options: []*discordgo.ApplicationCommandOption{ Options: []discord.ApplicationCommandOption{
{ &discord.ApplicationCommandOptionUser{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user", Name: "user",
Description: "The user you need information about.", Description: "The user you need information about.",
Required: true, Required: true,
}, },
}, },
}, },
{ &discord.ApplicationCommandOptionSubCommand{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "bot-service", Name: "bot-service",
Description: "Gives you information about this bot's server service.", Description: "Gives you information about this bot's server service.",
}, },
}, },
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name { switch *e.SlashCommandInteractionData().SubCommandName {
case "user": case "user":
var user *discordgo.User = i.ApplicationCommandData().Options[0].Options[0].UserValue(s) var user discord.User = e.SlashCommandInteractionData().User("user")
var extendedUser UserExtend = extendedUserFromAPI(user.ID) var userHasFlags string = fetchFlagStrings(user)
var userHasFlags string = fetchFlagStrings(user, extendedUser.AvatarDecorationData.Asset)
var userType string = "User" var userType string = "User"
if user.Bot { if user.Bot {
userType = "Unverified Bot" userType = "Unverified Bot"
if user.PublicFlags&discordgo.UserFlagVerifiedBot != 0 { if user.PublicFlags&discord.UserFlagVerifiedBot != 0 {
userType = "Verified Bot" userType = "Verified Bot"
} }
} else if user.System { } else if user.System {
userType = "System" userType = "System"
} }
createdate, err := discordgo.SnowflakeTimestamp(user.ID) embedBuilder := discord.NewEmbedBuilder()
if err != nil { embedBuilder.SetThumbnail(checkDefaultPb(user))
logrus.Error(err) embedBuilder.AddField("ID", user.ID.String(), false)
} embedBuilder.AddField("Type", userType, true)
err = respondEmbed(i.Interaction, discordgo.MessageEmbed{ if user.GlobalName != nil {
Title: extendedUser.GlobalName + " user info", embedBuilder.AddField("Global name", *user.GlobalName, true)
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: user.AvatarURL("512")}, }
Description: user.Mention(), embedBuilder.AddField("Username", user.Username, true)
Type: discordgo.EmbedTypeArticle, if userHasFlags != "" {
Fields: []*discordgo.MessageEmbedField{ embedBuilder.AddField("Badges", userHasFlags, false)
{ }
Name: "test", if user.Discriminator != "0" {
Value: fmt.Sprint(s.State.Application.BotPublic), embedBuilder.AddField("Discriminator", user.Discriminator, false)
}, }
{ if user.AccentColor != nil {
Name: "ID", embedBuilder.AddField("Accent color", strconv.Itoa(*user.AccentColor), true)
Value: user.ID, }
}, if user.AvatarDecorationURL() != nil {
{ decoration := strings.TrimSuffix(*user.AvatarDecorationURL(), ".gif")
Name: "Type", value := fmt.Sprintf("[PNG (animated)](%s)\n[PNG](%s)", decoration, decoration+"?passthrough=false")
Value: userType, embedBuilder.AddField("Avatar decoration", value, true)
Inline: true, }
}, creation := "<:discord_member:1224717530078253166> " + discord.TimestampStyleLongDateTime.FormatTime(user.CreatedAt()) + "-" + discord.TimestampStyleRelative.FormatTime(user.CreatedAt())
{ embedBuilder.AddField("Created at", creation, false)
Name: "Global name", if user.BannerURL() != nil {
Value: extendedUser.GlobalName, embedBuilder.SetImage(*user.BannerURL())
Inline: true, }
}, embedBuilder.SetTitle("User info")
{ embedBuilder.SetDescription(user.Mention())
Name: "Username", embedBuilder.SetColor(hexToDecimal(color["primary"]))
Value: user.Username, embedBuilder.SetFooterText("Currently a bit broken because of Discord's constant user API changes")
Inline: true, err := e.CreateMessage(discord.NewMessageCreateBuilder().
}, SetEmbeds(embedBuilder.Build()).
{ Build())
Name: "Badges",
Value: userHasFlags,
},
{
Name: "Discriminator",
Value: user.Discriminator,
Inline: true,
},
{
Name: "Accent color",
Value: "#" + decimalToHex(user.AccentColor),
Inline: true,
},
{
Name: "Avatar Decoration",
Value: "[PNG (animated)](" + extendedUser.AvatarDecorationData.URL + ")\n[PNG](" + extendedUser.AvatarDecorationData.URL + "?size=4096&passthrough=false)\nSKU ID: `" + extendedUser.AvatarDecorationData.SkuID + "`",
Inline: true,
},
{
Name: "Created at",
Value: "<:discord_member:1224717530078253166> <t:" + fmt.Sprint(createdate.Unix()) + ":f> - <t:" + fmt.Sprint(createdate.Unix()) + ":R>",
},
},
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{URL: user.BannerURL("512")},
}, false)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
case "bot-service": case "bot-service":
} }
@@ -155,19 +120,27 @@ var cmd_userinfo Command = Command{
AllowDM: true, AllowDM: true,
} }
func fetchFlagStrings(user *discordgo.User, decorationAsset string) string { func checkDefaultPb(user discord.User) string {
if user.AvatarURL() == nil {
return "https://discord.com/assets/ac6f8cf36394c66e7651.png"
}
return *user.AvatarURL()
}
func fetchFlagStrings(user discord.User) string {
var userHasFlagsString string var userHasFlagsString string
for flag, flagName := range userFlagsString { for flag, flagName := range userFlagsString {
if user.PublicFlags&flag != 0 { if flag&user.PublicFlags != 0 {
userHasFlagsString += flagName + ", " userHasFlagsString += flagName + ", "
} }
} }
if noNullString(user.AvatarDecorationData.Asset) == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
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 decorationAsset == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
userHasFlagsString += "<:Limited_Lootbox_Clown:1224714172705804300>[`Lootbox Clown`](https://discord.com/settings/Lootboxes)"
}
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 {
@@ -177,60 +150,7 @@ func fetchFlagStrings(user *discordgo.User, decorationAsset string) string {
userHasFlagsString += "<:Uses_Automod:1224862880982106202>`Uses Automod`" userHasFlagsString += "<:Uses_Automod:1224862880982106202>`Uses Automod`"
} }
} }
*/
returnString := strings.TrimSuffix(userHasFlagsString, ", ") returnString := strings.TrimSuffix(userHasFlagsString, ", ")
return returnString return returnString
} }
func extendedUserFromAPI(userID string) UserExtend {
client := &http.Client{}
var userExtend UserExtend
req, err := http.NewRequest("GET", "https://discord.com/api/v10/users/"+userID, nil)
if err != nil {
logrus.Error(err)
return userExtend
}
req.Header.Add("Authorization", "Bot "+os.Getenv("BOT_TOKEN"))
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
logrus.Error(err)
return userExtend
}
defer res.Body.Close()
if res.StatusCode == http.StatusTooManyRequests {
retryAfter := parseRetryAfterHeader(res.Header)
if retryAfter > 0 {
time.Sleep(retryAfter)
}
}
body, err := io.ReadAll(res.Body)
if err != nil {
logrus.Error(err)
return userExtend
}
json.Unmarshal(body, &userExtend)
if userExtend.AvatarDecorationData.Asset != "" {
userExtend.AvatarDecorationData.URL = "https://cdn.discordapp.com/avatar-decoration-presets/" + userExtend.AvatarDecorationData.Asset + ".png"
}
return userExtend
}
func parseRetryAfterHeader(headers http.Header) time.Duration {
retryAfterStr := headers.Get("Retry-After")
if retryAfterStr == "" {
return 0
}
retryAfter, err := strconv.Atoi(retryAfterStr)
if err != nil {
return 0
}
return time.Duration(retryAfter) * time.Millisecond
}
*/

View File

@@ -1,28 +1,28 @@
package main package main
/*
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var cmd_ping Command = Command{ var cmd_ping Command = Command{
Definition: discordgo.ApplicationCommand{ Definition: discord.SlashCommandCreate{
Name: "ping", Name: "ping",
Description: "Returns the ping of the bot", Description: "Returns the ping of the bot",
}, },
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
start := time.Now() start := time.Now()
client := http.Client{ client := http.Client{
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
} }
resp, err := client.Get("https://discord.com/api/" + discordgo.APIVersion + "/gateway/bot") resp, err := client.Get("https://discord.com/api/v9/gateway/bot")
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return return
@@ -30,23 +30,26 @@ var cmd_ping Command = Command{
defer resp.Body.Close() defer resp.Body.Close()
ping := time.Since(start) ping := time.Since(start)
var ping_color string var pingColor string
if ping.Milliseconds() < 200 { if ping.Milliseconds() < 200 {
ping_color = "green" pingColor = "green"
} else if ping.Milliseconds() < 400 { } else if ping.Milliseconds() < 400 {
ping_color = "yellow" pingColor = "yellow"
} else { } else {
ping_color = "red" pingColor = "red"
} }
err = respondEmbed(i.Interaction, discordgo.MessageEmbed{ app, err := e.Client().Rest().GetCurrentApplication()
Title: s.State.User.Username + " ping", if err != nil {
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000), logrus.Error(err)
Type: discordgo.EmbedTypeArticle, }
Color: hexToDecimal(color[ping_color])}, true) err = e.CreateMessage(discord.NewMessageCreateBuilder().
SetEmbeds(discord.NewEmbedBuilder().
SetTitle(app.Bot.Username + " ping").
SetDescription(fmt.Sprintf("# %.2fms", ping.Seconds()*1000)).
SetColor(hexToDecimal(color[pingColor])).Build()).SetEphemeral(true).Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
}, },
AllowDM: true, AllowDM: true,
} }
*/

8
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/vaporvee/acecore
go 1.21.6 go 1.21.6
require ( require (
github.com/disgoorg/disgo v0.17.2 github.com/disgoorg/disgo v0.18.0
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
@@ -15,9 +15,9 @@ require (
require ( require (
github.com/gorilla/websocket v1.5.1 // indirect github.com/gorilla/websocket v1.5.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
golang.org/x/crypto v0.18.0 // indirect golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.20.0 // indirect golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.16.0 // indirect golang.org/x/sys v0.17.0 // indirect
) )
replace github.com/vaporvee/acecore/custom => ./custom replace github.com/vaporvee/acecore/custom => ./custom

8
go.sum
View File

@@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disgoorg/disgo v0.17.2 h1:RxiLq8guMtk+9tArFwve02iya2APQ9yZVtV30ySKNtw= 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/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=
@@ -27,11 +29,17 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@@ -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_form, cmd_ticket_form, cmd_dadjoke, cmd_ping, cmd_ask, cmd_cat, cmd_autojoinroles, cmd_autopublish, cmd_userinfo*/} 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...")

15
tool.go
View File

@@ -36,6 +36,21 @@ type MessageIDs struct {
ChannelID string ChannelID string
} }
func noNullString(in interface{}) string {
var s string = ""
var is_str bool
switch in.(type) {
case string:
is_str = true
case *string:
is_str = true
}
if in != nil && is_str {
s = fmt.Sprint(in)
}
return s
}
func jsonStringShowModal(userID string, manageID string, formID string, overwrite ...string) discord.InteractionResponse { func jsonStringShowModal(userID string, manageID string, formID string, overwrite ...string) discord.InteractionResponse {
var modal ModalJson = getModalByFormID(formID) var modal ModalJson = getModalByFormID(formID)
var components []discord.ContainerComponent var components []discord.ContainerComponent