card-drop/src/buttonEvents/Reroll.ts
Ethan Lane 6629ac30aa
All checks were successful
continuous-integration/drone/push Build is passing
hotfix/0.1.1 (#23)
- Fix gifs not animating

Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/23
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2023-09-04 13:02:02 +01:00

48 lines
No EOL
1.8 KiB
TypeScript

import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, EmbedBuilder } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent";
import CardDropHelper from "../helpers/CardDropHelper";
import { readFileSync } from "fs";
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
import { v4 } from "uuid";
import { CoreClient } from "../client/client";
export default class Reroll extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) {
if (!interaction.guild || !interaction.guildId) return;
const randomCard = await CardDropHelper.GetRandomCard();
const image = readFileSync(randomCard.Path);
const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
const embed = new EmbedBuilder()
.setTitle(randomCard.Name)
.setDescription(randomCard.Series.Name)
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
.setColor(CardRarityToColour(randomCard.Rarity))
.setImage(`attachment://${randomCard.FileName}`);
const row = new ActionRowBuilder<ButtonBuilder>();
const claimId = v4();
row.addComponents(
new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
.setLabel("Claim")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId(`reroll`)
.setLabel("Reroll")
.setStyle(ButtonStyle.Secondary));
await interaction.reply({
embeds: [ embed ],
files: [ attachment ],
components: [ row ],
});
CoreClient.ClaimId = claimId;
}
}