refactor: 🧑💻 refactor config audits
Refactored and improved UX for the /config audits command
This commit is contained in:
parent
ad67954772
commit
61eaf84dc7
1 changed files with 29 additions and 39 deletions
|
@ -1,30 +1,27 @@
|
||||||
import {
|
import {
|
||||||
|
channelMention,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
|
||||||
PermissionsBitField,
|
PermissionsBitField,
|
||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import prisma from "../../../../handlers/database";
|
import prisma from "../../../../handlers/database";
|
||||||
import deferReply from "../../../../handlers/deferReply";
|
import deferReply from "../../../../handlers/deferReply";
|
||||||
|
import { success as embedSuccess } from "../../../../helpers/baseEmbeds";
|
||||||
import checkPermission from "../../../../helpers/checkPermission";
|
import checkPermission from "../../../../helpers/checkPermission";
|
||||||
import getEmbedConfig from "../../../../helpers/getEmbedData";
|
|
||||||
import logger from "../../../../middlewares/logger";
|
import logger from "../../../../middlewares/logger";
|
||||||
|
|
||||||
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
return command
|
return command
|
||||||
.setName("audits")
|
.setName("audits")
|
||||||
.setDescription("Audits")
|
.setDescription("Configure audits module")
|
||||||
.addBooleanOption((option) =>
|
.addBooleanOption((option) =>
|
||||||
option
|
option.setName("status").setDescription("Module status").setRequired(true)
|
||||||
.setName("status")
|
|
||||||
.setDescription("Should audits be enabled?")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
)
|
||||||
.addChannelOption((option) =>
|
.addChannelOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("channel")
|
.setName("channel")
|
||||||
.setDescription("Channel for audit messages.")
|
.setDescription("Log channel")
|
||||||
.addChannelTypes(ChannelType.GuildText)
|
.addChannelTypes(ChannelType.GuildText)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
);
|
);
|
||||||
|
@ -36,15 +33,14 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
|
||||||
const { guild, options } = interaction;
|
const { guild, options } = interaction;
|
||||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(guild);
|
if (!guild) throw new Error("Guild unavailable");
|
||||||
|
|
||||||
const status = options.getBoolean("status");
|
const status = options.getBoolean("status");
|
||||||
const channel = options.getChannel("channel");
|
const channel = options.getChannel("channel");
|
||||||
|
if (status === null) throw new Error("Status must be set");
|
||||||
|
if (!channel) throw new Error("Channel unavailable");
|
||||||
|
|
||||||
if (!guild) throw new Error("Guild not found.");
|
const upsertGuildConfigAudits = await prisma.guildConfigAudits.upsert({
|
||||||
if (!channel) throw new Error("Channel not found.");
|
|
||||||
if (status === null) throw new Error("Status not found.");
|
|
||||||
|
|
||||||
const createGuild = await prisma.guildConfigAudits.upsert({
|
|
||||||
where: {
|
where: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
},
|
},
|
||||||
|
@ -59,34 +55,28 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.silly(createGuild);
|
logger.silly(upsertGuildConfigAudits);
|
||||||
|
|
||||||
const embedSuccess = new EmbedBuilder()
|
const successEmbed = await embedSuccess(
|
||||||
.setTitle("[:hammer:] Audits")
|
guild,
|
||||||
.setDescription("Guild configuration updated successfully.")
|
":gear:︱Configuration of Audits"
|
||||||
.setColor(successColor)
|
);
|
||||||
.addFields(
|
|
||||||
|
successEmbed.setDescription("Configuration updated successfully!").addFields(
|
||||||
{
|
{
|
||||||
name: "🤖 Status",
|
name: "Status",
|
||||||
value: `${
|
value: `${upsertGuildConfigAudits.status ? "Enabled" : "Disabled"}`,
|
||||||
createGuild.status ? ":white_check_mark: Enabled" : ":x: Disabled"
|
|
||||||
}`,
|
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "🌊 Channel",
|
name: "Channel",
|
||||||
value: `<#${createGuild.channelId}>`,
|
value: `${channelMention(upsertGuildConfigAudits.channelId)}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
iconURL: footerIcon,
|
|
||||||
text: footerText,
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [embedSuccess],
|
embeds: [successEmbed],
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue