From e224796d865095fc42e4993dbd3672a12569c3f4 Mon Sep 17 00:00:00 2001 From: ZRunner Date: Thu, 24 Oct 2024 22:43:29 +0200 Subject: [PATCH] feat(event): add Halloween 2024 event --- core/enums.py | 1 + events-list.json | 42 +++++++++++++++++++ modules/bot_events/bot_events.py | 6 +-- .../bot_events/data/events-translations.json | 12 ++++++ .../subcogs/random_collect_subcog.py | 15 +++---- 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/core/enums.py b/core/enums.py index e4ae2f1b4..f953c3286 100644 --- a/core/enums.py +++ b/core/enums.py @@ -35,6 +35,7 @@ class RankCardsFlag(_BaseFlagClass): 1 << 13: "halloween23", 1 << 14: "christmas23", 1 << 15: "april24", + 1 << 16: "halloween24", } class UserFlag(_BaseFlagClass): diff --git a/events-list.json b/events-list.json index cfbe5cf92..5ef4248d6 100644 --- a/events-list.json +++ b/events-list.json @@ -289,5 +289,47 @@ ], "probability": 0.18 } + }, + "halloween-2024": { + "begin": "2024-10-29", + "end": "2024-11-01", + "type": "halloween", + "icon": "https://zrunner.me/cdn/halloween_2024.png", + "color": 16089635, + "objectives": [ + { + "points": 250, + "reward_type": "rankcard", + "rank_card": "halloween24" + }, + { + "points": 500, + "reward_type": "role", + "role_id": 1299069272340955191 + } + ], + "emojis": { + "reactions_list": [ + "🦇", + "🎃", + "🕷️", + "👻", + "🪦", + "🧙" + ], + "triggers": [ + "booh", + "halloween", + "witch", + "ghost", + "pumpkin", + "tombstone", + "sorcière", + "fantôme", + "citrouille", + "tombe" + ], + "probability": 0.05 + } } } \ No newline at end of file diff --git a/modules/bot_events/bot_events.py b/modules/bot_events/bot_events.py index aaf0108b4..5ba193b4b 100644 --- a/modules/bot_events/bot_events.py +++ b/modules/bot_events/bot_events.py @@ -12,7 +12,7 @@ from core.formatutils import FormatUtils from .data import EventData, EventRewardRole, EventType -from .subcogs import AbstractSubcog, SingleReactionSubcog +from .subcogs import AbstractSubcog, RandomCollectSubcog class BotEvents(commands.Cog): @@ -32,7 +32,7 @@ def __init__(self, bot: Axobot): self.coming_event_id: str | None = None self.update_current_event() - self._subcog: AbstractSubcog = SingleReactionSubcog( + self._subcog: AbstractSubcog = RandomCollectSubcog( self.bot, self.current_event, self.current_event_data, self.current_event_id) @property @@ -40,7 +40,7 @@ def subcog(self) -> AbstractSubcog: "Return the subcog populated with the current event data" if self._subcog.current_event != self.current_event or self._subcog.current_event_data != self.current_event_data: self.log.debug("Updating subcog with new data") - self._subcog = SingleReactionSubcog(self.bot, self.current_event, self.current_event_data, self.current_event_id) + self._subcog = RandomCollectSubcog(self.bot, self.current_event, self.current_event_data, self.current_event_id) return self._subcog async def cog_load(self): diff --git a/modules/bot_events/data/events-translations.json b/modules/bot_events/data/events-translations.json index ed435652f..d065c03be 100644 --- a/modules/bot_events/data/events-translations.json +++ b/modules/bot_events/data/events-translations.json @@ -9,6 +9,7 @@ "halloween-2023": "Le mois d'octobre est là ! Profitez jusqu'au 1er novembre d'une atmosphère ténébreuse, remplie de chauve-souris, de squelettes et de citrouilles.\nProfitez-en pour redécorer votre serveur aux couleurs d'Halloween avec la commande `/halloween lightfy` et ses dérivées, vérifiez que votre avatar soit bien conforme avec la commande `/halloween check`, et récupérez des points d'événements le plus régulièrement possible avec la commande `/event collect`.\n\nLes plus téméraires d'entre vous réussirons peut-être à débloquer la carte d'xp spécial Halloween 2023, que vous pourrez utiliser via la commande `/profile card` !", "christmas-2023": "Noël approche ! Pendant le mois de décembre, participez aux festivités en collectant votre récompense chaque jour du calendrier de l'avent, jouez au morpion pour gagner des points d'événement, et récupérez la carte d'XP spécial Noël 2023 le 25 décembre avec `/event collect` !\nLes trois meilleurs participants (hors équipe du bot) gagneront même un **mois d'abonnement Nitro !**", "april-2024": "La journée internationale des poissons fait son retour ! Pendant toute la journée, Axobot fêtera le 1er avril avec des réactions aléatoires sur le thème des poissons, des commandes uniques ainsi que d'autres choses trop cool.\nAvec un peu de chance, vous trouverez peut-être la carte d'xp collector cachée dans les réactions !\n\nPour rappel, les cartes d'xp sont accessibles via ma commande `profile card`", + "halloween-2024": "Le mois d'octobre est là ! Profitez jusqu'au 1er novembre d'une atmosphère ténébreuse, remplie de chauve-souris, de squelettes et de citrouilles.\nRécupérez des points d'événements le plus régulièrement possible avec la commande `/event collect` : les plus téméraires d'entre vous réussirons peut-être à débloquer la carte d'xp spécial Halloween 2024, que vous pourrez utiliser via la commande `/profile card` !", "test-2022": "Test event!" }, "events_prices": { @@ -36,6 +37,10 @@ }, "april-2024": { "1": "Débloquez la carte d'xp Avril 2024, obtenable pendant seulement 24h !" + }, + "halloween-2024": { + "250": "Débloquez la carte d'xp Halloween 2024, obtenable uniquement pendant cet événement !", + "500": "Venez réclamer votre rôle spécial Halloween 2024 sur le serveur officiel d'Axobot !" } }, "events_title": { @@ -47,6 +52,7 @@ "halloween-2023": "Le temps des citrouilles est arrivé !", "christmas-2023": "Joyeux Noël !", "april-2024": "Joyeux 1er avril !", + "halloween-2024": "Le temps des citrouilles est arrivé !", "test-2022": "Test event!" } }, @@ -60,6 +66,7 @@ "halloween-2023": "October is upon us! Until November 1st, you'll be able to enjoy an atmosphere of darkness, full of bats, skeletons and pumpkins.\nTake advantage of this time to redecorate your server in Halloween colors with the `/halloween lightfy` command and its derivatives, check that your avatar is in tune with the `/halloween check` command, and collect event points as regularly as possible with the `/event collect` command. \nThe most daring among you may even manage to unlock the special Halloween 2023 xp card, which you will be able to use via the `/profile card` command!", "christmas-2023": "Christmas is coming! During the month of December, take part in the festivities by collecting your reward each day of the advent calendar, play tic-tac-toe to earn event points, and collect the special Christmas 2023 XP card on December 25 with `/event collect`!\nThe three best participants (excluding the bot staff) will even win **a month's Nitro subscription!**", "april-2024": "International Fish Day is back! Throughout the day, Axobot will be celebrating April 1st with random fish-themed reactions, unique commands and other cool stuff.\nWith a little luck, you might find the hidden collector's XP card in the reactions!\n\nAs a reminder, the XP cards are accessible via my `profile card` command", + "halloween-2024": "October is here! Enjoy a dark atmosphere full of bats, skeletons and pumpkins until November 1st.\nCollect event points as regularly as possible with the `/event collect` command: the most daring among you may succeed in unlocking the special Halloween 2024 xp card, which you will be able to use via the `/profile card` command!", "test-2022": "Test event!" }, "events_prices": { @@ -87,6 +94,10 @@ }, "april-2024": { "1": "Unlock the April 2024 xp card, obtainable only for 24h!" + }, + "halloween-2024": { + "250": "Unlock the Halloween 2024 xp card, obtainable only during this event!", + "500": "Come claim your special Halloween 2024 role on the official Axobot server!" } }, "events_title": { @@ -98,6 +109,7 @@ "halloween-2023": "It's pumpkin time!", "christmas-2023": "Merry Christmas!", "april-2024": "Happy April 1st!", + "halloween-2024": "It's pumpkin time!", "test-2022": "Test event!" } } diff --git a/modules/bot_events/subcogs/random_collect_subcog.py b/modules/bot_events/subcogs/random_collect_subcog.py index 9b96bd165..6512a5109 100644 --- a/modules/bot_events/subcogs/random_collect_subcog.py +++ b/modules/bot_events/subcogs/random_collect_subcog.py @@ -1,10 +1,10 @@ +import time from collections import defaultdict from random import choice, choices, lognormvariate, randint, random import discord from core.bot_classes import Axobot -from core.formatutils import FormatUtils from ..data.dict_types import EventData, EventItem, EventType from .abstract_subcog import AbstractSubcog @@ -17,10 +17,12 @@ def __init__(self, bot: Axobot, current_event: EventType | None, current_event_data: EventData, current_event_id: str | None): super().__init__(bot, current_event, current_event_data, current_event_id) - self.collect_reward = [-8, 25] + self.collect_reward = [-8, 25] # points given when no item is collected self.collect_cooldown = 60*60 # (1h) time in seconds between 2 collects self.collect_max_strike_period = 3600 * 2 # (2h) time in seconds after which the strike level is reset to 0 - self.collect_bonus_per_strike = 1.05 # the amount of points is multiplied by this number for each strike level + self.collect_bonus_per_strike = 1.07 # the amount of points is multiplied by this number for each strike level + self.normvariate_params = (2.8, 1.2) # parameters for the lognormal distribution (average, standard deviation) + self.max_items_per_collect = 10 # maximum number of items that can be collected at once async def on_message(self, msg): "Add random reaction to some messages" @@ -86,9 +88,8 @@ async def collect_cmd(self, interaction): can_collect, is_strike = await self.check_user_collect_availability(interaction.user.id, seconds_since_last_collect) if not can_collect: # cooldown error - time_remaining = self.collect_cooldown - seconds_since_last_collect - remaining = await FormatUtils.time_delta(time_remaining, lang=lang) - txt = await self.bot._(interaction, "bot_events.collect.too-quick", time=remaining) + time_to_next_collect = time.time() - seconds_since_last_collect + self.collect_cooldown + txt = await self.bot._(interaction, "bot_events.collect.too-quick", time=f"") else: # grant points items = await self.get_random_items() @@ -147,7 +148,7 @@ async def get_random_items(self) -> list[EventItem]: "Get some random items to win during an event" if self.current_event is None: return [] - items_count = min(round(lognormvariate(1.1, 0.9)), 8) # random number between 0 and 8 + items_count = min(round(lognormvariate(*self.normvariate_params)), self.max_items_per_collect) if items_count <= 0: return [] items = await self.db_get_event_items(self.current_event)