From 723ccfaa211a0e7424489da3d4fd7a34f286b914 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 29 Apr 2021 23:12:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20I=20don't=20really=20know,=20I?= =?UTF-8?q?=20forgot=20to=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- royalnet_discordpy/pda.py | 83 +++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c39f262..b156ae6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "royalnet-discordpy" -version = "0.5.2" +version = "0.5.7" description = "A Discord.py-based frontend for the royalnet.engineer module." authors = ["Stefano Pigozzi "] license = "AGPL-3.0-or-later" diff --git a/royalnet_discordpy/pda.py b/royalnet_discordpy/pda.py index 17e65bb6..57731485 100644 --- a/royalnet_discordpy/pda.py +++ b/royalnet_discordpy/pda.py @@ -3,6 +3,7 @@ The PDA ("main" class) for the :mod:`royalnet_telethon` frontend. """ from __future__ import annotations + import royalnet.royaltyping as t import logging @@ -50,26 +51,43 @@ class DiscordpyPDAImplementation(engi.ConversationListImplementation): .. todo:: Document this. """ - self.client: d.Client = d.Client() + # noinspection PyMethodParameters + class CustomClient(d.Client): + async def on_ready(cli): + log.debug("CustomClient is ready!") + + async def on_error(self, event_method, *args, **kwargs): + log.error(f"An error occoured in CustomClient: {event_method!r} {args!r} {kwargs!r}") + + async def on_message(cli, message: d.Message): + log.debug("Triggered on_message, putting in dispenser...") + + await self.put( + key=self._determine_key(message=message), + projectile=DiscordMessageReceived(event=message) + ) + + async def on_message_edit(cli, message: d.Message): + log.debug("Triggered on_message_edit, putting in dispenser...") + + await self.put( + key=self._determine_key(message=message), + projectile=DiscordMessageEdited(event=message) + ) + + async def on_message_delete(cli, message: d.Message): + log.debug("Triggered on_message_delete, putting in dispenser...") + + await self.put( + key=self._determine_key(message=message), + projectile=DiscordMessageDeleted(event=message) + ) + + self.client: d.Client = CustomClient() """ .. todo:: Document this. """ - self._register_events() - - def _register_events(self): - """ - .. todo:: Document this. - """ - - self.log.info("Registering Discord.py events...") - self.log.debug("Registering on_message...") - self.client.on_message = self._on_message - self.log.debug("Registering on_message_edit...") - self.client.on_message_edit = self._on_message_edit - self.log.debug("Registering on_message_delete...") - self.client.on_message_delete = self._on_message_delete - def _determine_key(self, message: d.Message): """ .. todo:: Document this. @@ -90,39 +108,8 @@ class DiscordpyPDAImplementation(engi.ConversationListImplementation): else: raise TypeError("Invalid mode") - async def _on_message(self, message: d.Message): - """ - .. todo:: Document this. - """ - - await self.put( - key=self._determine_key(message=message), - projectile=DiscordMessageReceived(event=message) - ) - - async def _on_message_edit(self, message: d.Message): - """ - .. todo:: Document this. - """ - - await self.put( - key=self._determine_key(message=message), - projectile=DiscordMessageEdited(event=message) - ) - - async def _on_message_delete(self, message: d.Message): - """ - .. todo:: Document this. - """ - - await self.put( - key=self._determine_key(message=message), - projectile=DiscordMessageDeleted(event=message) - ) - async def run(self) -> t.NoReturn: - await self.client.login(token=self.bot_token) - await self.client.connect(reconnect=True) + await self.client.start(self.bot_token, bot=True, reconnect=True) __all__ = (