diff --git a/stdborg.py b/stdborg.py index 81143bb..6e82efe 100644 --- a/stdborg.py +++ b/stdborg.py @@ -8,6 +8,6 @@ from uniborg import Uniborg logging.basicConfig(level=logging.INFO) -borg = Uniborg("stdborg", plugin_path="stdplugins") +borg = Uniborg("stdborg", plugin_path="stdplugins", connection_retries=None) -borg.run() +borg.run_until_disconnected() diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index 0c8d3df..fa1a5cc 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -144,7 +144,7 @@ async def reparse(event): return await borg(EditMessageRequest( - peer=await event.input_chat, + peer=await event.get_input_chat(), id=event.message.id, message=message, no_webpage=not bool(event.message.media), diff --git a/stdplugins/ninja.py b/stdplugins/ninja.py index edf22aa..d9ebaae 100644 --- a/stdplugins/ninja.py +++ b/stdplugins/ninja.py @@ -11,9 +11,10 @@ from uniborg import util async def get_target_message(event): - if event.is_reply and (await event.reply_message).from_id == borg.uid: - return await event.reply_message - async for message in borg.iter_messages(await event.input_chat, limit=20): + if event.is_reply and (await event.get_reply_message()).from_id == borg.uid: + return await event.get_reply_message() + async for message in borg.iter_messages( + await event.get_input_chat(), limit=20): if message.out: return message @@ -22,7 +23,7 @@ async def await_read(chat, message): chat = telethon.utils.get_peer_id(chat) async def read_filter(read_event): - return (telethon.utils.get_peer_id(await read_event.input_chat) == chat + return (read_event.chat_id == chat and read_event.is_read(message)) fut = borg.await_event(events.MessageRead(inbox=False), read_filter) @@ -44,7 +45,7 @@ async def delete(event): return target = await get_target_message(event) if target: - chat = await event.input_chat + chat = await event.get_input_chat() await await_read(chat, target) await asyncio.sleep(.5) if command == 'edit': diff --git a/stdplugins/snip.py b/stdplugins/snip.py index 5ec01a9..cf3f803 100644 --- a/stdplugins/snip.py +++ b/stdplugins/snip.py @@ -28,7 +28,7 @@ async def on_snip(event): else: media = None - await borg.send_message(await event.input_chat, snip['text'], + await borg.send_message(await event.get_input_chat(), snip['text'], file=media, reply_to=event.message.reply_to_msg_id) @@ -38,7 +38,7 @@ async def on_snip(event): @borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True)) async def on_snip_save(event): name = event.pattern_match.group(1) - msg = await event.reply_message + msg = await event.get_reply_message() if msg: snips.pop(name, None) snip = {'type': TYPE_TEXT, 'text': msg.message or ''} diff --git a/uniborg/uniborg.py b/uniborg/uniborg.py index 0eabbfc..97465f1 100644 --- a/uniborg/uniborg.py +++ b/uniborg/uniborg.py @@ -52,21 +52,6 @@ class Uniborg(TelegramClient): self.me = await self.get_me() self.uid = telethon.utils.get_peer_id(self.me) - async def _reconnect_nofail(self): - while True: - try: - await self.connect() - return - except ConnectionError: - pass - - def run(self): - while True: - try: - self.run_until_disconnected() - except ConnectionError: - self.loop.run_until_complete(self._reconnect_nofail()) - def load_plugin(self, shortname): self.load_plugin_from_file(f"{self._plugin_path}/{shortname}.py")