Files
2026-08-18 20:07:41 +02:00

301 lines
6.5 KiB
JavaScript

const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle
} = require("discord.js");
const {
getCookieBalance,
getCooldown,
getUnixTime,
temporaryEphemeralReply
} = require(
"../../utils/cookieEconomy"
);
const {
HEIST_COOLDOWN
} = require(
"../../utils/cookieHeist"
);
module.exports = {
name:
"crumbSaucerHeist",
async execute(interaction) {
/*
* Verify ownership of the Crumb Saucer menu.
*/
const footer =
interaction.message
.embeds[0]
?.footer
?.text;
const [
type,
ownerId
] =
footer?.split(":")
?? [];
if (
type !== "crumbSaucer" ||
ownerId !== interaction.user.id
) {
return temporaryEphemeralReply(
interaction,
{
content:
"This isn't your Crumb Saucer session."
}
);
}
/*
* ====================================================
* SHARED HEIST COOLDOWN PRE-CHECK
* ====================================================
*/
const now =
getUnixTime();
const cooldown =
await getCooldown(
interaction.user.id,
interaction.guildId,
"heist"
);
if (
cooldown >
now
) {
return temporaryEphemeralReply(
interaction,
{
content:
`🏦 The ShaiBot Vault is still on alert.\nYou can attempt another heist <t:${cooldown}:R>.`
},
6000
);
}
/*
* Balances
*/
const vaultId =
interaction.client.user.id;
const [
vault,
player
] =
await Promise.all([
getCookieBalance(
vaultId
),
getCookieBalance(
interaction.user.id
)
]);
if (
player <
1
) {
return temporaryEphemeralReply(
interaction,
{
content:
"You need at least **1 Cookie** before attempting a vault heist."
}
);
}
if (
vault <
1
) {
return temporaryEphemeralReply(
interaction,
{
content:
"The ShaiBot Vault is currently empty."
}
);
}
/*
* Heist menu
*/
const embed =
new EmbedBuilder()
.setTitle(
"🏦 ShaiBot Cookie Vault"
)
.setDescription(
[
`**Vault Balance:** ${vault.toLocaleString()} 🍪`,
`**Security:** ${getSecurityLabel(vault)}`,
"",
"Choose your approach.",
"",
"🥷 **Sneak**",
"High chance • Small haul • Small fine",
"",
"💻 **Hack**",
"Medium chance • Medium haul • Medium fine",
"",
"💥 **Smash**",
"Low chance • Large haul • Large fine"
].join("\n")
)
.setFooter({
text:
`cookieHeist:${interaction.user.id}`
});
const heistButtons =
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(
"cookieHeistSneak"
)
.setLabel(
"Sneak"
)
.setEmoji(
"🥷"
)
.setStyle(
ButtonStyle.Primary
),
new ButtonBuilder()
.setCustomId(
"cookieHeistHack"
)
.setLabel(
"Hack"
)
.setEmoji(
"💻"
)
.setStyle(
ButtonStyle.Secondary
),
new ButtonBuilder()
.setCustomId(
"cookieHeistSmash"
)
.setLabel(
"Smash"
)
.setEmoji(
"💥"
)
.setStyle(
ButtonStyle.Danger
)
);
const backButton =
new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(
"crumbSaucerBack"
)
.setLabel(
"Back to Crumb Saucer"
)
.setEmoji(
"◀️"
)
.setStyle(
ButtonStyle.Secondary
)
);
return interaction.update({
embeds: [
embed
],
components: [
heistButtons,
backButton
]
});
}
};
/*
* SECURITY LABEL
*/
function getSecurityLabel(
vault
) {
if (
vault <
1000
) {
return "🟢 Low";
}
if (
vault <
10000
) {
return "🟡 Moderate";
}
if (
vault <
50000
) {
return "🟠 High";
}
if (
vault <
250000
) {
return "🔴 Very High";
}
return "🟣 Maximum";
}