1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

💥 I don't really know, I forgot to commit

This commit is contained in:
Steffo 2021-04-29 23:12:43 +02:00
parent eefae69a9d
commit 723ccfaa21
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 36 additions and 49 deletions

View file

@ -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 <me@steffo.eu>"]
license = "AGPL-3.0-or-later"

View file

@ -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__ = (