outside-fetcher/tasks/mtproto_task_abstraction.py
2019-11-05 19:48:14 +01:00

27 lines
710 B
Python

import abc
import typing
from async_worker import AsyncTask
from pyrogram.errors.exceptions import FloodWait, ChannelInvalid, ChannelPrivate, Unauthorized
class MtProtoTask(AsyncTask, abc.ABC):
@abc.abstractmethod
def setup(self, *args, **kwargs):
raise NotImplementedError
@abc.abstractmethod
async def process(self) -> typing.Union[bool, int]:
raise NotImplementedError
async def _process(self) -> typing.Union[bool, int]:
try:
return await self.process() * 1e9
except FloodWait as error:
return int(error.MESSAGE.split("_")[-1]) * 1e9
except (ChannelInvalid, ChannelPrivate, Unauthorized):
return False