2019-11-04 16:58:31 +01:00
|
|
|
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
|
2019-11-05 19:48:14 +01:00
|
|
|
async def process(self) -> typing.Union[bool, int]:
|
2019-11-04 16:58:31 +01:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-11-05 19:48:14 +01:00
|
|
|
async def _process(self) -> typing.Union[bool, int]:
|
2019-11-04 16:58:31 +01:00
|
|
|
try:
|
2019-11-05 19:48:14 +01:00
|
|
|
return await self.process() * 1e9
|
2019-11-04 16:58:31 +01:00
|
|
|
|
|
|
|
except FloodWait as error:
|
2019-11-05 19:48:14 +01:00
|
|
|
return int(error.MESSAGE.split("_")[-1]) * 1e9
|
2019-11-04 16:58:31 +01:00
|
|
|
|
|
|
|
except (ChannelInvalid, ChannelPrivate, Unauthorized):
|
|
|
|
return False
|