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/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)

View File

@@ -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)

View File

@@ -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",

View File

@@ -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())

View File

@@ -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)
}

View File

@@ -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)
}

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/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()),
},
},

10
tool.go
View File

@@ -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)