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

Commit

Permalink
Merge pull request #22 from ilyash0/dev
Browse files Browse the repository at this point in the history
v0.4.3
  • Loading branch information
ilyash0 authored Jan 9, 2024
2 parents 5b897e3 + 21d387c commit ace0787
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<div style="background-color: orange; color: black; border-radius: 0 0 10px 10px; padding: 5px" align="center">
As CPPS.APP will be shut down on 25 January 2024, the bot will soon be disabled
</div>

<h1 align="center">
Puffle Bot
</h1>
Expand Down
5 changes: 3 additions & 2 deletions bot/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bot.events import event
from bot.events.module import hot_reload_module
import bot.handlers
from bot.misc.constants import owner_ids


class Server:
Expand Down Expand Up @@ -58,7 +59,7 @@ async def start(self):
command_sync_flags.sync_commands = True

self.bot = PuffleBot(defer=self.config.defer, intents=intents, command_sync_flags=command_sync_flags,
owner_id=527140180696629248) # test_guilds=[755445822920982548],
owner_ids=owner_ids) # test_guilds=[guild_ids]

await hot_reload_module(bot.handlers)
await event.emit("boot", self)
Expand All @@ -81,5 +82,5 @@ async def connect_to_houdini(self):
except ConnectionRefusedError:
logger.error("The remote computer refused the network connection")
return
logger.info(f"Server ('{self.config.houdini_address}', {self.config.houdini_port}) connected")
logger.info(f"Connected to server ('{self.config.houdini_address}', {self.config.houdini_port})")
self.client_object = self.client_class(self, reader, writer)
4 changes: 2 additions & 2 deletions bot/handlers/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ async def coins100_button(self, button: disnake.ui.Button, inter: MessageInterac
async def coins500_button(self, button: disnake.ui.Button, inter: MessageInteraction):
await self.donate(inter, int(button.custom_id))

@disnake.ui.button(label="1000", style=disnake.ButtonStyle.blurple, emoji="<:coin:788877461588279336>",
custom_id="1 000")
@disnake.ui.button(label="1 000", style=disnake.ButtonStyle.blurple, emoji="<:coin:788877461588279336>",
custom_id="1000")
async def coins1000_button(self, button: disnake.ui.Button, inter: MessageInteraction):
await self.donate(inter, int(button.custom_id))

Expand Down
13 changes: 7 additions & 6 deletions bot/handlers/cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ async def card(self, inter: AppCommandInter,
if user:
p = await user.penguin
if p is None:
await inter.send(self.bot.i18n.get("USER_PENGUIN_NOT_FOUND")[lang], ephemeral=True)
return
raise CommandError("USER_PENGUIN_NOT_FOUND")
else:
p = await inter.user.penguin

Expand Down Expand Up @@ -100,9 +99,11 @@ async def pay(self, inter: AppCommandInter,
"""
await inter.response.defer()
p: Penguin = await inter.user.penguin
receiver_id, = await Penguin.select('id').where(Penguin.username == nickname.lower()).gino.first()
if receiver_id is None:
return await inter.send(self.bot.i18n.get("PENGUIN_NOT_FOUND")[str(inter.avail_lang)], ephemeral=True)
try:
receiver_id, = await Penguin.select('id').where(Penguin.username == nickname.lower()).gino.first()
except TypeError:
raise CommandError("PENGUIN_NOT_FOUND")

r: Penguin = await Penguin.get(int(receiver_id))

await transfer_coins(p, r, coins)
Expand Down Expand Up @@ -246,7 +247,7 @@ async def gift(self, inter: AppCommandInter, channel: disnake.TextChannel, coins
if message is None:
message = self.bot.i18n.get("GIFT_DEFAULT_RESPONSE")[lang]
elif not is_message_valid(message):
return await inter.send(self.bot.i18n.get("KEEP_RULES")[lang], ephemeral=True)
raise CommandError("KEEP_RULES")

if coins <= 0:
raise CommandError("INCORRECT_COINS_AMOUNT")
Expand Down
1 change: 1 addition & 0 deletions bot/misc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"}

# Arrays
owner_ids = [527140180696629248]
guild_ids = [cppsapp_server_id, test_server_id]
non_deferred_commands = ["settings"]
commands_without_penguin_requirement = ["ilyash", "online", "login", "top", "settings"]
Expand Down
16 changes: 11 additions & 5 deletions bot/misc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


@event.on("boot")
async def setup(server):
global client
client = server.client_object
async def setup(_server):
global server
server = _server


async def get_my_penguin_from_user_id(user_id: int) -> Penguin:
Expand Down Expand Up @@ -76,6 +76,11 @@ async def get_penguin_from_penguin_id(penguin_id: int) -> Penguin:
return p


async def check_connection_to_houdini():
if server.client_object.__writer.is_closing():
await server.connect_to_houdini()


async def transfer_coins(sender: Penguin, receiver: Penguin, coins: int):
"""
Transfer coins from one penguin to another and return a status dictionary.
Expand Down Expand Up @@ -118,6 +123,7 @@ async def transfer_coins(sender: Penguin, receiver: Penguin, coins: int):
text=f"Получил от {sender.username} {int(coins)} монет. Через Discord бота", room_id=0,
server_id=8000)

await client.send_xml({'body': {'action': 'pb-cdu', 'r': '0'}, 'penguin': {'p': str(sender.id)}})
await client.send_xml({'body': {'action': 'pb-cdu', 'r': '0'}, 'penguin': {'p': str(receiver.id)}})
await check_connection_to_houdini()
await server.client_object.send_xml({'body': {'action': 'pb-cdu', 'r': '0'}, 'penguin': {'p': str(sender.id)}})
await server.client_object.send_xml({'body': {'action': 'pb-cdu', 'r': '0'}, 'penguin': {'p': str(receiver.id)}})
return

0 comments on commit ace0787

Please sign in to comment.