Add dropnumber test command #69
6 changed files with 121 additions and 49 deletions
|
@ -1,8 +1,7 @@
|
||||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, DiscordAPIError, EmbedBuilder } from "discord.js";
|
import { AttachmentBuilder, ButtonInteraction, DiscordAPIError } from "discord.js";
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
import { ButtonEvent } from "../type/buttonEvent";
|
||||||
import CardDropHelper from "../helpers/CardDropHelper";
|
import CardDropHelper from "../helpers/CardDropHelper";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
import { CoreClient } from "../client/client";
|
import { CoreClient } from "../client/client";
|
||||||
import Card from "../database/entities/card/Card";
|
import Card from "../database/entities/card/Card";
|
||||||
|
@ -36,30 +35,11 @@ export default class Reroll extends ButtonEvent {
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.CardNumber);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.CardNumber);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
let embedDescription = "";
|
const embed = CardDropHelper.GenerateDropEmbed(randomCard, quantityClaimed || 0);
|
||||||
embedDescription += `Series: ${randomCard.Series.Name}\n`;
|
|
||||||
embedDescription += `Claimed: ${quantityClaimed || 0}\n`;
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle(randomCard.Name)
|
|
||||||
.setDescription(embedDescription)
|
|
||||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
|
||||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
|
||||||
.setImage(`attachment://${randomCard.FileName}`);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
|
||||||
|
|
||||||
const claimId = v4();
|
const claimId = v4();
|
||||||
|
|
||||||
row.addComponents(
|
const row = CardDropHelper.GenerateDropButtons(randomCard, claimId, interaction.user.id);
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
|
|
||||||
.setLabel("Claim")
|
|
||||||
.setStyle(ButtonStyle.Primary),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`reroll`)
|
|
||||||
.setLabel("Reroll")
|
|
||||||
.setStyle(ButtonStyle.Secondary));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
@ -70,7 +50,6 @@ export default class Reroll extends ButtonEvent {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
||||||
|
|
||||||
if (e instanceof DiscordAPIError) {
|
if (e instanceof DiscordAPIError) {
|
||||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, DiscordAPIError, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
import { AttachmentBuilder, CommandInteraction, DiscordAPIError, SlashCommandBuilder } from "discord.js";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import CardDropHelper from "../helpers/CardDropHelper";
|
import CardDropHelper from "../helpers/CardDropHelper";
|
||||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { CoreClient } from "../client/client";
|
import { CoreClient } from "../client/client";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
@ -42,30 +41,11 @@ export default class Drop extends Command {
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.CardNumber);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.CardNumber);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
let embedDescription = "";
|
const embed = CardDropHelper.GenerateDropEmbed(randomCard, quantityClaimed || 0);
|
||||||
embedDescription += `Series: ${randomCard.Series.Name}\n`;
|
|
||||||
embedDescription += `Claimed: ${quantityClaimed || 0}\n`;
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle(randomCard.Name)
|
|
||||||
.setDescription(embedDescription)
|
|
||||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
|
||||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
|
||||||
.setImage(`attachment://${randomCard.FileName}`);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
|
||||||
|
|
||||||
const claimId = v4();
|
const claimId = v4();
|
||||||
|
|
||||||
row.addComponents(
|
const row = CardDropHelper.GenerateDropButtons(randomCard, claimId, interaction.user.id);
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
|
|
||||||
.setLabel("Claim")
|
|
||||||
.setStyle(ButtonStyle.Primary),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`reroll`)
|
|
||||||
.setLabel("Reroll")
|
|
||||||
.setStyle(ButtonStyle.Secondary));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
@ -76,7 +56,6 @@ export default class Drop extends Command {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
||||||
|
|
||||||
if (e instanceof DiscordAPIError) {
|
if (e instanceof DiscordAPIError) {
|
||||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
||||||
} else {
|
} else {
|
||||||
|
|
76
src/commands/stage/dropnumber.ts
Normal file
76
src/commands/stage/dropnumber.ts
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import { AttachmentBuilder, CacheType, CommandInteraction, DiscordAPIError, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../../type/command";
|
||||||
|
import Card from "../../database/entities/card/Card";
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
import Inventory from "../../database/entities/app/Inventory";
|
||||||
|
import CardDropHelper from "../../helpers/CardDropHelper";
|
||||||
|
import { v4 } from "uuid";
|
||||||
|
import { CoreClient } from "../../client/client";
|
||||||
|
|
||||||
|
export default class Dropnumber extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('dropnumber')
|
||||||
|
.setDescription('(TEST) Summon a specific card')
|
||||||
|
.addStringOption(x =>
|
||||||
|
x
|
||||||
|
.setName('cardnumber')
|
||||||
|
.setDescription('The card number to summon')
|
||||||
|
.setRequired(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const cardNumber = interaction.options.get('cardnumber');
|
||||||
|
|
||||||
|
if (!cardNumber || !cardNumber.value) {
|
||||||
|
await interaction.reply('Card Number is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const card = await Card.FetchOneByCardNumber(cardNumber.value.toString(), [
|
||||||
|
"Series"
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!card) {
|
||||||
|
await interaction.reply('Card not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const image = readFileSync(card.Path);
|
||||||
|
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
const attachment = new AttachmentBuilder(image, { name: card.FileName });
|
||||||
|
|
||||||
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.CardNumber);
|
||||||
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
const embed = CardDropHelper.GenerateDropEmbed(card, quantityClaimed || 0);
|
||||||
|
|
||||||
|
const claimId = v4();
|
||||||
|
|
||||||
|
const row = CardDropHelper.GenerateDropButtons(card, claimId, interaction.user.id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [ embed ],
|
||||||
|
files: [ attachment ],
|
||||||
|
components: [ row ],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
|
if (e instanceof DiscordAPIError) {
|
||||||
|
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
||||||
|
} else {
|
||||||
|
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening.Code: UNKNOWN`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreClient.ClaimId = claimId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,4 +5,5 @@ export enum Environment {
|
||||||
Local = 1 << 2,
|
Local = 1 << 2,
|
||||||
|
|
||||||
All = Production | Stage | Local,
|
All = Production | Stage | Local,
|
||||||
|
Test = Stage | Local,
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import { CardRarity } from "../constants/CardRarity";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
|
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||||
import Card from "../database/entities/card/Card";
|
import Card from "../database/entities/card/Card";
|
||||||
|
|
||||||
export default class CardDropHelper {
|
export default class CardDropHelper {
|
||||||
|
@ -30,4 +31,30 @@ export default class CardDropHelper {
|
||||||
|
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GenerateDropEmbed(card: Card, quantityClaimed: Number): EmbedBuilder {
|
||||||
|
let description = "";
|
||||||
|
description += `Series: ${card.Series.Name}\n`;
|
||||||
|
description += `Claimed: ${quantityClaimed}\n`;
|
||||||
|
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle(card.Name)
|
||||||
|
.setDescription(description)
|
||||||
|
.setFooter({ text: CardRarityToString(card.Rarity) })
|
||||||
|
.setColor(CardRarityToColour(card.Rarity))
|
||||||
|
.setImage(`attachment://${card.FileName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GenerateDropButtons(card: Card, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> {
|
||||||
|
return new ActionRowBuilder<ButtonBuilder>()
|
||||||
|
.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`claim ${card.CardNumber} ${claimId} ${userId}`)
|
||||||
|
.setLabel("Claim")
|
||||||
|
.setStyle(ButtonStyle.Primary),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`reroll`)
|
||||||
|
.setLabel("Reroll")
|
||||||
|
.setStyle(ButtonStyle.Secondary));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,25 @@
|
||||||
import { CoreClient } from "./client/client";
|
import { CoreClient } from "./client/client";
|
||||||
|
|
||||||
|
// Global Command Imports
|
||||||
import About from "./commands/about";
|
import About from "./commands/about";
|
||||||
import Drop from "./commands/drop";
|
import Drop from "./commands/drop";
|
||||||
|
|
||||||
|
// Test Command Imports
|
||||||
|
import Dropnumber from "./commands/stage/dropnumber";
|
||||||
|
|
||||||
|
// Button Event Imports
|
||||||
import Claim from "./buttonEvents/Claim";
|
import Claim from "./buttonEvents/Claim";
|
||||||
import Reroll from "./buttonEvents/Reroll";
|
import Reroll from "./buttonEvents/Reroll";
|
||||||
|
import { Environment } from "./constants/Environment";
|
||||||
|
|
||||||
export default class Registry {
|
export default class Registry {
|
||||||
public static RegisterCommands() {
|
public static RegisterCommands() {
|
||||||
|
// Global Commands
|
||||||
CoreClient.RegisterCommand('about', new About());
|
CoreClient.RegisterCommand('about', new About());
|
||||||
CoreClient.RegisterCommand('drop', new Drop());
|
CoreClient.RegisterCommand('drop', new Drop());
|
||||||
|
|
||||||
|
// Test Commands
|
||||||
|
CoreClient.RegisterCommand('dropnumber', new Dropnumber(), Environment.Test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterEvents() {
|
public static RegisterEvents() {
|
||||||
|
|
Loading…
Reference in a new issue