From 6b9d71758a6b936bb34869bd166df6f58453b98d Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 1 Jun 2024 14:52:38 +0100 Subject: [PATCH] Add a warning to the logs if an ID is used twice (#248) # 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. - Make the bot log a warning if the card metadata function finds duplicated ids #233 ## 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://git.vylpes.xyz/External/card-drop/pulls/248 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- src/Functions/CardMetadataFunction.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Functions/CardMetadataFunction.ts b/src/Functions/CardMetadataFunction.ts index 733c50c..a2499d9 100644 --- a/src/Functions/CardMetadataFunction.ts +++ b/src/Functions/CardMetadataFunction.ts @@ -39,6 +39,13 @@ export default class CardMetadataFunction { CoreClient.Cards = cardResult.Result!; AppLogger.LogInfo("Functions/CardMetadataFunction", `Loaded ${CoreClient.Cards.flatMap(x => x.cards).length} cards to database`); + const duplicateCards = CoreClient.Cards.flatMap(x => x.cards) + .filter((card, index, self) => self.findIndex(c => c.id === card.id) !== index); + + if (duplicateCards.length > 0) { + AppLogger.LogWarn("Functions/CardMetadataFunction", `Duplicate card ids found: ${duplicateCards.flatMap(x => x.id).join(", ")}`); + } + return { IsSuccess: true, };