Add ability to force a card
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ethan Lane 2023-09-05 20:45:33 +01:00
parent 476b9ad5f9
commit 5ec79ee67c
6 changed files with 31 additions and 0 deletions

View file

@ -16,6 +16,7 @@ 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

View file

@ -16,6 +16,7 @@ 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

View file

@ -16,6 +16,7 @@ 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

View file

@ -5,6 +5,7 @@ import { readFileSync } from "fs";
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity"; 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";
export default class Reroll extends ButtonEvent { export default class Reroll extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) { public override async execute(interaction: ButtonInteraction) {
@ -14,6 +15,15 @@ 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);

View file

@ -5,6 +5,7 @@ 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";
import Card from "../database/entities/card/Card";
export default class Drop extends Command { export default class Drop extends Command {
constructor() { constructor() {
@ -20,6 +21,15 @@ 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);

View file

@ -35,6 +35,14 @@ export default class Card extends CardBaseEntity {
@ManyToOne(() => Series, x => x.Cards) @ManyToOne(() => Series, x => x.Cards)
Series: Series; Series: Series;
public static async FetchOneByCardNumber(cardNumber: string, relations?: string[]): Promise<Card | null> {
const repository = CardDataSource.getRepository(Card);
const single = await repository.findOne({ where: { CardNumber: cardNumber }, relations: relations || [] });
return single;
}
public static async FetchAllByRarity(rarity: CardRarity, relations?: string[]): Promise<Card[]> { public static async FetchAllByRarity(rarity: CardRarity, relations?: string[]): Promise<Card[]> {
const repository = CardDataSource.getRepository(Card); const repository = CardDataSource.getRepository(Card);