From 07c1fcc827160af15b80f11afab7132551e388ac Mon Sep 17 00:00:00 2001 From: Ilya Shmyrev Date: Wed, 17 Jan 2024 15:01:11 +0500 Subject: [PATCH 1/4] Minor changes in `/gift` --- bot/handlers/cogs/commands.py | 4 +++- bot/locale/en_GB.json | 5 +++-- bot/locale/en_US.json | 5 +++-- bot/locale/pl.json | 5 +++-- bot/locale/ru.json | 5 +++-- bot/locale/uk.json | 5 +++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bot/handlers/cogs/commands.py b/bot/handlers/cogs/commands.py index 4232a54..fedb1d3 100644 --- a/bot/handlers/cogs/commands.py +++ b/bot/handlers/cogs/commands.py @@ -227,7 +227,7 @@ async def top(self, inter: AppCommandInter, await inter.send(embed=embed, view=view) @slash_command() - @cooldown(1, 60, BucketType.user) + @cooldown(1, 300, BucketType.user) async def gift(self, inter: AppCommandInter, channel: disnake.TextChannel, coins: int, message: str = None): """ Gift coins to users in a specific channel {{GIFT}} @@ -248,6 +248,8 @@ async def gift(self, inter: AppCommandInter, channel: disnake.TextChannel, coins message = self.bot.i18n.get("GIFT_DEFAULT_RESPONSE")[lang] elif not is_message_valid(message): raise CommandError("KEEP_RULES") + elif len(message) > 100: + raise CommandError("TEXT_TOO_LONG") if coins <= 0: raise CommandError("INCORRECT_COINS_AMOUNT") diff --git a/bot/locale/en_GB.json b/bot/locale/en_GB.json index cca8242..9400d97 100644 --- a/bot/locale/en_GB.json +++ b/bot/locale/en_GB.json @@ -150,6 +150,7 @@ "ECONOMIC_DATA": "Economic data", "MICROTRANSACTION_REVENUE": "Total revenue from microtransactions", "GIFT_RESPONSE": "A gift of %coins% coins is claimed by %nickname%", - "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again in %time%", - "TOO_LATE": "It's too late" + "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again %time%", + "TOO_LATE": "It's too late", + "TEXT_TOO_LONG": "The text is too long" } \ No newline at end of file diff --git a/bot/locale/en_US.json b/bot/locale/en_US.json index bf0f608..cde312c 100644 --- a/bot/locale/en_US.json +++ b/bot/locale/en_US.json @@ -150,6 +150,7 @@ "ECONOMIC_DATA": "Economic data", "MICROTRANSACTION_REVENUE": "Total revenue from microtransactions", "GIFT_RESPONSE": "A gift of %coins% coins is claimed by %nickname%", - "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again in %time%", - "TOO_LATE": "It's too late" + "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again %time%", + "TOO_LATE": "It's too late", + "TEXT_TOO_LONG": "The text is too long" } \ No newline at end of file diff --git a/bot/locale/pl.json b/bot/locale/pl.json index e6e0bd4..88435ea 100644 --- a/bot/locale/pl.json +++ b/bot/locale/pl.json @@ -150,6 +150,7 @@ "ECONOMIC_DATA": "Dane ekonomiczne", "MICROTRANSACTION_REVENUE": "Całkowite przychody od mikrotranzakcji", "GIFT_RESPONSE": "Prezent w postaci %coins% monet został odebrany przez %nickname%", - "COMMAND_COOLDOWN_RESPONSE": "To polecenie jest w trakcie odnawiania. Spróbuj ponownie za %time%", - "TOO_LATE": "Jest już za późno" + "COMMAND_COOLDOWN_RESPONSE": "To polecenie jest w trakcie odnawiania. Spróbuj ponownie %time%", + "TOO_LATE": "Jest już za późno", + "TEXT_TOO_LONG": "Tekst jest zbyt długi" } \ No newline at end of file diff --git a/bot/locale/ru.json b/bot/locale/ru.json index 2ecd685..3163705 100644 --- a/bot/locale/ru.json +++ b/bot/locale/ru.json @@ -150,6 +150,7 @@ "ECONOMIC_DATA": "Экономические данные", "MICROTRANSACTION_REVENUE": "Общая выручка от микротранзакций", "GIFT_RESPONSE": "Подарок в виде %coins% монет забирает %nickname%", - "COMMAND_COOLDOWN_RESPONSE": "Эта команда находится в режиме ожидания. Повторите попытку через %time%", - "TOO_LATE": "Слишком поздно" + "COMMAND_COOLDOWN_RESPONSE": "Эта команда находится в режиме ожидания. Повторите попытку %time%", + "TOO_LATE": "Слишком поздно", + "TEXT_TOO_LONG": "Текст слишком длинный" } \ No newline at end of file diff --git a/bot/locale/uk.json b/bot/locale/uk.json index 52fe4c6..f6adb43 100644 --- a/bot/locale/uk.json +++ b/bot/locale/uk.json @@ -150,6 +150,7 @@ "ECONOMIC_DATA": "Экономічні дані", "MICROTRANSACTION_REVENUE": "Загальна виручка від мікротранзакцій", "GIFT_RESPONSE": "Подарунок у вигляді %coins% монет забирає %nickname%", - "COMMAND_COOLDOWN_RESPONSE": "Ця команда перебуває у стані охолодження. Спробуйте ще раз через %time%", - "TOO_LATE": "Занадто пізно" + "COMMAND_COOLDOWN_RESPONSE": "Ця команда перебуває у стані охолодження. Спробуйте ще раз %time%", + "TOO_LATE": "Занадто пізно", + "TEXT_TOO_LONG": "Текст занадто довгий" } \ No newline at end of file From f640a57ba060a763590de07f1864726616f48f47 Mon Sep 17 00:00:00 2001 From: Ilya Shmyrev Date: Wed, 17 Jan 2024 15:01:33 +0500 Subject: [PATCH 2/4] Minor changes in `/fundraising open` --- bot/handlers/cogs/fundraising.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/handlers/cogs/fundraising.py b/bot/handlers/cogs/fundraising.py index 370592c..01aa573 100644 --- a/bot/handlers/cogs/fundraising.py +++ b/bot/handlers/cogs/fundraising.py @@ -1,6 +1,6 @@ import disnake from disnake import AppCommandInter, Embed -from disnake.ext.commands import Cog, slash_command, cooldown, BucketType +from disnake.ext.commands import Cog, slash_command, cooldown, BucketType, CommandError from loguru import logger from bot.data.pufflebot.fundraising import Fundraising @@ -37,7 +37,9 @@ async def fundraising_open(self, inter: AppCommandInter, title: str, coins: int # TODO: replace the embed with a picture. lang: str = str(inter.avail_lang) if not is_message_valid(title): - return await inter.send(self.bot.i18n.get("KEEP_RULES")[lang], ephemeral=True) + raise CommandError("KEEP_RULES") + elif len(title) > 100: + raise CommandError("TEXT_TOO_LONG") p: Penguin = await inter.user.penguin current_fundraising = await Fundraising.query.where(Fundraising.penguin_id == p.id).gino.first() From 1489d72ff35e4d73934f0468c5e15cc878d2b310 Mon Sep 17 00:00:00 2001 From: Ilya Shmyrev Date: Wed, 17 Jan 2024 15:15:15 +0500 Subject: [PATCH 3/4] Minor refactoring --- bot/core/disnaleOverride.py | 4 ++-- bot/misc/constants.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/core/disnaleOverride.py b/bot/core/disnaleOverride.py index 463af17..677ab08 100644 --- a/bot/core/disnaleOverride.py +++ b/bot/core/disnaleOverride.py @@ -1,7 +1,7 @@ import disnake import bot.data.pufflebot.user -from bot.misc.constants import available_languages +from bot.misc.constants import available_languages, default_language from bot.misc.penguin import Penguin from bot.misc.utils import get_penguin_or_none_from_user_id @@ -38,4 +38,4 @@ def __init__(self, *args, **kwargs): @property def avail_lang(self) -> disnake.i18n.Locale: - return self.locale if self.locale in available_languages else disnake.i18n.Locale.en_GB + return self.locale if self.locale in available_languages else default_language diff --git a/bot/misc/constants.py b/bot/misc/constants.py index 1873673..1be169b 100644 --- a/bot/misc/constants.py +++ b/bot/misc/constants.py @@ -29,6 +29,7 @@ commands_without_penguin_requirement = ["ilyash", "online", "login", "top", "settings"] available_languages = [disnake.i18n.Locale.en_GB, disnake.i18n.Locale.en_US, disnake.i18n.Locale.ru, disnake.i18n.Locale.pl, disnake.i18n.Locale.uk] +default_language = disnake.i18n.Locale.en_GB # Bytearrays avatarImageBytearray = BytesIO(get(avatarImageLink).content).getvalue() From ab70c225f0ac5b7196092eecf4c8b65ebc61265e Mon Sep 17 00:00:00 2001 From: Ilya Shmyrev Date: Wed, 17 Jan 2024 16:09:13 +0500 Subject: [PATCH 4/4] Minor changes in `/statistics` --- bot/handlers/cogs/private.py | 8 ++++++-- bot/locale/en_GB.json | 5 +++-- bot/locale/en_US.json | 5 +++-- bot/locale/pl.json | 5 +++-- bot/locale/ru.json | 5 +++-- bot/locale/uk.json | 5 +++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bot/handlers/cogs/private.py b/bot/handlers/cogs/private.py index 45b67bf..bcb74da 100644 --- a/bot/handlers/cogs/private.py +++ b/bot/handlers/cogs/private.py @@ -12,7 +12,7 @@ embedAboutImage, embedAbout, guild_ids, - avatarImageBytearray, placeholderImageLink) + avatarImageBytearray, placeholderImageLink, default_language) from bot.handlers.select import AboutSelect @@ -60,7 +60,11 @@ async def statistics(self, inter: AppCommandInter, await inter.response.defer() try: - start_datetime = datetime.strptime(start_date_str, date_format) + if start_date_str.lower() == self.bot.i18n.get('TODAY')[lang].lower() or start_date_str.lower() == \ + self.bot.i18n.get('TODAY')[str(default_language)].lower(): + start_datetime = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) + else: + start_datetime = datetime.strptime(start_date_str, date_format) if end_date_str: end_datetime = datetime.strptime(end_date_str, date_format) title = (self.bot.i18n.get('STATISTIC_TITLE')[lang] diff --git a/bot/locale/en_GB.json b/bot/locale/en_GB.json index 9400d97..c8de338 100644 --- a/bot/locale/en_GB.json +++ b/bot/locale/en_GB.json @@ -139,7 +139,7 @@ "NOTIFY_GIFT_COINS": "You have received a gift of %coins% coins", "STATISTIC_TITLE": "From %start% to %end%", "STATISTIC_FOOTER": "If the day is not yet over, the data may not be correct", - "INVALID_DATE": "The date `%date%` is invalid. The expected format is `DD/MM/YYYY`", + "INVALID_DATE": "The date `%date%` is invalid. The expected format is `DD/MM/YYYY`, e.g. ", "TOO_EARLY_DATE": "No data are available for the specified period. The earliest available date is ", "PLAYERS_ACTIVITY": "Players activity", "MAX_ONLINE": "Max online", @@ -152,5 +152,6 @@ "GIFT_RESPONSE": "A gift of %coins% coins is claimed by %nickname%", "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again %time%", "TOO_LATE": "It's too late", - "TEXT_TOO_LONG": "The text is too long" + "TEXT_TOO_LONG": "The text is too long", + "TODAY": "Today" } \ No newline at end of file diff --git a/bot/locale/en_US.json b/bot/locale/en_US.json index cde312c..830b8ac 100644 --- a/bot/locale/en_US.json +++ b/bot/locale/en_US.json @@ -139,7 +139,7 @@ "NOTIFY_GIFT_COINS": "You have received a gift of %coins% coins", "STATISTIC_TITLE": "From %start% to %end%", "STATISTIC_FOOTER": "If the day is not yet over, the data may not be correct", - "INVALID_DATE": "The date `%date%` is invalid. The expected format is `MM/DD/YYYY`", + "INVALID_DATE": "The date `%date%` is invalid. The expected format is `MM/DD/YYYY`, e.g. ", "TOO_EARLY_DATE": "No data is available for the specified period. The earliest available date is ", "PLAYERS_ACTIVITY": "Players activity", "MAX_ONLINE": "Max online", @@ -152,5 +152,6 @@ "GIFT_RESPONSE": "A gift of %coins% coins is claimed by %nickname%", "COMMAND_COOLDOWN_RESPONSE": "This command is on cooldown. Try again %time%", "TOO_LATE": "It's too late", - "TEXT_TOO_LONG": "The text is too long" + "TEXT_TOO_LONG": "The text is too long", + "TODAY": "Today" } \ No newline at end of file diff --git a/bot/locale/pl.json b/bot/locale/pl.json index 88435ea..ef89411 100644 --- a/bot/locale/pl.json +++ b/bot/locale/pl.json @@ -139,7 +139,7 @@ "NOTIFY_GIFT_COINS": "Otrzymałeś w prezent %coins%м", "STATISTIC_TITLE": "Z %start% po %end%", "STATISTIC_FOOTER": "Jeżeli dzień jeszcze nie skończył, dane mogą być nieprawidłowe", - "INVALID_DATE": "Data `%date%` nieprawidłowa. Potrzebuje format `DD.MM.RRRR`", + "INVALID_DATE": "Data `%date%` nieprawidłowa. Potrzebuje format `DD.MM.RRRR`, np. ", "TOO_EARLY_DATE": "Za ten period niema danych. Najwcześniejsze dane — ", "PLAYERS_ACTIVITY": "Aktywność użytkowników", "MAX_ONLINE": "Maksymalny online", @@ -152,5 +152,6 @@ "GIFT_RESPONSE": "Prezent w postaci %coins% monet został odebrany przez %nickname%", "COMMAND_COOLDOWN_RESPONSE": "To polecenie jest w trakcie odnawiania. Spróbuj ponownie %time%", "TOO_LATE": "Jest już za późno", - "TEXT_TOO_LONG": "Tekst jest zbyt długi" + "TEXT_TOO_LONG": "Tekst jest zbyt długi", + "TODAY": "Dzisiaj" } \ No newline at end of file diff --git a/bot/locale/ru.json b/bot/locale/ru.json index 3163705..6073f98 100644 --- a/bot/locale/ru.json +++ b/bot/locale/ru.json @@ -139,7 +139,7 @@ "NOTIFY_GIFT_COINS": "Вы получили подарок в размере %coins%м", "STATISTIC_TITLE": "С %start% по %end%", "STATISTIC_FOOTER": "Если день ещё не закончился, то данные могут быть не верные", - "INVALID_DATE": "Дата `%date%` невалидна. Ожидается формат `ДД.ММ.ГГГГ`", + "INVALID_DATE": "Дата `%date%` невалидна. Ожидается формат `ДД.ММ.ГГГГ`, например ", "TOO_EARLY_DATE": "За указанный период данные отсутствуют. Самая ранняя доступная дата — ", "PLAYERS_ACTIVITY": "Активность игроков", "MAX_ONLINE": "Максимальный онлайн", @@ -152,5 +152,6 @@ "GIFT_RESPONSE": "Подарок в виде %coins% монет забирает %nickname%", "COMMAND_COOLDOWN_RESPONSE": "Эта команда находится в режиме ожидания. Повторите попытку %time%", "TOO_LATE": "Слишком поздно", - "TEXT_TOO_LONG": "Текст слишком длинный" + "TEXT_TOO_LONG": "Текст слишком длинный", + "TODAY": "Сегодня" } \ No newline at end of file diff --git a/bot/locale/uk.json b/bot/locale/uk.json index f6adb43..365618b 100644 --- a/bot/locale/uk.json +++ b/bot/locale/uk.json @@ -139,7 +139,7 @@ "NOTIFY_GIFT_COINS": "Ви отримали подарунок у розмірі %coins%м", "STATISTIC_TITLE": "З %start% по %end%", "STATISTIC_FOOTER": "Якщо день не закінчився, то дані можуть бути хибними", - "INVALID_DATE": "Дата `%date%` невалідна. Очікується формат `ДД.ММ.РРРР`", + "INVALID_DATE": "Дата `%date%` невалідна. Очікується формат `ДД.ММ.РРРР`, наприклад ", "TOO_EARLY_DATE": "За вказаний період дані відсутні. Найбільш рання доступна дата — ", "PLAYERS_ACTIVITY": "Активність гравців", "MAX_ONLINE": "Максимальний онлайн", @@ -152,5 +152,6 @@ "GIFT_RESPONSE": "Подарунок у вигляді %coins% монет забирає %nickname%", "COMMAND_COOLDOWN_RESPONSE": "Ця команда перебуває у стані охолодження. Спробуйте ще раз %time%", "TOO_LATE": "Занадто пізно", - "TEXT_TOO_LONG": "Текст занадто довгий" + "TEXT_TOO_LONG": "Текст занадто довгий", + "TODAY": "Сьогодні" } \ No newline at end of file