From a10eaf7d751eb3aa9ffee29edf1af0f4d89cbe79 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 29 Aug 2024 18:53:09 +0100 Subject: [PATCH 1/5] Make the rarity text on the series embed lower case To be more consistent with the inventory command #348 --- src/helpers/SeriesHelper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/SeriesHelper.ts b/src/helpers/SeriesHelper.ts index c3a22d6..5469938 100644 --- a/src/helpers/SeriesHelper.ts +++ b/src/helpers/SeriesHelper.ts @@ -31,7 +31,7 @@ export default class SeriesHelper { const cardsOnPage = series.cards.splice(page * itemsPerPage, itemsPerPage); const description = cardsOnPage - .map(x => `[${x.id}] ${x.name} ${CardRarityToString(x.type).toUpperCase()}`) + .map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)})`) .join("\n"); const embed = new EmbedBuilder() From 5deb6fcc1488a7b8d17edd401eb7f8df72ad9490 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 29 Aug 2024 19:21:53 +0100 Subject: [PATCH 2/5] Add a colour override for embed colours - Using a new optional value in the JSON, if set overrides the default one set by the rarity - Added a failsafe if the override colour is invalid to default and log a warning #349 --- src/contracts/SeriesMetadata.ts | 1 + src/helpers/CardDropHelperMetadata.ts | 16 +++++++++++++++- src/helpers/StringTools.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/contracts/SeriesMetadata.ts b/src/contracts/SeriesMetadata.ts index 4a989bc..4dd2eb9 100644 --- a/src/contracts/SeriesMetadata.ts +++ b/src/contracts/SeriesMetadata.ts @@ -12,6 +12,7 @@ export interface CardMetadata { type: CardRarity, path: string, subseries?: string, + colour?: string, } export interface DropResult { diff --git a/src/helpers/CardDropHelperMetadata.ts b/src/helpers/CardDropHelperMetadata.ts index 84bcdfa..bc59e93 100644 --- a/src/helpers/CardDropHelperMetadata.ts +++ b/src/helpers/CardDropHelperMetadata.ts @@ -5,6 +5,7 @@ import { DropResult } from "../contracts/SeriesMetadata"; import { CoreClient } from "../client/client"; import AppLogger from "../client/appLogger"; import CardConstants from "../constants/CardConstants"; +import StringTools from "./StringTools"; export default class CardDropHelperMetadata { public static GetRandomCard(): DropResult | undefined { @@ -82,12 +83,25 @@ export default class CardDropHelperMetadata { AppLogger.LogSilly("CardDropHelperMetadata/GenerateDropEmbed", `Parameters: drop=${drop.card.id}, quantityClaimed=${quantityClaimed}, imageFileName=${imageFileName}`); const description = drop.card.subseries ?? drop.series.name; + let colour = CardRarityToColour(drop.card.type); + + if (drop.card.colour && StringTools.IsHexCode(drop.card.colour)) { + const hexCode = Number("0x" + drop.card.colour); + + if (hexCode) { + colour = hexCode; + } else { + AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`); + } + } else if (drop.card.colour) { + AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`); + } const embed = new EmbedBuilder() .setTitle(drop.card.name) .setDescription(description) .setFooter({ text: `${CardRarityToString(drop.card.type)} ยท ${drop.card.id}` }) - .setColor(CardRarityToColour(drop.card.type)) + .setColor(colour) .setImage(`attachment://${imageFileName}`) .addFields([ { diff --git a/src/helpers/StringTools.ts b/src/helpers/StringTools.ts index cb5591a..1e43ded 100644 --- a/src/helpers/StringTools.ts +++ b/src/helpers/StringTools.ts @@ -39,4 +39,18 @@ export default class StringTools { public static ReplaceAll(str: string, find: string, replace: string) { return str.replace(new RegExp(find, "g"), replace); } + + public static IsHexCode(str: string): boolean { + if (str.length != 6) return false; + + const characters = "0123456789abcdefABCDEF"; + + for (let i = 0; i < 6; i++) { + const char = str[i]; + + if (!characters.includes(char)) return false; + } + + return true; + } } \ No newline at end of file From e8b20004bd7fdf88e60c311abed9647904401f3a Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 30 Aug 2024 18:47:04 +0100 Subject: [PATCH 3/5] Create an admin command to give a breakdown of card stats - Created a command for admins to see what cards have been added by type - Added this information to the logger #350 --- src/Functions/CardMetadataFunction.ts | 18 +++++++++- src/commands/stats.ts | 51 +++++++++++++++++++++++++++ src/registry.ts | 2 ++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/commands/stats.ts diff --git a/src/Functions/CardMetadataFunction.ts b/src/Functions/CardMetadataFunction.ts index a2499d9..9b10665 100644 --- a/src/Functions/CardMetadataFunction.ts +++ b/src/Functions/CardMetadataFunction.ts @@ -5,6 +5,7 @@ import { glob } from "glob"; import { SeriesMetadata } from "../contracts/SeriesMetadata"; import { CoreClient } from "../client/client"; import AppLogger from "../client/appLogger"; +import {CardRarity} from "../constants/CardRarity"; export interface CardMetadataResult { IsSuccess: boolean; @@ -37,7 +38,22 @@ export default class CardMetadataFunction { if (cardResult.IsSuccess) { 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) .filter((card, index, self) => self.findIndex(c => c.id === card.id) !== index); diff --git a/src/commands/stats.ts b/src/commands/stats.ts new file mode 100644 index 0000000..e65ab93 --- /dev/null +++ b/src/commands/stats.ts @@ -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, + }); + } +} diff --git a/src/registry.ts b/src/registry.ts index 86b2b68..5ba3af6 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -13,6 +13,7 @@ import Inventory from "./commands/inventory"; import Resync from "./commands/resync"; import Sacrifice from "./commands/sacrifice"; import Series from "./commands/series"; +import Stats from "./commands/stats"; import Trade from "./commands/trade"; import View from "./commands/view"; @@ -42,6 +43,7 @@ export default class Registry { CoreClient.RegisterCommand("resync", new Resync()); CoreClient.RegisterCommand("sacrifice", new Sacrifice()); CoreClient.RegisterCommand("series", new Series()); + CoreClient.RegisterCommand("stats", new Stats()); CoreClient.RegisterCommand("trade", new Trade()); CoreClient.RegisterCommand("view", new View()); From 93b12bbbf6b1da8bc5cb14e5df245fc14cee52cd Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 31 Aug 2024 13:37:16 +0100 Subject: [PATCH 4/5] 0.8.1 --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 00a861f..8f1bfc6 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.8.0 +BOT_VER=0.8.1 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 From 65a55895e75ac548bba6516c179ca2ef2fe309ed Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 31 Aug 2024 13:37:22 +0100 Subject: [PATCH 5/5] v0.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9126a28..292f0c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-drop", - "version": "0.8.0", + "version": "0.8.1", "main": "./dist/bot.js", "typings": "./dist", "scripts": {