137 lines
3.8 KiB
JavaScript
137 lines
3.8 KiB
JavaScript
const {
|
|
EmbedBuilder,
|
|
ActionRowBuilder,
|
|
ButtonBuilder,
|
|
ButtonStyle
|
|
} = require("discord.js");
|
|
|
|
const {
|
|
getCookieBalance,
|
|
temporaryEphemeralReply
|
|
} = require("./cookieEconomy");
|
|
|
|
async function showCrumbSaucer(interaction) {
|
|
if (interaction.isButton()) {
|
|
const ownerId = getCrumbSaucerSessionOwner(interaction);
|
|
if (ownerId !== interaction.user.id) {
|
|
return temporaryEphemeralReply(interaction, {
|
|
content: "This isn't your Crumb Saucer session."
|
|
});
|
|
}
|
|
}
|
|
|
|
const balance = await getCookieBalance(interaction.user.id);
|
|
const embed = buildMainMenuEmbed(interaction.user, balance);
|
|
const components = buildMainMenuButtons();
|
|
|
|
if (interaction.isButton()) {
|
|
return interaction.update({
|
|
embeds: [embed],
|
|
components
|
|
});
|
|
}
|
|
|
|
return interaction.reply({
|
|
embeds: [embed],
|
|
components
|
|
});
|
|
}
|
|
|
|
function buildMainMenuEmbed(user, balance) {
|
|
return new EmbedBuilder()
|
|
.setTitle("🎰 The Crumb Saucer")
|
|
.setDescription([
|
|
`Welcome, ${user}!`,
|
|
"",
|
|
"Where Cookies are won, lost,",
|
|
"and occasionally confiscated by ShaiBot.",
|
|
"",
|
|
"### 🎰 Slots",
|
|
"Spin the reels and chase the Cookie jackpot.",
|
|
"",
|
|
"### 🏦 Vault Heist",
|
|
"Attempt to breach ShaiBot's Cookie Vault.",
|
|
"",
|
|
"### 🃏 Blackjack",
|
|
"Beat the dealer without going over 21.",
|
|
"",
|
|
"### 🎡 Roulette",
|
|
"Bet on Red, Black, Odd, Even, or Zero.",
|
|
"",
|
|
"*More attractions coming soon... make a lala offering or buy me a white monster*"
|
|
].join("\n"))
|
|
.addFields({
|
|
name: "Your Vault",
|
|
value: `**${balance.toLocaleString()} 🍪**`
|
|
})
|
|
.setFooter({
|
|
text: `crumbSaucer:${user.id}`
|
|
});
|
|
}
|
|
|
|
function buildMainMenuButtons() {
|
|
return [
|
|
new ActionRowBuilder().addComponents(
|
|
new ButtonBuilder()
|
|
.setCustomId("crumbSaucerSlots")
|
|
.setLabel("Slots")
|
|
.setEmoji("🎰")
|
|
.setStyle(ButtonStyle.Primary),
|
|
|
|
new ButtonBuilder()
|
|
.setCustomId("crumbSaucerBlackjack")
|
|
.setLabel("Blackjack")
|
|
.setEmoji("🃏")
|
|
.setStyle(ButtonStyle.Success),
|
|
|
|
new ButtonBuilder()
|
|
.setCustomId("crumbSaucerRoulette")
|
|
.setLabel("Roulette")
|
|
.setEmoji("🎡")
|
|
.setStyle(ButtonStyle.Primary),
|
|
|
|
new ButtonBuilder()
|
|
.setCustomId("crumbSaucerHeist")
|
|
.setLabel("Vault Heist")
|
|
.setEmoji("🏦")
|
|
.setStyle(ButtonStyle.Danger)
|
|
),
|
|
|
|
new ActionRowBuilder().addComponents(
|
|
new ButtonBuilder()
|
|
.setCustomId("abort")
|
|
.setLabel("Close")
|
|
.setEmoji("✖️")
|
|
.setStyle(ButtonStyle.Secondary)
|
|
)
|
|
];
|
|
}
|
|
|
|
function getCrumbSaucerSessionOwner(interaction) {
|
|
const footer = interaction.message?.embeds?.[0]?.footer?.text;
|
|
const parts = footer?.split(":") ?? [];
|
|
|
|
switch (parts[0]) {
|
|
case "crumbSaucer":
|
|
case "crumbSaucerSlots":
|
|
case "crumbSaucerSlotsResult":
|
|
case "crumbSaucerBlackjack":
|
|
case "crumbBlackjackResult":
|
|
case "crumbRouletteMenu":
|
|
case "crumbRouletteBet":
|
|
case "crumbRouletteResult":
|
|
case "cookieHeist":
|
|
return parts[1];
|
|
|
|
case "crumbBlackjack":
|
|
return parts[2];
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
showCrumbSaucer
|
|
};
|