♻️ /config embeds now on Prisma
This commit is contained in:
parent
7437fddd84
commit
fcf98e5a4e
2 changed files with 88 additions and 62 deletions
|
@ -1,6 +1,7 @@
|
|||
import { ChatInputCommandInteraction, ColorResolvable } from "discord.js";
|
||||
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
|
||||
import guildSchema from "../../../../../../../models/guild";
|
||||
import logger from "../../../../../../../middlewares/logger";
|
||||
import prisma from "../../../../../../../prisma";
|
||||
|
||||
export default async (interaction: ChatInputCommandInteraction) => {
|
||||
const { options, guild } = interaction;
|
||||
|
@ -10,26 +11,46 @@ export default async (interaction: ChatInputCommandInteraction) => {
|
|||
const embedConfig = await getEmbedConfig(guild);
|
||||
if (!embedConfig) throw new Error("Embed config not found");
|
||||
|
||||
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 newSuccessColor = <ColorResolvable>options.getString("success-color");
|
||||
const newWaitColor = <ColorResolvable>options.getString("wait-color");
|
||||
const newErrorColor = <ColorResolvable>options.getString("error-color");
|
||||
const newFooterIcon = options.getString("footer-icon");
|
||||
const newFooterText = options.getString("footer-text");
|
||||
|
||||
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;
|
||||
if (!newSuccessColor) throw new Error("Success color not found");
|
||||
if (!newWaitColor) throw new Error("Wait color not found");
|
||||
if (!newErrorColor) throw new Error("Error color not found");
|
||||
if (!newFooterIcon) throw new Error("Footer icon not found");
|
||||
if (!newFooterText) throw new Error("Footer text not found");
|
||||
|
||||
successColor = newSuccessColor || successColor;
|
||||
waitColor = newWaitColor || waitColor;
|
||||
errorColor = newErrorColor || errorColor;
|
||||
footerIcon = newFooterIcon || footerIcon;
|
||||
footerText = newFooterText || footerText;
|
||||
const createGuild = await prisma.guild.upsert({
|
||||
where: {
|
||||
id: guild.id,
|
||||
},
|
||||
update: {
|
||||
embedColorSuccess: <string>newSuccessColor,
|
||||
embedColorWait: <string>newWaitColor,
|
||||
embedColorError: <string>newErrorColor,
|
||||
embedFooterIcon: newFooterIcon,
|
||||
embedFooterText: newFooterText,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
embedColorSuccess: <string>newSuccessColor,
|
||||
embedColorWait: <string>newWaitColor,
|
||||
embedColorError: <string>newErrorColor,
|
||||
embedFooterIcon: newFooterIcon,
|
||||
embedFooterText: newFooterText,
|
||||
},
|
||||
});
|
||||
|
||||
logger.silly(createGuild);
|
||||
|
||||
const successColor = <ColorResolvable>createGuild.embedColorSuccess;
|
||||
const waitColor = <ColorResolvable>createGuild.embedColorWait;
|
||||
const errorColor = <ColorResolvable>createGuild.embedColorError;
|
||||
const footerText = createGuild.embedFooterText;
|
||||
const footerIcon = createGuild.embedFooterIcon;
|
||||
|
||||
return { successColor, waitColor, errorColor, footerText, footerIcon };
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
} from "discord.js";
|
||||
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import guildSchema from "../../../../../models/guild";
|
||||
import getValues from "./components/getValues";
|
||||
|
||||
export default {
|
||||
|
@ -23,18 +22,31 @@ export default {
|
|||
option
|
||||
.setName("success-color")
|
||||
.setDescription("No provided description")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("wait-color").setDescription("No provided description")
|
||||
option
|
||||
.setName("wait-color")
|
||||
.setDescription("No provided description")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("error-color").setDescription("No provided description")
|
||||
option
|
||||
.setName("error-color")
|
||||
.setDescription("No provided description")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-icon").setDescription("No provided description")
|
||||
option
|
||||
.setName("footer-icon")
|
||||
.setDescription("No provided description")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-text").setDescription("No provided description")
|
||||
option
|
||||
.setName("footer-text")
|
||||
.setDescription("No provided description")
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: ChatInputCommandInteraction) => {
|
||||
|
@ -49,47 +61,40 @@ export default {
|
|||
.setFooter({ text: footerText, iconURL: footerIcon })
|
||||
.setTimestamp(new Date());
|
||||
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
if (!guildData) throw new Error("Guild data not found");
|
||||
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,
|
||||
},
|
||||
]);
|
||||
|
||||
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,
|
||||
},
|
||||
]);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [embed],
|
||||
});
|
||||
return;
|
||||
await interaction.editReply({
|
||||
embeds: [embed],
|
||||
});
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue