fixed customization module implementation

This commit is contained in:
2024-04-14 16:15:57 +02:00
parent a0269f37f8
commit d308a2cfc8
9 changed files with 18 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
var cmd_ask = Command{ var cmd_ask = Command{
@@ -29,7 +30,7 @@ var cmd_ask = Command{
}, },
Interact: func(e *events.ApplicationCommandInteractionCreate) { Interact: func(e *events.ApplicationCommandInteractionCreate) {
err := e.CreateMessage(discord.NewMessageCreateBuilder(). 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()) Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)

View File

@@ -8,6 +8,7 @@ import (
"github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
var cmd_cat = Command{ var cmd_cat = Command{
@@ -28,7 +29,7 @@ var cmd_cat = Command{
cat, err := GetCatImageURL() cat, err := GetCatImageURL()
if err == nil { if err == nil {
err = e.CreateMessage(discord.NewMessageCreateBuilder(). 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()) Build())
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)

View File

@@ -12,6 +12,7 @@ import (
"github.com/disgoorg/snowflake/v2" "github.com/disgoorg/snowflake/v2"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
var cmd_form Command = Command{ var cmd_form Command = Command{
@@ -141,7 +142,7 @@ var cmd_form Command = Command{
exists = getFormManageIdExists(formManageID) exists = getFormManageIdExists(formManageID)
} }
messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder(). 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{ Build()).SetContainerComponents(discord.ActionRowComponent{
discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{ discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{
Name: "anim_rocket", Name: "anim_rocket",
@@ -243,7 +244,7 @@ var cmd_form Command = Command{
if result.CommentCategoryID != "" { if result.CommentCategoryID != "" {
channel := createFormComment(form_manage_id, e.User().ID, snowflake.MustParse(result.ModeratorID), "answer", discord.NewEmbedBuilder(). 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"). 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()) Build(), *e.GuildID(), e.Client())
err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Created channel " + discord.ChannelMention(channel.ID())).SetEphemeral(true).Build()) err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Created channel " + discord.ChannelMention(channel.ID())).SetEphemeral(true).Build())
if err != nil { if err != nil {
@@ -259,7 +260,7 @@ var cmd_form Command = Command{
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.ResultChannelID), discord.NewMessageCreateBuilder(). _, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.ResultChannelID), discord.NewMessageCreateBuilder().
SetEmbeds(discord.NewEmbedBuilder(). SetEmbeds(discord.NewEmbedBuilder().
SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("This is the submitted result"). 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()). Build()).
SetContainerComponents(discord.NewActionRow(discord. SetContainerComponents(discord.NewActionRow(discord.
NewButton(discord.ButtonStylePrimary, "Comment", "form:"+form_manage_id+";comment", ""). 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(). _, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.AcceptChannelID), discord.NewMessageCreateBuilder().
SetEmbeds(discord.NewEmbedBuilder(). SetEmbeds(discord.NewEmbedBuilder().
SetAuthorName(*e.User().GlobalName).SetAuthorIcon(*e.User().AvatarURL()).SetTitle("\""+modal.Title+"\"").SetDescription("**This submission needs approval.**"). 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()). Build()).
SetContainerComponents(discord.NewActionRow(buttons...)). SetContainerComponents(discord.NewActionRow(buttons...)).
Build()) Build())
@@ -370,7 +371,7 @@ var cmd_ticket_form Command = Command{
exists = getFormManageIdExists(formManageID) exists = getFormManageIdExists(formManageID)
} }
messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder(). 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{ Build()).SetContainerComponents(discord.ActionRowComponent{
discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{ discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{
Name: "anim_rocket", Name: "anim_rocket",

View File

@@ -8,6 +8,7 @@ import (
"github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
type UserExtend struct { type UserExtend struct {
@@ -115,7 +116,7 @@ var cmd_userinfo Command = Command{
} }
embedBuilder.SetTitle("User info") embedBuilder.SetTitle("User info")
embedBuilder.SetDescription(user.Mention()) embedBuilder.SetDescription(user.Mention())
embedBuilder.SetColor(hexToDecimal(color["primary"])) embedBuilder.SetColor(custom.GetColor("primary"))
err = e.CreateMessage(discord.NewMessageCreateBuilder(). err = e.CreateMessage(discord.NewMessageCreateBuilder().
SetEmbeds(embedBuilder.Build()). SetEmbeds(embedBuilder.Build()).
Build()) Build())

View File

@@ -8,6 +8,7 @@ import (
"github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
var cmd_ping Command = Command{ var cmd_ping Command = Command{
@@ -55,7 +56,7 @@ var cmd_ping Command = Command{
SetEmbeds(discord.NewEmbedBuilder(). SetEmbeds(discord.NewEmbedBuilder().
SetTitle(app.Bot.Username + " ping"). SetTitle(app.Bot.Username + " ping").
SetDescription(fmt.Sprintf("# %.2fms", ping.Seconds()*1000)). 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 { if err != nil {
logrus.Error(err) logrus.Error(err)
} }

View File

@@ -6,6 +6,7 @@ import (
"github.com/disgoorg/json" "github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2" "github.com/disgoorg/snowflake/v2"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
var cmd_sticky Command = Command{ var cmd_sticky Command = Command{
@@ -85,7 +86,7 @@ func inputStickyMessage(e *events.ApplicationCommandInteractionCreate) {
} }
} else { } else {
message, err := e.Client().Rest().CreateMessage(e.Channel().ID(), discord.MessageCreate{Embeds: []discord.Embed{ 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 { if err != nil {
logrus.Error(err) logrus.Error(err)
} }

View File

@@ -1,9 +0,0 @@
package main
var color map[string]string = map[string]string{
"red": "#FF6B6B",
"yellow": "#FFD93D",
"green": "#6BCB77",
"blue": "#008DDA",
"primary": "#564BA0",
}

View File

@@ -11,6 +11,7 @@ import (
"github.com/disgoorg/disgo/events" "github.com/disgoorg/disgo/events"
"github.com/disgoorg/snowflake/v2" "github.com/disgoorg/snowflake/v2"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/custom"
) )
type Command struct { type Command struct {
@@ -155,7 +156,7 @@ func messageCreate(e *events.MessageCreate) {
Footer: &discord.EmbedFooter{ Footer: &discord.EmbedFooter{
Text: "📌 Sticky message", Text: "📌 Sticky message",
}, },
Color: hexToDecimal(color["primary"]), Color: custom.GetColor("primary"),
Description: getStickyMessageContent(e.Message.GuildID.String(), e.Message.ChannelID.String()), Description: getStickyMessageContent(e.Message.GuildID.String(), e.Message.ChannelID.String()),
}, },
}, },

10
tool.go
View File

@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strconv"
"strings" "strings"
"github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/bot"
@@ -126,15 +125,6 @@ func getHighestRole(guildID string, c bot.Client) (*discord.Role, error) {
return highestRole, nil 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{} { func simpleGetFromAPI(key string, url string) interface{} {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)