abstract mtproto error handling
This commit is contained in:
parent
a76a369d91
commit
f34504deb4
@ -1,5 +1,7 @@
|
|||||||
from .channel_history import ChannelHistoryReadTask
|
from .channel_history import ChannelHistoryReadTask
|
||||||
|
from .mtproto_task_abstraction import MtProtoTask
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"ChannelHistoryReadTask"
|
"ChannelHistoryReadTask",
|
||||||
|
"MtProtoTask"
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import pyrogram
|
import pyrogram
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import json
|
import json
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from .mtproto_task_abstraction import MtProtoTask
|
||||||
|
|
||||||
from async_worker.async_worker import AsyncTask
|
|
||||||
from pyrogram.api.types import ChannelMessagesFilterEmpty
|
from pyrogram.api.types import ChannelMessagesFilterEmpty
|
||||||
from pyrogram.api.types.updates import ChannelDifference, ChannelDifferenceTooLong, ChannelDifferenceEmpty
|
from pyrogram.api.types.updates import ChannelDifference, ChannelDifferenceTooLong, ChannelDifferenceEmpty
|
||||||
from pyrogram.api.functions.updates.get_channel_difference import GetChannelDifference
|
from pyrogram.api.functions.updates.get_channel_difference import GetChannelDifference
|
||||||
@ -58,7 +60,7 @@ class JsonSerializer:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class ChannelHistoryReadTask(AsyncTask):
|
class ChannelHistoryReadTask(MtProtoTask):
|
||||||
channel: pyrogram.Chat
|
channel: pyrogram.Chat
|
||||||
client: pyrogram.Client
|
client: pyrogram.Client
|
||||||
pts: int
|
pts: int
|
||||||
@ -72,7 +74,7 @@ class ChannelHistoryReadTask(AsyncTask):
|
|||||||
self.webhook = webhook
|
self.webhook = webhook
|
||||||
self.http = aiohttp.ClientSession()
|
self.http = aiohttp.ClientSession()
|
||||||
|
|
||||||
async def process(self):
|
async def mt_process(self) -> typing.Union[bool, int]:
|
||||||
response = await self.client.send(
|
response = await self.client.send(
|
||||||
GetChannelDifference(
|
GetChannelDifference(
|
||||||
channel=self.channel,
|
channel=self.channel,
|
||||||
|
27
tasks/mtproto_task_abstraction.py
Normal file
27
tasks/mtproto_task_abstraction.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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 mt_process(self) -> typing.Union[bool, int]:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
async def process(self) -> int:
|
||||||
|
try:
|
||||||
|
|
||||||
|
return await self.mt_process()
|
||||||
|
|
||||||
|
except FloodWait as error:
|
||||||
|
return int(error.MESSAGE.split("_")[-1])
|
||||||
|
|
||||||
|
except (ChannelInvalid, ChannelPrivate, Unauthorized):
|
||||||
|
return False
|
Loading…
Reference in New Issue
Block a user