feature/5-drop-command #17

Merged
Vylpes merged 4 commits from feature/5-drop-command into develop 2023-09-03 20:27:31 +01:00
3 changed files with 56 additions and 2 deletions
Showing only changes of commit 2809cc1014 - Show all commits

View file

@ -0,0 +1,48 @@
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.Id}.png` });
const embed = new EmbedBuilder()
.setTitle(randomCard.Name)
.setDescription(randomCard.Series.Name)
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
.setColor(CardRarityToColour(randomCard.Rarity))
.setImage(`attachment://${randomCard.Id}.png`);
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;
}
}

View file

@ -37,9 +37,13 @@ export default class Drop extends Command {
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) .setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
.setLabel("Claim") .setLabel("Claim")
.setStyle(ButtonStyle.Primary)); .setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId(`reroll`)
.setLabel("Reroll")
.setStyle(ButtonStyle.Secondary));
const message = await interaction.reply({ await interaction.reply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: [ attachment ],
components: [ row ], components: [ row ],

View file

@ -4,6 +4,7 @@ import About from "./commands/about";
import Drop from "./commands/drop"; import Drop from "./commands/drop";
import Claim from "./buttonEvents/Claim"; import Claim from "./buttonEvents/Claim";
import Reroll from "./buttonEvents/Reroll";
export default class Registry { export default class Registry {
public static RegisterCommands() { public static RegisterCommands() {
@ -17,5 +18,6 @@ export default class Registry {
public static RegisterButtonEvents() { public static RegisterButtonEvents() {
CoreClient.RegisterButtonEvent('claim', new Claim()); CoreClient.RegisterButtonEvent('claim', new Claim());
CoreClient.RegisterButtonEvent('reroll', new Reroll());
} }
} }