Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into ilyash0-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyash0 authored Jan 26, 2024
2 parents f8a9525 + 8646bdf commit 8208b0c
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bot/core/disnaleOverride.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion bot/handlers/cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions bot/handlers/cogs/fundraising.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions bot/handlers/cogs/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
embedAboutImage,
embedAbout,
guild_ids,
avatarImageBytearray, placeholderImageLink)
avatarImageBytearray, placeholderImageLink, default_language)
from bot.handlers.select import AboutSelect


Expand Down Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions bot/locale/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. <t:1601233740:d>",
"TOO_EARLY_DATE": "No data are available for the specified period. The earliest available date is <t:1601233740:d>",
"PLAYERS_ACTIVITY": "Players activity",
"MAX_ONLINE": "Max online",
Expand All @@ -150,6 +150,8 @@
"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",
"TODAY": "Today"
}
8 changes: 5 additions & 3 deletions bot/locale/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. <t:1601233740:d>",
"TOO_EARLY_DATE": "No data is available for the specified period. The earliest available date is <t:1601233740:d>",
"PLAYERS_ACTIVITY": "Players activity",
"MAX_ONLINE": "Max online",
Expand All @@ -150,6 +150,8 @@
"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",
"TODAY": "Today"
}
8 changes: 5 additions & 3 deletions bot/locale/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. <t:1601233740:d>",
"TOO_EARLY_DATE": "Za ten period niema danych. Najwcześniejsze dane — <t:1601233740:d>",
"PLAYERS_ACTIVITY": "Aktywność użytkowników",
"MAX_ONLINE": "Maksymalny online",
Expand All @@ -150,6 +150,8 @@
"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",
"TODAY": "Dzisiaj"
}
8 changes: 5 additions & 3 deletions bot/locale/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"NOTIFY_GIFT_COINS": "Вы получили подарок в размере %coins%м",
"STATISTIC_TITLE": "С %start% по %end%",
"STATISTIC_FOOTER": "Если день ещё не закончился, то данные могут быть не верные",
"INVALID_DATE": "Дата `%date%` невалидна. Ожидается формат `ДД.ММ.ГГГГ`",
"INVALID_DATE": "Дата `%date%` невалидна. Ожидается формат `ДД.ММ.ГГГГ`, например <t:1601233740:d>",
"TOO_EARLY_DATE": "За указанный период данные отсутствуют. Самая ранняя доступная дата — <t:1601233740:d>",
"PLAYERS_ACTIVITY": "Активность игроков",
"MAX_ONLINE": "Максимальный онлайн",
Expand All @@ -150,6 +150,8 @@
"ECONOMIC_DATA": "Экономические данные",
"MICROTRANSACTION_REVENUE": "Общая выручка от микротранзакций",
"GIFT_RESPONSE": "Подарок в виде %coins% монет забирает %nickname%",
"COMMAND_COOLDOWN_RESPONSE": "Эта команда находится в режиме ожидания. Повторите попытку через %time%",
"TOO_LATE": "Слишком поздно"
"COMMAND_COOLDOWN_RESPONSE": "Эта команда находится в режиме ожидания. Повторите попытку %time%",
"TOO_LATE": "Слишком поздно",
"TEXT_TOO_LONG": "Текст слишком длинный",
"TODAY": "Сегодня"
}
8 changes: 5 additions & 3 deletions bot/locale/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"NOTIFY_GIFT_COINS": "Ви отримали подарунок у розмірі %coins%м",
"STATISTIC_TITLE": "З %start% по %end%",
"STATISTIC_FOOTER": "Якщо день не закінчився, то дані можуть бути хибними",
"INVALID_DATE": "Дата `%date%` невалідна. Очікується формат `ДД.ММ.РРРР`",
"INVALID_DATE": "Дата `%date%` невалідна. Очікується формат `ДД.ММ.РРРР`, наприклад <t:1601233740:d>",
"TOO_EARLY_DATE": "За вказаний період дані відсутні. Найбільш рання доступна дата — <t:1601233740:d>",
"PLAYERS_ACTIVITY": "Активність гравців",
"MAX_ONLINE": "Максимальний онлайн",
Expand All @@ -150,6 +150,8 @@
"ECONOMIC_DATA": "Экономічні дані",
"MICROTRANSACTION_REVENUE": "Загальна виручка від мікротранзакцій",
"GIFT_RESPONSE": "Подарунок у вигляді %coins% монет забирає %nickname%",
"COMMAND_COOLDOWN_RESPONSE": "Ця команда перебуває у стані охолодження. Спробуйте ще раз через %time%",
"TOO_LATE": "Занадто пізно"
"COMMAND_COOLDOWN_RESPONSE": "Ця команда перебуває у стані охолодження. Спробуйте ще раз %time%",
"TOO_LATE": "Занадто пізно",
"TEXT_TOO_LONG": "Текст занадто довгий",
"TODAY": "Сьогодні"
}
1 change: 1 addition & 0 deletions bot/misc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8208b0c

Please # to comment.