refactor: 🚸 refactor config credits
Refactored and improved UX for /config credits
This commit is contained in:
parent
915b78e5d4
commit
8d4072446d
1 changed files with 57 additions and 75 deletions
|
@ -1,61 +1,51 @@
|
||||||
import {
|
import {
|
||||||
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("credits")
|
.setName("credits")
|
||||||
.setDescription(`Configure this guild's credits module.`)
|
.setDescription(`Configure credits module`)
|
||||||
.addBooleanOption((option) =>
|
.addBooleanOption((option) =>
|
||||||
option
|
option.setName("status").setDescription("Module Status").setRequired(true)
|
||||||
.setName("enabled")
|
|
||||||
.setDescription("Do you want to activate the credit module?")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("rate")
|
.setName("rate")
|
||||||
.setDescription("Credit rate per message.")
|
.setDescription("Credits per message")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setMinValue(1)
|
.setMinValue(1)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("minimum-length")
|
.setName("minimum-length")
|
||||||
.setDescription("Minimum message length to receive credit.")
|
.setDescription("Minimum length per message")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("work-rate")
|
.setName("work-rate")
|
||||||
.setDescription(
|
.setDescription("Maximum credits per workshift")
|
||||||
"The maximum amount of credit that can be obtained within a working day."
|
|
||||||
)
|
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setMinValue(1)
|
.setMinValue(1)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("work-timeout")
|
.setName("work-timeout")
|
||||||
.setDescription(
|
.setDescription("Time between workshifts")
|
||||||
"How long you need to wait before you can work again provided in seconds."
|
|
||||||
)
|
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("timeout")
|
.setName("timeout")
|
||||||
.setDescription(
|
.setDescription("Time between messages")
|
||||||
"How long you need to wait before you can earn more credits."
|
|
||||||
)
|
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -65,12 +55,9 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
|
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
|
||||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
|
||||||
interaction.guild
|
|
||||||
);
|
|
||||||
const { guild, options } = interaction;
|
const { guild, options } = interaction;
|
||||||
|
|
||||||
const enabled = options.getBoolean("enabled");
|
const status = options.getBoolean("status");
|
||||||
const rate = options.getNumber("rate");
|
const rate = options.getNumber("rate");
|
||||||
const timeout = options.getNumber("timeout");
|
const timeout = options.getNumber("timeout");
|
||||||
const minimumLength = options.getNumber("minimum-length");
|
const minimumLength = options.getNumber("minimum-length");
|
||||||
|
@ -78,23 +65,22 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const workTimeout = options.getNumber("work-timeout");
|
const workTimeout = options.getNumber("work-timeout");
|
||||||
|
|
||||||
if (!guild) throw new Error("Guild not found.");
|
if (!guild) throw new Error("Guild not found.");
|
||||||
if (typeof enabled !== "boolean")
|
if (typeof status !== "boolean") throw new Error("Status must be an boolean");
|
||||||
throw new Error("Enabled option is not a boolean.");
|
if (typeof rate !== "number") throw new Error("Rate must be a number");
|
||||||
if (typeof rate !== "number") throw new Error("Rate is not a number.");
|
|
||||||
if (typeof workRate !== "number")
|
if (typeof workRate !== "number")
|
||||||
throw new Error("Work rate is not a number.");
|
throw new Error("Work rate must be a number");
|
||||||
if (typeof workTimeout !== "number")
|
if (typeof workTimeout !== "number")
|
||||||
throw new Error("Work timeout is not a number.");
|
throw new Error("Work timeout must be a number");
|
||||||
if (typeof timeout !== "number") throw new Error("Timeout is not a number.");
|
if (typeof timeout !== "number") throw new Error("Timeout must be a number");
|
||||||
if (typeof minimumLength !== "number")
|
if (typeof minimumLength !== "number")
|
||||||
throw new Error("Minimum length is not a number.");
|
throw new Error("Minimum length must be a number");
|
||||||
|
|
||||||
const createGuild = await prisma.guildConfigCredits.upsert({
|
const upsertGuildConfigCredits = await prisma.guildConfigCredits.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
status: enabled,
|
status,
|
||||||
rate,
|
rate,
|
||||||
timeout,
|
timeout,
|
||||||
workRate,
|
workRate,
|
||||||
|
@ -103,7 +89,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
status: enabled,
|
status,
|
||||||
rate,
|
rate,
|
||||||
timeout,
|
timeout,
|
||||||
workRate,
|
workRate,
|
||||||
|
@ -112,52 +98,48 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.silly(createGuild);
|
logger.silly(upsertGuildConfigCredits);
|
||||||
|
|
||||||
const interactionEmbed = new EmbedBuilder()
|
const successEmbed = await embedSuccess(
|
||||||
.setTitle("[:tools:] Credits")
|
guild,
|
||||||
.setDescription("Credits settings updated")
|
":gear:︱Configuration of Credits"
|
||||||
.setColor(successColor)
|
);
|
||||||
.addFields(
|
|
||||||
{
|
successEmbed.setDescription("Configuration updated successfully!").addFields(
|
||||||
name: "🤖 Enabled?",
|
{
|
||||||
value: `${createGuild.status}`,
|
name: "Status",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.status ? "Enabled" : "Disabled"}`,
|
||||||
},
|
inline: true,
|
||||||
{
|
},
|
||||||
name: "📈 Rate",
|
{
|
||||||
value: `${createGuild.rate}`,
|
name: "Rate",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.rate}`,
|
||||||
},
|
inline: true,
|
||||||
{
|
},
|
||||||
name: "📈 Work Rate",
|
{
|
||||||
value: `${createGuild.workRate}`,
|
name: "Work Rate",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.workRate}`,
|
||||||
},
|
inline: true,
|
||||||
{
|
},
|
||||||
name: "🔨 Minimum Length",
|
{
|
||||||
value: `${createGuild.minimumLength}`,
|
name: "Minimum Length",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.minimumLength}`,
|
||||||
},
|
inline: true,
|
||||||
{
|
},
|
||||||
name: "⏰ Timeout",
|
{
|
||||||
value: `${createGuild.timeout}`,
|
name: "Timeout",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.timeout}`,
|
||||||
},
|
inline: true,
|
||||||
{
|
},
|
||||||
name: "⏰ Work Timeout",
|
{
|
||||||
value: `${createGuild.workTimeout}`,
|
name: "Work Timeout",
|
||||||
inline: true,
|
value: `${upsertGuildConfigCredits.workTimeout}`,
|
||||||
}
|
inline: true,
|
||||||
)
|
}
|
||||||
.setTimestamp()
|
);
|
||||||
.setFooter({
|
|
||||||
iconURL: footerIcon,
|
|
||||||
text: footerText,
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [interactionEmbed],
|
embeds: [successEmbed],
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue