diff --git a/pyproject.toml b/pyproject.toml index 6c813abc..05f58011 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "royalnet-telethon" -version = "0.1.6" +version = "0.2.0" description = "A Telethon-based frontend for the royalnet.engineer module." authors = ["Stefano Pigozzi "] license = "AGPL-3.0-or-later" diff --git a/royalnet_telethon/bullet/contents/__init__.py b/royalnet_telethon/bullet/contents/__init__.py index cabd4175..6dd23016 100644 --- a/royalnet_telethon/bullet/contents/__init__.py +++ b/royalnet_telethon/bullet/contents/__init__.py @@ -13,75 +13,75 @@ import datetime class TelegramMessage(co.Message): def __init__(self, msg: tlc.Message): super().__init__() - self.msg: tlc.Message = msg + self._msg: tlc.Message = msg def __hash__(self) -> int: - return self.msg.id + return self._msg.id @ap.async_property async def text(self) -> t.Optional[str]: - return self.msg.text + return self._msg.text @ap.async_property async def timestamp(self) -> t.Optional[datetime.datetime]: - return max(self.msg.date, self.msg.edit_date) + return max(self._msg.date, self._msg.edit_date) @ap.async_property async def channel(self) -> t.Optional[TelegramChannel]: - channel: t.Union[tlt.Chat, tlt.User, tlt.Channel] = await self.msg.get_chat() - return TelegramChannel(channel=channel, client=self.msg.client) + channel: t.Union[tlt.Chat, tlt.User, tlt.Channel] = await self._msg.get_chat() + return TelegramChannel(channel=channel, client=self._msg.client) @ap.async_property async def sender(self) -> t.Optional[TelegramUser]: - sender: tlt.User = await self.msg.get_sender() - return TelegramUser(user=sender, client=self.msg.client) + sender: tlt.User = await self._msg.get_sender() + return TelegramUser(user=sender, client=self._msg.client) async def reply(self, *, text: str = None, files: t.List[t.BinaryIO] = None) -> t.Optional[TelegramMessage]: - sent = await self.msg.reply(message=text, file=files) + sent = await self._msg.reply(message=text, file=files) return TelegramMessage(msg=sent) class TelegramChannel(co.Channel): def __init__(self, channel: t.Union[tlt.Chat, tlt.User, tlt.Channel], client: tt.TelegramClient): super().__init__() - self.channel: t.Union[tlt.Chat, tlt.User, tlt.Channel] = channel - self.client: tt.TelegramClient = client + self._channel: t.Union[tlt.Chat, tlt.User, tlt.Channel] = channel + self._client: tt.TelegramClient = client def __hash__(self): - return self.channel.id + return self._channel.id @ap.async_property async def name(self) -> t.Optional[str]: - return self.channel.title + return self._channel.title async def send_message(self, *, text: str = None, files: t.List[t.BinaryIO] = None) -> t.Optional[TelegramMessage]: - sent = await self.client.send_message(self.channel, message=text, file=files) + sent = await self._client.send_message(self._channel, message=text, file=files) return TelegramMessage(msg=sent) class TelegramUser(co.User): def __init__(self, user: tlt.User, client: tt.TelegramClient): super().__init__() - self.user: tlt.User = user - self.client: tt.TelegramClient = client + self._user: tlt.User = user + self._client: tt.TelegramClient = client def __hash__(self): - return self.user.id + return self._user.id @ap.async_property async def name(self) -> t.Optional[str]: - if self.user.username: - return f"{self.user.username}" - elif self.user.last_name: - return f"{self.user.first_name} {self.user.last_name}" - return f"{self.user.first_name}" + if self._user.username: + return f"{self._user.username}" + elif self._user.last_name: + return f"{self._user.first_name} {self._user.last_name}" + return f"{self._user.first_name}" async def slide(self) -> TelegramChannel: - return TelegramChannel(channel=self.user, client=self.client) + return TelegramChannel(channel=self._user, client=self._client) __all__ = ( diff --git a/royalnet_telethon/bullet/projectiles/message.py b/royalnet_telethon/bullet/projectiles/message.py index 084cf826..ca4bb370 100644 --- a/royalnet_telethon/bullet/projectiles/message.py +++ b/royalnet_telethon/bullet/projectiles/message.py @@ -7,40 +7,40 @@ from ..contents.__init__ import TelegramMessage class TelegramMessageReceived(p.MessageReceived): def __init__(self, event: tlc.Message): super().__init__() - self.event: tlc.Message = event + self._event: tlc.Message = event def __hash__(self) -> int: - return self.event.id + return self._event.id @ap.async_cached_property async def message(self) -> TelegramMessage: - return TelegramMessage(msg=self.event) + return TelegramMessage(msg=self._event) class TelegramMessageEdited(p.MessageEdited): def __init__(self, event: tlc.Message): super().__init__() - self.event: tlc.Message = event + self._event: tlc.Message = event def __hash__(self) -> int: - return self.event.id + return self._event.id @ap.async_cached_property async def message(self) -> TelegramMessage: - return TelegramMessage(msg=self.event) + return TelegramMessage(msg=self._event) class TelegramMessageDeleted(p.MessageDeleted): def __init__(self, event: tlc.Message): super().__init__() - self.event: tlc.Message = event + self._event: tlc.Message = event def __hash__(self) -> int: - return self.event.id + return self._event.id @ap.async_cached_property async def message(self) -> TelegramMessage: - return TelegramMessage(msg=self.event) + return TelegramMessage(msg=self._event) __all__ = ( diff --git a/royalnet_telethon/pda.py b/royalnet_telethon/pda.py index 4d862b61..56786bae 100644 --- a/royalnet_telethon/pda.py +++ b/royalnet_telethon/pda.py @@ -54,13 +54,13 @@ class TelethonPDA: self.conversations: t.List[engi.Conversation] = [] """ - A :class:`list` of conversations to run before a new event is :meth:`.put` in a + A :class:`list` of conversations to run before a new _event is :meth:`.put` in a :class:`~royalnet.engineer.dispenser.Dispenser`. """ self.client: tt.TelegramClient = tt.TelegramClient("bot", api_id=tg_api_id, api_hash=tg_api_hash) """ - The :mod:`telethon` Telegram client that this PDA will use to interface with Telegram. + The :mod:`telethon` Telegram _client that this PDA will use to interface with Telegram. """ self._register_events() @@ -76,12 +76,12 @@ class TelethonPDA: self.client.add_event_handler(callback=self._message_new, event=tt.events.NewMessage()) self.client.add_event_handler(callback=self._message_edit, event=tt.events.MessageEdited()) self.client.add_event_handler(callback=self._message_delete, event=tt.events.MessageDeleted()) - # self.client.add_event_handler(callback=self._message_read, event=tt.events.MessageRead()) - # self.client.add_event_handler(callback=self._chat_action, event=tt.events.ChatAction()) - # self.client.add_event_handler(callback=self._user_update, event=tt.events.UserUpdate()) - # self.client.add_event_handler(callback=self._callback_query, event=tt.events.CallbackQuery()) - # self.client.add_event_handler(callback=self._inline_query, event=tt.events.InlineQuery()) - # self.client.add_event_handler(callback=self._album, event=tt.events.Album()) + # self._client.add_event_handler(callback=self._message_read, _event=tt.events.MessageRead()) + # self._client.add_event_handler(callback=self._chat_action, _event=tt.events.ChatAction()) + # self._client.add_event_handler(callback=self._user_update, _event=tt.events.UserUpdate()) + # self._client.add_event_handler(callback=self._callback_query, _event=tt.events.CallbackQuery()) + # self._client.add_event_handler(callback=self._inline_query, _event=tt.events.InlineQuery()) + # self._client.add_event_handler(callback=self._album, _event=tt.events.Album()) def _determine_key(self, event: tlc.message.Message): if self.mode == TelethonPDAMode.GLOBAL: @@ -186,13 +186,13 @@ class TelethonPDA: log.debug(f"Creating run task for: {conversation!r}") loop.create_task(dispenser.run(conversation, _pda=self), name=f"{repr(conversation)}") - log.debug("Running a event loop cycle...") + log.debug("Running a _event loop cycle...") await asyncio.sleep(0) log.debug(f"Putting projectile {proj!r} in dispenser {dispenser!r}...") await dispenser.put(proj) - log.debug("Awaiting another event loop cycle...") + log.debug("Awaiting another _event loop cycle...") await asyncio.sleep(0)