🧑💻 seperated /config embeds
This commit is contained in:
parent
e3e054122e
commit
efd7f24598
3 changed files with 142 additions and 129 deletions
|
@ -1,129 +0,0 @@
|
|||
// Dependencies
|
||||
import { ColorResolvable, CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
//Handlers
|
||||
import logger from "@logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import getEmbedConfig from "@helpers/getEmbedConfig";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("embeds")
|
||||
.setDescription(`Embeds`)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("success-color")
|
||||
.setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("wait-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("error-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-icon").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-text").setDescription("No provided description")
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { guild, options } = interaction;
|
||||
|
||||
if (guild == null) return;
|
||||
|
||||
const embedConfig = await getEmbedConfig(guild);
|
||||
|
||||
if (embedConfig == null) return;
|
||||
|
||||
logger.info(embedConfig);
|
||||
|
||||
// Get options
|
||||
const successColor = options?.getString("success-color") as ColorResolvable;
|
||||
const waitColor = options?.getString("wait-color") as ColorResolvable;
|
||||
const errorColor = options?.getString("error-color") as ColorResolvable;
|
||||
const footerIcon = options?.getString("footer-icon");
|
||||
const footerText = options?.getString("footer-text");
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guildSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
guildDB.embeds.successColor =
|
||||
successColor !== null ? successColor : guildDB?.embeds?.successColor;
|
||||
guildDB.embeds.waitColor =
|
||||
waitColor !== null ? waitColor : guildDB?.embeds?.waitColor;
|
||||
guildDB.embeds.errorColor =
|
||||
errorColor !== null ? errorColor : guildDB?.embeds?.errorColor;
|
||||
guildDB.embeds.footerIcon =
|
||||
footerIcon !== null ? footerIcon : guildDB?.embeds?.footerIcon;
|
||||
guildDB.embeds.footerText =
|
||||
footerText !== null ? footerText : guildDB?.embeds?.footerText;
|
||||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.silly(`Guild saved`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
{
|
||||
title: ":tools: Settings - Guild [Credits]",
|
||||
description: `Credits settings updated.`,
|
||||
color: successColor || embedConfig.successColor,
|
||||
fields: [
|
||||
{
|
||||
name: "🤖 Success Color",
|
||||
value: `${guildDB?.embeds?.successColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📈 Wait Color",
|
||||
value: `${guildDB?.embeds?.waitColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📈 Error Color",
|
||||
value: `${guildDB?.embeds?.errorColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🔨 Footer Icon",
|
||||
value: `${guildDB?.embeds?.footerIcon}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "⏰ Footer Text",
|
||||
value: `${guildDB?.embeds?.footerText}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon || embedConfig.footerIcon,
|
||||
text: footerText || embedConfig.footerText,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
import { ColorResolvable, CommandInteraction } from "discord.js";
|
||||
import guildSchema from "@schemas/guild";
|
||||
import getEmbedConfig from "@root/helpers/getEmbedConfig";
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const { options, guild } = interaction;
|
||||
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
|
||||
const embedConfig = await getEmbedConfig(guild);
|
||||
if (!embedConfig) throw new Error("Embed config not found");
|
||||
|
||||
// Get new values
|
||||
const newSuccessColor = options.getString("success-color") as ColorResolvable;
|
||||
const newWaitColor = options.getString("wait-color") as ColorResolvable;
|
||||
const newErrorColor = options.getString("error-color") as ColorResolvable;
|
||||
const newFooterIcon = options.getString("footer-icon");
|
||||
const newFooterText = options.getString("footer-text");
|
||||
|
||||
// Get guild values
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
if (!guildData) throw new Error("Guild data not found");
|
||||
if (!guildData?.embeds)
|
||||
throw new Error("Guild embed configuration not found");
|
||||
let { successColor, waitColor, errorColor, footerText, footerIcon } =
|
||||
guildData.embeds;
|
||||
|
||||
// Set new values
|
||||
successColor = newSuccessColor || successColor;
|
||||
waitColor = newWaitColor || waitColor;
|
||||
errorColor = newErrorColor || errorColor;
|
||||
footerIcon = newFooterIcon || footerIcon;
|
||||
footerText = newFooterText || footerText;
|
||||
|
||||
return { successColor, waitColor, errorColor, footerText, footerIcon };
|
||||
};
|
104
src/plugins/config/modules/embeds/index.ts
Normal file
104
src/plugins/config/modules/embeds/index.ts
Normal file
|
@ -0,0 +1,104 @@
|
|||
// Dependencies
|
||||
import {
|
||||
ColorResolvable,
|
||||
CommandInteraction,
|
||||
MessageEmbed,
|
||||
Permissions,
|
||||
} from "discord.js";
|
||||
|
||||
//Handlers
|
||||
import logger from "@logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import getEmbedConfig from "@helpers/getEmbedConfig";
|
||||
import getValues from "./components/getValues";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("embeds")
|
||||
.setDescription(`Embeds`)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("success-color")
|
||||
.setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("wait-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("error-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-icon").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-text").setDescription("No provided description")
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
const { guild } = interaction;
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
|
||||
const { successColor, waitColor, errorColor, footerText, footerIcon } =
|
||||
await getValues(interaction);
|
||||
|
||||
// Initialize embed object
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:tools:] Embeds")
|
||||
.setFooter({ text: footerText, iconURL: footerIcon })
|
||||
.setTimestamp(new Date());
|
||||
|
||||
// Get guild values
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
if (!guildData) throw new Error("Guild data not found");
|
||||
|
||||
await guildData.save().then(async () => {
|
||||
embed
|
||||
.setDescription("Following embed configuration will be used.")
|
||||
.setColor(successColor)
|
||||
.addFields([
|
||||
{
|
||||
name: "🟢 Success Color",
|
||||
value: `${successColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🟡 Wait Color",
|
||||
value: `${waitColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🔴 Error Color",
|
||||
value: `${errorColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🖼️ Footer Icon",
|
||||
value: `${footerIcon}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Footer Text",
|
||||
value: `${footerText}`,
|
||||
inline: true,
|
||||
},
|
||||
]);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
Loading…
Add table
Reference in a new issue