Quit failing

wank.party seems to have a garbage tier connection to Telegram, so work
around this by looping reconnects indefinitely, without crashing to
preserve runtime state.
ninja_fix
Dan Elkouby 2018-06-17 17:48:17 +00:00
parent 88fd76653a
commit b34b1c516f
1 changed files with 12 additions and 1 deletions

View File

@ -52,8 +52,19 @@ 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:
self.connect()
except ConnectionError:
pass
def run(self):
self.loop.run_forever()
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")