diff --git a/README.md b/README.md index 7841c13..4ed9a5c 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,11 @@ Puffle Bot is a public Discord bot for interaction with online game "CPPS.APP". Available languages: -- English -- Russian -- Polski -- Ukrainian +- English, Great Britain; +- English, USA; +- Russian; +- Polski; +- Ukrainian. ## Features diff --git a/bot/core/puffleBot.py b/bot/core/puffleBot.py index 0e1313d..982bc7e 100644 --- a/bot/core/puffleBot.py +++ b/bot/core/puffleBot.py @@ -99,8 +99,15 @@ async def on_connect(self): async def on_slash_command_error(self, inter: AppCommandInter, exception: CommandError): try: - logger.error(f"User error: {exception.args[0]}") - await inter.send(f"{self.i18n.get(exception.args[0])[str(inter.avail_lang)]}", ephemeral=True) + if (exception.args[0] == + "Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions"): + logger.error(f"403 Forbidden: Missing Permissions") + await inter.send(f"{self.i18n.get('BOT_DOESNT_HAVE_PERMISSION')[str(inter.avail_lang)]}", + ephemeral=True) + else: + logger.error(f"User error: {exception.args[0]}") + await inter.send(f"{self.i18n.get(exception.args[0])[str(inter.avail_lang)]}", ephemeral=True) + except (KeyError, TypeError, AttributeError): logger.error(exception) traceback.print_exception(type(exception), exception, exception.__traceback__) diff --git a/bot/handlers/button.py b/bot/handlers/button.py index 4594e0a..506bd4b 100644 --- a/bot/handlers/button.py +++ b/bot/handlers/button.py @@ -62,13 +62,12 @@ def __init__(self, fundraising: Fundraising, message: disnake.Message, receiver: self.command = "fundraising" async def donate(self, inter: MessageInteraction, coins: int): - await inter.response.defer() p: Penguin = await get_my_penguin_from_user_id(inter.author.id) await transfer_coins(p, self.receiver, int(coins)) await notify_coins_receive(p, self.receiver, coins, None, self.command) await inter.send( inter.bot.i18n.get("COINS_TRANSFERRED")[str(inter.avail_lang)]. - replace("%coins%", str(coins)).replace("%receiver%", self.receiver.safe_name())) + replace("%coins%", str(coins)).replace("%receiver%", self.receiver.safe_name()), ephemeral=True) self.raised += int(coins) embed = self.message.embeds[0] @@ -89,17 +88,17 @@ async def donate(self, inter: MessageInteraction, coins: int): @disnake.ui.button(label="100", style=disnake.ButtonStyle.blurple, emoji="<:coin:788877461588279336>", custom_id="100") async def coins100_button(self, button: disnake.ui.Button, inter: MessageInteraction): - await self.donate(inter, int(button.label)) + await self.donate(inter, int(button.custom_id)) @disnake.ui.button(label="500", style=disnake.ButtonStyle.blurple, emoji="<:coin:788877461588279336>", custom_id="500") async def coins500_button(self, button: disnake.ui.Button, inter: MessageInteraction): - await self.donate(inter, int(button.label)) + await self.donate(inter, int(button.custom_id)) @disnake.ui.button(label="1000", style=disnake.ButtonStyle.blurple, emoji="<:coin:788877461588279336>", - custom_id="1000") + custom_id="1 000") async def coins1000_button(self, button: disnake.ui.Button, inter: MessageInteraction): - await self.donate(inter, int(button.label)) + await self.donate(inter, int(button.custom_id)) @disnake.ui.button(label="OTHER_AMOUNT", style=disnake.ButtonStyle.gray, custom_id="other") @@ -329,17 +328,15 @@ def __init__(self, original_inter: AppCommandInter, message: Message, coins: int @disnake.ui.button(label="GIFT", style=disnake.ButtonStyle.blurple, custom_id="gift", emoji="🎁") async def gift(self, button, inter: MessageInteraction): - button.disabled = True - await self.message.edit(view=self) await inter.response.defer() p = await get_my_penguin_from_user_id(inter.user.id) if p.moderator or p.id == self.giver_penguin.id: await inter.send(inter.bot.i18n.get("NOT_FOR_YOU")[str(inter.locale)], ephemeral=True) - button.disabled = False - await self.message.edit(view=self) return await transfer_coins(self.giver_penguin, p, self.coins) await inter.send(inter.bot.i18n.get("GIFT_RESPONSE")[str(inter.locale)]. replace("%coins%", str(self.coins)).replace("%nickname%", p.safe_name())) await notify_gift_coins(inter.user, p, self.coins) + button.disabled = True + await self.message.edit(view=self) diff --git a/bot/handlers/cogs/commands.py b/bot/handlers/cogs/commands.py index 6ddef47..c72fd4c 100644 --- a/bot/handlers/cogs/commands.py +++ b/bot/handlers/cogs/commands.py @@ -61,7 +61,7 @@ async def card(self, inter: AppCommandInter, p = await inter.user.penguin if p.get_custom_attribute("mood") and not p.get_custom_attribute("mood").isspace(): - mood = f'_\{p.get_custom_attribute("mood")}_' + mood = f'_' + p.get_custom_attribute("mood").replace("#", "\#").replace("*", "\*").replace("_", "\_") + '_' else: mood = None @@ -253,8 +253,8 @@ async def gift(self, inter: AppCommandInter, channel: disnake.TextChannel, coins if p.coins < coins: raise CommandError("NOT_ENOUGH_COINS") - await inter.send(self.bot.i18n.get("SUCCESS")[lang], ephemeral=True) message_object = await channel.send(f"{message} {self.bot.i18n.get('WAIT_A_FEW_SECONDS')[lang]}") + await inter.send(self.bot.i18n.get("SUCCESS")[lang], ephemeral=True) await sleep(randrange(3, 15)) await message_object.edit(message, view=Gift(inter, message_object, coins, p)) diff --git a/bot/handlers/cogs/fundraising.py b/bot/handlers/cogs/fundraising.py index 4ac5dfd..eb1d18c 100644 --- a/bot/handlers/cogs/fundraising.py +++ b/bot/handlers/cogs/fundraising.py @@ -86,8 +86,6 @@ async def fundraising_close(self, inter: AppCommandInter): await message.edit(self.bot.i18n.get("CLOSED")[lang], view=None) except disnake.NotFound: pass - except disnake.errors.Forbidden: - return await inter.send(self.bot.i18n.get("BOT_DOESNT_HAVE_PERMISSION")[lang], ephemeral=True) await inter.send(self.bot.i18n.get("SUCCESS")[lang], ephemeral=True) diff --git a/bot/handlers/notification.py b/bot/handlers/notification.py index 659430b..73a206a 100644 --- a/bot/handlers/notification.py +++ b/bot/handlers/notification.py @@ -34,8 +34,11 @@ async def check_membership(): async def notify_coins_receive(sender_penguin: Penguin, receiver_penguin: Penguin, coins: int, message: str = None, command: str = None): - user_id, = await PenguinIntegrations.select("discord_id").where( - PenguinIntegrations.penguin_id == receiver_penguin.id).gino.first() + try: + user_id, = await PenguinIntegrations.select("discord_id").where( + PenguinIntegrations.penguin_id == receiver_penguin.id).gino.first() + except TypeError: + return user: disnake.User = await bot.get_or_fetch_user(int(user_id)) sender_user_id, = await User.select("id").where(User.penguin_id == sender_penguin.id).gino.first() lang = (await user.db).language diff --git a/requirements.txt b/requirements.txt index 53cc282..25f972a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ bs4~=0.0.1 beautifulsoup4~=4.12.2 hachiko~=0.4.0 awebus==1.0a6 -typeguard~=4.1.5 \ No newline at end of file +typeguard~=4.1.5 +defusedxml~=0.7.1 \ No newline at end of file