feature/5-drop-command (#17)
#5 Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/17 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
51d97bacd5
commit
58d1541e47
21 changed files with 382 additions and 48 deletions
38
src/buttonEvents/Claim.ts
Normal file
38
src/buttonEvents/Claim.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { ButtonInteraction } from "discord.js";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
import { CoreClient } from "../client/client";
|
||||
|
||||
export default class Claim extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
if (!interaction.guild || !interaction.guildId) return;
|
||||
|
||||
const cardNumber = interaction.customId.split(' ')[1];
|
||||
const claimId = interaction.customId.split(' ')[2];
|
||||
const userId = interaction.user.id;
|
||||
|
||||
const claimed = await Inventory.FetchOneByClaimId(claimId);
|
||||
|
||||
if (claimed) {
|
||||
await interaction.reply('This card has already been claimed');
|
||||
return;
|
||||
}
|
||||
|
||||
if (claimId != CoreClient.ClaimId) {
|
||||
await interaction.reply('This card has expired');
|
||||
return;
|
||||
}
|
||||
|
||||
let inventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
|
||||
|
||||
if (!inventory) {
|
||||
inventory = new Inventory(userId, cardNumber, 1, claimId);
|
||||
} else {
|
||||
inventory.SetQuantity(inventory.Quantity + 1);
|
||||
}
|
||||
|
||||
await inventory.Save(Inventory, inventory);
|
||||
|
||||
await interaction.reply('Card claimed');
|
||||
}
|
||||
}
|
48
src/buttonEvents/Reroll.ts
Normal file
48
src/buttonEvents/Reroll.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue