Update card database to use JSON files (#107)
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. - Updated the card database to use JSON files instead of directly assuming the file system into a SQLITE database - Removed sqlite3 package #27 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) # 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 using my dev bot - I have tested using an up-to-date copy of the google drive data # 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/107 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
2091e326b8
commit
be7a7c4ca4
19 changed files with 575 additions and 363 deletions
|
@ -1,10 +1,11 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import CardRarityChances from "../constants/CardRarityChances";
|
||||
import Card from "../database/entities/card/Card";
|
||||
import { DropResult } from "../contracts/SeriesMetadata";
|
||||
import { CoreClient } from "../client/client";
|
||||
|
||||
export default class CardDropHelper {
|
||||
public static async GetRandomCard(): Promise<Card> {
|
||||
export default class CardDropHelperMetadata {
|
||||
public static GetRandomCard(): DropResult | undefined {
|
||||
const randomRarity = Math.random() * 100;
|
||||
|
||||
let cardRarity: CardRarity;
|
||||
|
@ -20,39 +21,50 @@ export default class CardDropHelper {
|
|||
else if (randomRarity < mangaChance) cardRarity = CardRarity.Manga;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const randomCard = await this.GetRandomCardByRarity(cardRarity);
|
||||
const randomCard = this.GetRandomCardByRarity(cardRarity);
|
||||
|
||||
return randomCard;
|
||||
}
|
||||
|
||||
public static async GetRandomCardByRarity(rarity: CardRarity): Promise<Card> {
|
||||
const allCards = await Card.FetchAllByRarity(rarity, [ "Series" ]);
|
||||
public static GetRandomCardByRarity(rarity: CardRarity): DropResult | undefined {
|
||||
const allCards = CoreClient.Cards
|
||||
.flatMap(x => x.cards)
|
||||
.filter(x => x.type == rarity);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
||||
const card = allCards[randomCardIndex];
|
||||
const series = CoreClient.Cards
|
||||
.find(x => x.cards.includes(card));
|
||||
|
||||
return card;
|
||||
if (!series) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
series: series,
|
||||
card: card,
|
||||
};
|
||||
}
|
||||
|
||||
public static GenerateDropEmbed(card: Card, quantityClaimed: Number): EmbedBuilder {
|
||||
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: Number, imageFileName: string): EmbedBuilder {
|
||||
let description = "";
|
||||
description += `Series: ${card.Series.Name}\n`;
|
||||
description += `Series: ${drop.series.name}\n`;
|
||||
description += `Claimed: ${quantityClaimed}\n`;
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setTitle(card.Name)
|
||||
.setTitle(drop.card.name)
|
||||
.setDescription(description)
|
||||
.setFooter({ text: CardRarityToString(card.Rarity) })
|
||||
.setColor(CardRarityToColour(card.Rarity))
|
||||
.setImage(`attachment://${card.FileName}`);
|
||||
.setFooter({ text: CardRarityToString(drop.card.type) })
|
||||
.setColor(CardRarityToColour(drop.card.type))
|
||||
.setImage(`attachment://${imageFileName}`);
|
||||
}
|
||||
|
||||
public static GenerateDropButtons(card: Card, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> {
|
||||
public static GenerateDropButtons(drop: DropResult, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> {
|
||||
return new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`claim ${card.CardNumber} ${claimId} ${userId}`)
|
||||
.setCustomId(`claim ${drop.card.id} ${claimId} ${userId}`)
|
||||
.setLabel("Claim")
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder()
|
Loading…
Add table
Add a link
Reference in a new issue