Create an admin command to give a breakdown of card stats
All checks were successful
Test / build (push) Successful in 9s

- Created a  command for admins to see what cards have been added by type
- Added this information to the logger

#350
This commit is contained in:
Ethan Lane 2024-08-30 18:47:04 +01:00
parent 5deb6fcc14
commit e8b20004bd
3 changed files with 70 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import { glob } from "glob";
import { SeriesMetadata } from "../contracts/SeriesMetadata"; import { SeriesMetadata } from "../contracts/SeriesMetadata";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
import AppLogger from "../client/appLogger"; import AppLogger from "../client/appLogger";
import {CardRarity} from "../constants/CardRarity";
export interface CardMetadataResult { export interface CardMetadataResult {
IsSuccess: boolean; IsSuccess: boolean;
@ -37,7 +38,22 @@ export default class CardMetadataFunction {
if (cardResult.IsSuccess) { if (cardResult.IsSuccess) {
CoreClient.Cards = cardResult.Result!; CoreClient.Cards = cardResult.Result!;
AppLogger.LogInfo("Functions/CardMetadataFunction", `Loaded ${CoreClient.Cards.flatMap(x => x.cards).length} cards to database`);
const allCards = CoreClient.Cards.flatMap(x => x.cards);
const totalCards = allCards.length;
const bronzeCards = allCards.filter(x => x.type == CardRarity.Bronze)
.length;
const silverCards = allCards.filter(x => x.type == CardRarity.Silver)
.length;
const goldCards = allCards.filter(x => x.type == CardRarity.Gold)
.length;
const mangaCards = allCards.filter(x => x.type == CardRarity.Manga)
.length;
const legendaryCards = allCards.filter(x => x.type == CardRarity.Legendary)
.length;
AppLogger.LogInfo("Functions/CardMetadataFunction", `Loaded ${totalCards} cards to database (${bronzeCards} bronze, ${silverCards} silver, ${goldCards} gold, ${mangaCards} manga, ${legendaryCards} legendary)`);
const duplicateCards = CoreClient.Cards.flatMap(x => x.cards) const duplicateCards = CoreClient.Cards.flatMap(x => x.cards)
.filter((card, index, self) => self.findIndex(c => c.id === card.id) !== index); .filter((card, index, self) => self.findIndex(c => c.id === card.id) !== index);

51
src/commands/stats.ts Normal file
View file

@ -0,0 +1,51 @@
import {CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder} from "discord.js";
import {Command} from "../type/command";
import {CoreClient} from "../client/client";
import {CardRarity} from "../constants/CardRarity";
import EmbedColours from "../constants/EmbedColours";
export default class Stats extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("stats")
.setDescription("Get bot stats such as card info")
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
}
public override async execute(interaction: CommandInteraction) {
const allCards = CoreClient.Cards.flatMap(x => x.cards);
const totalCards = allCards.length;
const bronzeCards = allCards.filter(x => x.type == CardRarity.Bronze)
.length;
const silverCards = allCards.filter(x => x.type == CardRarity.Silver)
.length;
const goldCards = allCards.filter(x => x.type == CardRarity.Gold)
.length;
const mangaCards = allCards.filter(x => x.type == CardRarity.Manga)
.length;
const legendaryCards = allCards.filter(x => x.type == CardRarity.Legendary)
.length;
const description = [
`${totalCards} Total`,
`${bronzeCards} Bronze`,
`${silverCards} Silver`,
`${goldCards} Gold`,
`${mangaCards} Manga`,
`${legendaryCards} Legendary`,
].join("\n");
const embed = new EmbedBuilder()
.setTitle("Stats")
.setDescription(description)
.setColor(EmbedColours.Ok);
await interaction.reply({
embeds: [ embed ],
ephemeral: true,
});
}
}

View file

@ -13,6 +13,7 @@ import Inventory from "./commands/inventory";
import Resync from "./commands/resync"; import Resync from "./commands/resync";
import Sacrifice from "./commands/sacrifice"; import Sacrifice from "./commands/sacrifice";
import Series from "./commands/series"; import Series from "./commands/series";
import Stats from "./commands/stats";
import Trade from "./commands/trade"; import Trade from "./commands/trade";
import View from "./commands/view"; import View from "./commands/view";
@ -42,6 +43,7 @@ export default class Registry {
CoreClient.RegisterCommand("resync", new Resync()); CoreClient.RegisterCommand("resync", new Resync());
CoreClient.RegisterCommand("sacrifice", new Sacrifice()); CoreClient.RegisterCommand("sacrifice", new Sacrifice());
CoreClient.RegisterCommand("series", new Series()); CoreClient.RegisterCommand("series", new Series());
CoreClient.RegisterCommand("stats", new Stats());
CoreClient.RegisterCommand("trade", new Trade()); CoreClient.RegisterCommand("trade", new Trade());
CoreClient.RegisterCommand("view", new View()); CoreClient.RegisterCommand("view", new View());