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

v0.4.1 #20

Merged
merged 15 commits into from
Dec 28, 2023
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions bot/core/puffleBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
17 changes: 7 additions & 10 deletions bot/handlers/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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")
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions bot/handlers/cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions bot/handlers/cogs/fundraising.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 5 additions & 2 deletions bot/handlers/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bs4~=0.0.1
beautifulsoup4~=4.12.2
hachiko~=0.4.0
awebus==1.0a6
typeguard~=4.1.5
typeguard~=4.1.5
defusedxml~=0.7.1