Add dropnumber test command (#69)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Add `dropnumber` test command, for test servers only - Remove `DROP_CARD` environment variable #39 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. - This has been tested locally # Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/69 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
28d745bf5c
commit
ec2b523702
9 changed files with 121 additions and 70 deletions
1
.dev.env
1
.dev.env
|
@ -17,7 +17,6 @@ ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
DROP_RARITY=-1
|
DROP_RARITY=-1
|
||||||
DROP_CARD=-1
|
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3301
|
DB_PORT=3301
|
||||||
|
|
|
@ -17,7 +17,6 @@ ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
DROP_RARITY=-1
|
DROP_RARITY=-1
|
||||||
DROP_CARD=-1
|
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3321
|
DB_PORT=3321
|
||||||
|
|
|
@ -17,7 +17,6 @@ ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
DROP_RARITY=-1
|
DROP_RARITY=-1
|
||||||
DROP_CARD=-1
|
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3311
|
DB_PORT=3311
|
||||||
|
|
|
@ -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";
|
||||||
|
@ -16,15 +15,6 @@ export default class Reroll extends ButtonEvent {
|
||||||
|
|
||||||
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
|
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
|
||||||
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
|
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
|
||||||
} else if (process.env.DROP_CARD && process.env.DROP_CARD != '-1') {
|
|
||||||
let card = await Card.FetchOneByCardNumber(process.env.DROP_CARD, [ "Series" ]);
|
|
||||||
|
|
||||||
if (!card) {
|
|
||||||
await interaction.reply("Card not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
randomCard = card;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = readFileSync(randomCard.Path);
|
const image = readFileSync(randomCard.Path);
|
||||||
|
@ -36,30 +26,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 +41,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";
|
||||||
|
@ -22,15 +21,6 @@ export default class Drop extends Command {
|
||||||
|
|
||||||
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
|
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
|
||||||
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
|
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
|
||||||
} else if (process.env.DROP_CARD && process.env.DROP_CARD != '-1') {
|
|
||||||
let card = await Card.FetchOneByCardNumber(process.env.DROP_CARD, [ "Series" ]);
|
|
||||||
|
|
||||||
if (!card) {
|
|
||||||
await interaction.reply("Card not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
randomCard = card;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = readFileSync(randomCard.Path);
|
const image = readFileSync(randomCard.Path);
|
||||||
|
@ -42,30 +32,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 +47,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