From d308a2cfc8418895e6a40afc641273171abe3923 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 14 Apr 2024 16:15:57 +0200 Subject: [PATCH] fixed customization module implementation --- cmd_ask.go | 3 ++- cmd_cat.go | 3 ++- cmd_form.go | 11 ++++++----- cmd_info.go | 3 ++- cmd_ping.go | 3 ++- cmd_sticky.go | 3 ++- config.go | 9 --------- handlers.go | 3 ++- tool.go | 10 ---------- 9 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 config.go diff --git a/cmd_ask.go b/cmd_ask.go index 902393c..794db2c 100644 --- a/cmd_ask.go +++ b/cmd_ask.go @@ -4,6 +4,7 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) var cmd_ask = Command{ @@ -29,7 +30,7 @@ var cmd_ask = Command{ }, Interact: func(e *events.ApplicationCommandInteractionCreate) { err := e.CreateMessage(discord.NewMessageCreateBuilder(). - AddEmbeds(discord.NewEmbedBuilder().SetImage(simpleGetFromAPI("image", "https://yesno.wtf/api").(string)).SetColor(hexToDecimal(color["primary"])).Build()). + AddEmbeds(discord.NewEmbedBuilder().SetImage(simpleGetFromAPI("image", "https://yesno.wtf/api").(string)).SetColor(custom.GetColor("primary")).Build()). Build()) if err != nil { logrus.Error(err) diff --git a/cmd_cat.go b/cmd_cat.go index a1e7032..1cc36b8 100644 --- a/cmd_cat.go +++ b/cmd_cat.go @@ -8,6 +8,7 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) var cmd_cat = Command{ @@ -28,7 +29,7 @@ var cmd_cat = Command{ cat, err := GetCatImageURL() if err == nil { err = e.CreateMessage(discord.NewMessageCreateBuilder(). - AddEmbeds(discord.NewEmbedBuilder().SetDescription(cat.Fact).SetImage(cat.Image).SetColor(hexToDecimal(color["primary"])).Build()). + AddEmbeds(discord.NewEmbedBuilder().SetDescription(cat.Fact).SetImage(cat.Image).SetColor(custom.GetColor("primary")).Build()). Build()) if err != nil { logrus.Error(err) diff --git a/cmd_form.go b/cmd_form.go index 186f979..d802993 100644 --- a/cmd_form.go +++ b/cmd_form.go @@ -12,6 +12,7 @@ import ( "github.com/disgoorg/snowflake/v2" "github.com/google/uuid" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) var cmd_form Command = Command{ @@ -141,7 +142,7 @@ var cmd_form Command = Command{ exists = getFormManageIdExists(formManageID) } messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder(). - SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(hexToDecimal(color["primary"])). + SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(custom.GetColor("primary")). Build()).SetContainerComponents(discord.ActionRowComponent{ discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{ Name: "anim_rocket", @@ -243,7 +244,7 @@ var cmd_form Command = Command{ if result.CommentCategoryID != "" { channel := createFormComment(form_manage_id, e.User().ID, snowflake.MustParse(result.ModeratorID), "answer", discord.NewEmbedBuilder(). SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("This is the submitted result"). - SetColor(hexToDecimal(color["primary"])).SetFields(fields...). + SetColor(custom.GetColor("primary")).SetFields(fields...). Build(), *e.GuildID(), e.Client()) err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Created channel " + discord.ChannelMention(channel.ID())).SetEphemeral(true).Build()) if err != nil { @@ -259,7 +260,7 @@ var cmd_form Command = Command{ _, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.ResultChannelID), discord.NewMessageCreateBuilder(). SetEmbeds(discord.NewEmbedBuilder(). SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("This is the submitted result"). - SetColor(hexToDecimal(color["primary"])).SetFields(fields...). + SetColor(custom.GetColor("primary")).SetFields(fields...). Build()). SetContainerComponents(discord.NewActionRow(discord. NewButton(discord.ButtonStylePrimary, "Comment", "form:"+form_manage_id+";comment", ""). @@ -289,7 +290,7 @@ var cmd_form Command = Command{ _, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.AcceptChannelID), discord.NewMessageCreateBuilder(). SetEmbeds(discord.NewEmbedBuilder(). SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("**This submission needs approval.**"). - SetColor(hexToDecimal(color["primary"])).SetFields(fields...). + SetColor(custom.GetColor("primary")).SetFields(fields...). Build()). SetContainerComponents(discord.NewActionRow(buttons...)). Build()) @@ -370,7 +371,7 @@ var cmd_ticket_form Command = Command{ exists = getFormManageIdExists(formManageID) } messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder(). - SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(hexToDecimal(color["primary"])). + SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(custom.GetColor("primary")). Build()).SetContainerComponents(discord.ActionRowComponent{ discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{ Name: "anim_rocket", diff --git a/cmd_info.go b/cmd_info.go index 2c81bb4..fdcd667 100644 --- a/cmd_info.go +++ b/cmd_info.go @@ -8,6 +8,7 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) type UserExtend struct { @@ -115,7 +116,7 @@ var cmd_userinfo Command = Command{ } embedBuilder.SetTitle("User info") embedBuilder.SetDescription(user.Mention()) - embedBuilder.SetColor(hexToDecimal(color["primary"])) + embedBuilder.SetColor(custom.GetColor("primary")) err = e.CreateMessage(discord.NewMessageCreateBuilder(). SetEmbeds(embedBuilder.Build()). Build()) diff --git a/cmd_ping.go b/cmd_ping.go index 9c39c32..15e50f6 100644 --- a/cmd_ping.go +++ b/cmd_ping.go @@ -8,6 +8,7 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) var cmd_ping Command = Command{ @@ -55,7 +56,7 @@ var cmd_ping Command = Command{ SetEmbeds(discord.NewEmbedBuilder(). SetTitle(app.Bot.Username + " ping"). SetDescription(fmt.Sprintf("# %.2fms", ping.Seconds()*1000)). - SetColor(hexToDecimal(color[pingColor])).Build()).SetEphemeral(true).Build()) + SetColor(custom.GetColor(pingColor)).Build()).SetEphemeral(true).Build()) if err != nil { logrus.Error(err) } diff --git a/cmd_sticky.go b/cmd_sticky.go index a9e8728..ab8ef7b 100644 --- a/cmd_sticky.go +++ b/cmd_sticky.go @@ -6,6 +6,7 @@ import ( "github.com/disgoorg/json" "github.com/disgoorg/snowflake/v2" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) var cmd_sticky Command = Command{ @@ -85,7 +86,7 @@ func inputStickyMessage(e *events.ApplicationCommandInteractionCreate) { } } else { message, err := e.Client().Rest().CreateMessage(e.Channel().ID(), discord.MessageCreate{Embeds: []discord.Embed{ - {Description: messageText, Footer: &discord.EmbedFooter{Text: "📌 Sticky message"}, Color: hexToDecimal(color["primary"])}}}) + {Description: messageText, Footer: &discord.EmbedFooter{Text: "📌 Sticky message"}, Color: custom.GetColor("primary")}}}) if err != nil { logrus.Error(err) } diff --git a/config.go b/config.go deleted file mode 100644 index cd35448..0000000 --- a/config.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -var color map[string]string = map[string]string{ - "red": "#FF6B6B", - "yellow": "#FFD93D", - "green": "#6BCB77", - "blue": "#008DDA", - "primary": "#564BA0", -} diff --git a/handlers.go b/handlers.go index c729bab..d0f9f9c 100644 --- a/handlers.go +++ b/handlers.go @@ -11,6 +11,7 @@ import ( "github.com/disgoorg/disgo/events" "github.com/disgoorg/snowflake/v2" "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" ) type Command struct { @@ -155,7 +156,7 @@ func messageCreate(e *events.MessageCreate) { Footer: &discord.EmbedFooter{ Text: "📌 Sticky message", }, - Color: hexToDecimal(color["primary"]), + Color: custom.GetColor("primary"), Description: getStickyMessageContent(e.Message.GuildID.String(), e.Message.ChannelID.String()), }, }, diff --git a/tool.go b/tool.go index 6a73589..cefb796 100644 --- a/tool.go +++ b/tool.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "net/http" - "strconv" "strings" "github.com/disgoorg/disgo/bot" @@ -126,15 +125,6 @@ func getHighestRole(guildID string, c bot.Client) (*discord.Role, error) { return highestRole, nil } -func hexToDecimal(hexColor string) int { - hexColor = strings.TrimPrefix(hexColor, "#") - decimal, err := strconv.ParseInt(hexColor, 16, 64) - if err != nil { - return 0 - } - return int(decimal) -} - func simpleGetFromAPI(key string, url string) interface{} { client := &http.Client{} req, err := http.NewRequest("GET", url, nil)