65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
const {
|
|
SlashCommandBuilder,
|
|
EmbedBuilder,
|
|
MessageFlags
|
|
} = require("discord.js");
|
|
|
|
const {
|
|
declareBankruptcy
|
|
} = require("../../utils/bankruptcy");
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName("bankruptcy")
|
|
.setDescription(
|
|
"Declare bankruptcy at exactly 0 Cookies and receive a starter kit."
|
|
),
|
|
|
|
async execute(interaction) {
|
|
const result = await declareBankruptcy(interaction);
|
|
|
|
if (!result.ok) {
|
|
if (result.reason === "COOLDOWN") {
|
|
return interaction.reply({
|
|
content:
|
|
`Bankruptcy assistance is unavailable until <t:${result.nextAvailableAt}:R>.`,
|
|
flags: MessageFlags.Ephemeral
|
|
});
|
|
}
|
|
|
|
if (result.reason === "BALANCE_NOT_ZERO") {
|
|
return interaction.reply({
|
|
content:
|
|
`You may only declare bankruptcy at exactly **0 Cookies**. Your current balance is **${result.balance.toLocaleString()}**.`,
|
|
flags: MessageFlags.Ephemeral
|
|
});
|
|
}
|
|
|
|
return interaction.reply({
|
|
content: "Bankruptcy could not be declared.",
|
|
flags: MessageFlags.Ephemeral
|
|
});
|
|
}
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🍪 Bankruptcy Declared")
|
|
.setDescription(
|
|
[
|
|
`${interaction.user} has been issued a fresh starter kit.`,
|
|
"",
|
|
`**+${result.amount.toLocaleString()} Cookies**`,
|
|
"",
|
|
"The Cookie economy believes in second chances."
|
|
].join("\n")
|
|
)
|
|
.addFields({
|
|
name: "Next Eligibility",
|
|
value: `<t:${result.nextAvailableAt}:R>`
|
|
});
|
|
|
|
return interaction.reply({
|
|
embeds: [embed]
|
|
});
|
|
}
|
|
};
|