From 8e1cd51dd93ebb0c68d643ff942c874abd212057 Mon Sep 17 00:00:00 2001
From: ZRunner <z.runner.mc@gmail.com>
Date: Sun, 19 Nov 2023 11:11:01 -0500
Subject: [PATCH] feat(event): add christmas 2023 xp card

---
 events-list.json                            |  4 ++--
 fcts/users.py                               |  2 +-
 libs/bot_events/subcogs/christmas_subcog.py | 15 ++++++++-------
 libs/enums.py                               |  1 +
 libs/xp_cards/cards_data.json               | 11 +++++++++++
 libs/xp_cards/cards_metadata.py             |  4 +++-
 6 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/events-list.json b/events-list.json
index 61636ec4d..5b2ed8446 100644
--- a/events-list.json
+++ b/events-list.json
@@ -204,7 +204,7 @@
         }
     },
     "christmas-2023": {
-        "begin": "2023-11-01",
+        "begin": "2023-12-01",
         "end": "2023-12-31",
         "type": "christmas",
         "icon": "https://zrunner.me/cdn/halloween_2023.png",
@@ -252,7 +252,7 @@
                 "lutin",
                 "cookie"
             ],
-            "probability": 0.91
+            "probability": 0.1
         }
     }
 }
\ No newline at end of file
diff --git a/fcts/users.py b/fcts/users.py
index 17317c916..ad2c242e2 100644
--- a/fcts/users.py
+++ b/fcts/users.py
@@ -213,7 +213,7 @@ async def cardpreview_autocomplete_style(self, inter: discord.Interaction, curre
     async def profile_card(self, ctx: MyContext, style: args.CardStyle):
         """Change your xp card style.
 
-        ..Example profile card christmas20
+        ..Example profile card christmas23
 
         ..Doc user.html#change-your-xp-card"""
         if style is None and len(ctx.view.buffer.split(' ')) > 2:
diff --git a/libs/bot_events/subcogs/christmas_subcog.py b/libs/bot_events/subcogs/christmas_subcog.py
index d6039211b..2756bb196 100644
--- a/libs/bot_events/subcogs/christmas_subcog.py
+++ b/libs/bot_events/subcogs/christmas_subcog.py
@@ -161,9 +161,9 @@ async def collect_cmd(self, ctx):
         else:
             await ctx.send(txt)
         # add points (and potentially grant reward rank card)
-        if gifts:
-            await self.db_add_collect(ctx.author.id, sum(item["points"] for item in gifts))
+        await self.db_add_collect(ctx.author.id, sum(item["points"] for item in gifts))
 
+    @acached(60*2) # cache for 2min
     async def today(self):
         return dt.datetime.now(dt.timezone.utc).date()
         # return dt.date(2023, 12, 1)
@@ -262,11 +262,12 @@ async def db_add_collect(self, user_id: int, points: int):
         """Add collect points to a user"""
         if not self.bot.database_online or self.bot.current_event is None:
             return
-        query = "INSERT INTO `event_points` (`user_id`, `collect_points`, `beta`) VALUES (%s, %s, %s) \
-            ON DUPLICATE KEY UPDATE collect_points = collect_points + VALUE(`collect_points`), \
-                last_collect = CURRENT_TIMESTAMP();"
-        async with self.bot.db_query(query, (user_id, points, self.bot.beta)):
-            pass
+        if points:
+            query = "INSERT INTO `event_points` (`user_id`, `collect_points`, `beta`) VALUES (%s, %s, %s) \
+                ON DUPLICATE KEY UPDATE collect_points = collect_points + VALUE(`collect_points`), \
+                    last_collect = CURRENT_TIMESTAMP();"
+            async with self.bot.db_query(query, (user_id, points, self.bot.beta)):
+                pass
         if cog := self.bot.get_cog("BotEvents"):
             try:
                 await cog.reload_event_rankcard(user_id)
diff --git a/libs/enums.py b/libs/enums.py
index 662874ac5..e595b8827 100644
--- a/libs/enums.py
+++ b/libs/enums.py
@@ -21,6 +21,7 @@ class RankCardsFlag:
         1 << 11: "christmas22",
         1 << 12: "blurple23",
         1 << 13: "halloween23",
+        1 << 14: "christmas23",
     }
 
     def flags_to_int(self, flags: list) -> int:
diff --git a/libs/xp_cards/cards_data.json b/libs/xp_cards/cards_data.json
index 4aadc164f..a764f0862 100644
--- a/libs/xp_cards/cards_data.json
+++ b/libs/xp_cards/cards_data.json
@@ -290,6 +290,17 @@
                 "total_xp_with_text": [255, 140, 26]
             }
         },
+        "christmas23": {
+            "xp_bar": [255, 153, 204],
+            "texts": {
+                "username": [255, 255, 255],
+                "level": [255, 255, 255],
+                "rank": [255, 255, 255],
+                "participants": [255, 255, 255],
+                "xp_to_next_level_with_text": [255, 255, 255],
+                "total_xp_with_text": [255, 255, 255]
+            }
+        },
         "premium": {
             "xp_bar": [255, 255, 102],
             "texts": {
diff --git a/libs/xp_cards/cards_metadata.py b/libs/xp_cards/cards_metadata.py
index b862bf78a..9ac6d72ee 100644
--- a/libs/xp_cards/cards_metadata.py
+++ b/libs/xp_cards/cards_metadata.py
@@ -1,7 +1,8 @@
 import json
 import os
 
-from libs.xp_cards.card_types import CardData, CardMetaData, TextData, TextMetaData, ColorsData
+from libs.xp_cards.card_types import (CardData, CardMetaData, ColorsData,
+                                      TextData, TextMetaData)
 
 V1_CARDS = {
     "april22",
@@ -35,6 +36,7 @@
     "support",
     "blurple23",
     "halloween23",
+    "christmas23"
 }
 
 JSON_DATA_FILE = os.path.dirname(__file__) + "/cards_data.json"