@ApplyOptions<Command.Options>({
description: 'The upgrader game',
preconditions: ['RoomsOnly', 'HasRegistered']
})
export class GameCoinFlip extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) => {
builder
.setName(this.name)
.setDescription(this.description)
.addStringOption((option) =>
option.setName('choice').setDescription('The choice to flip').setRequired(true).addChoices(
{
name: 'Head',
value: 'head'
},
{
name: 'Tails',
value: 'tails'
}
)
)
.addStringOption((option) => option.setName('amount').setDescription('The amount to flip').setRequired(true));
});
}
public override async chatInputRun(interaction: ChatInputCommandInteraction, _context: ChatInputCommand.RunContext) {
try {
await this.sendInfo(interaction);
} catch (error) {
console.error('Error in chatInputRun:', error);
await interaction.reply({ content: 'An error occurred while processing your request.', ephemeral: true });
}
}
private async sendInfo(interaction: ChatInputCommandInteraction) {
const choice = interaction.options.getString('choice');
const amountOption = interaction.options.getString('amount');
if (!amountOption || !choice) {
return await interaction.reply({ content: 'Amount and choice are required options.', ephemeral: true });
}
const amount = suffixToAmount(amountOption);
const user = await prisma.userStakes.findUnique({ where: { userId: Number(interaction.user.id) } });
if (!user || !checkIfUserHasBalance(user.userId, amount, interaction)) {
return await interaction.reply({ content: 'insufficient balance.', ephemeral: true });
}
const embed = createEmbed(
`${knowIcon} Coin Flip Confirmation`,
`${gemsIcon} **Gems Amount:** ${amountToSuffix(amount)}\n` + `${diceIcon} **Side:** ${choice}\n`
);
const confirmButton = new ButtonBuilder().setCustomId('confirm').setLabel('Confirm').setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(confirmButton);
return await interaction.reply({ embeds: [embed], components: [row] });
}
}
@ApplyOptions<Command.Options>({
description: 'The upgrader game',
preconditions: ['RoomsOnly', 'HasRegistered']
})
export class GameCoinFlip extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) => {
builder
.setName(this.name)
.setDescription(this.description)
.addStringOption((option) =>
option.setName('choice').setDescription('The choice to flip').setRequired(true).addChoices(
{
name: 'Head',
value: 'head'
},
{
name: 'Tails',
value: 'tails'
}
)
)
.addStringOption((option) => option.setName('amount').setDescription('The amount to flip').setRequired(true));
});
}
public override async chatInputRun(interaction: ChatInputCommandInteraction, _context: ChatInputCommand.RunContext) {
try {
await this.sendInfo(interaction);
} catch (error) {
console.error('Error in chatInputRun:', error);
await interaction.reply({ content: 'An error occurred while processing your request.', ephemeral: true });
}
}
private async sendInfo(interaction: ChatInputCommandInteraction) {
const choice = interaction.options.getString('choice');
const amountOption = interaction.options.getString('amount');
if (!amountOption || !choice) {
return await interaction.reply({ content: 'Amount and choice are required options.', ephemeral: true });
}
const amount = suffixToAmount(amountOption);
const user = await prisma.userStakes.findUnique({ where: { userId: Number(interaction.user.id) } });
if (!user || !checkIfUserHasBalance(user.userId, amount, interaction)) {
return await interaction.reply({ content: 'insufficient balance.', ephemeral: true });
}
const embed = createEmbed(
`${knowIcon} Coin Flip Confirmation`,
`${gemsIcon} **Gems Amount:** ${amountToSuffix(amount)}\n` + `${diceIcon} **Side:** ${choice}\n`
);
const confirmButton = new ButtonBuilder().setCustomId('confirm').setLabel('Confirm').setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(confirmButton);
return await interaction.reply({ embeds: [embed], components: [row] });
}
}