Add logger to project (#183)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
# 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 the winston package to handle logging - Add logging to the project's logic #146 ## 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. # Checklist - [ ] My code follows the style guidelines of this project - [ ] 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 - [ ] 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/183 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
42dfe2d047
commit
5dd50a3f3b
27 changed files with 465 additions and 26 deletions
|
@ -3,6 +3,7 @@ import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants
|
|||
import CardRarityChances from "../constants/CardRarityChances";
|
||||
import { CardMetadata, DropResult } from "../contracts/SeriesMetadata";
|
||||
import { CoreClient } from "../client/client";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
export default class CardDropHelperMetadata {
|
||||
public static GetRandomCard(): DropResult | undefined {
|
||||
|
@ -23,10 +24,14 @@ export default class CardDropHelperMetadata {
|
|||
|
||||
const randomCard = this.GetRandomCardByRarity(cardRarity);
|
||||
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCard", `Random card: ${randomCard?.card.id} ${randomCard?.card.name}`);
|
||||
|
||||
return randomCard;
|
||||
}
|
||||
|
||||
public static GetRandomCardByRarity(rarity: CardRarity): DropResult | undefined {
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarity", `Parameters: rarity=${rarity}`);
|
||||
|
||||
const allCards = CoreClient.Cards
|
||||
.flatMap(x => x.cards)
|
||||
.filter(x => x.type == rarity);
|
||||
|
@ -38,9 +43,13 @@ export default class CardDropHelperMetadata {
|
|||
.find(x => x.cards.includes(card));
|
||||
|
||||
if (!series) {
|
||||
AppLogger.LogWarn("CardDropHelperMetadata/GetRandomCardByRarity", `Series not found for card ${card.id}`);
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarity", `Random card: ${card.id} ${card.name}`);
|
||||
|
||||
return {
|
||||
series: series,
|
||||
card: card,
|
||||
|
@ -48,14 +57,20 @@ export default class CardDropHelperMetadata {
|
|||
}
|
||||
|
||||
public static GetCardByCardNumber(cardNumber: string): CardMetadata | undefined {
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetCardByCardNumber", `Parameters: cardNumber=${cardNumber}`);
|
||||
|
||||
const card = CoreClient.Cards
|
||||
.flatMap(x => x.cards)
|
||||
.find(x => x.id == cardNumber);
|
||||
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetCardByCardNumber", `Card: ${card?.id} ${card?.name}`);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: number, imageFileName: string): EmbedBuilder {
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GenerateDropEmbed", `Parameters: drop=${drop.card.id}, quantityClaimed=${quantityClaimed}, imageFileName=${imageFileName}`);
|
||||
|
||||
let description = "";
|
||||
description += `Series: ${drop.series.name}\n`;
|
||||
description += `Claimed: ${quantityClaimed}\n`;
|
||||
|
@ -69,6 +84,8 @@ export default class CardDropHelperMetadata {
|
|||
}
|
||||
|
||||
public static GenerateDropButtons(drop: DropResult, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> {
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GenerateDropButtons", `Parameters: drop=${drop.card.id}, claimId=${claimId}, userId=${userId}`);
|
||||
|
||||
return new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
|
|
|
@ -4,6 +4,7 @@ import { CoreClient } from "../client/client";
|
|||
import EmbedColours from "../constants/EmbedColours";
|
||||
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
||||
import cloneDeep from "clone-deep";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
interface InventoryPage {
|
||||
id: number,
|
||||
|
@ -21,6 +22,8 @@ interface InventoryPageCards {
|
|||
|
||||
export default class InventoryHelper {
|
||||
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
|
||||
AppLogger.LogSilly("Helpers/InventoryHelper", `Parameters: username=${username}, userid=${userid}, page=${page}`);
|
||||
|
||||
const cardsPerPage = 15;
|
||||
|
||||
const inventory = await Inventory.FetchAllByUserId(userid);
|
||||
|
@ -73,7 +76,7 @@ export default class InventoryHelper {
|
|||
const currentPage = pages[page];
|
||||
|
||||
if (!currentPage) {
|
||||
console.error("Unable to find page");
|
||||
AppLogger.LogError("Helpers/InventoryHelper", "Unable to find page");
|
||||
return Promise.reject("Unable to find page");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue