-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatch.py
More file actions
36 lines (26 loc) · 1.12 KB
/
Copy pathpatch.py
File metadata and controls
36 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pyrogram import Client
from pyrogram_patch.fsm import BaseStorage
from .patch_data_pool import PatchDataPool
from .dispatcher import PatchedDispatcher
from .router import Router
class PatchManager:
def __init__(self, client: Client):
self.client = client
self.dispatcher = client.dispatcher
def include_middleware(self, middleware: "PatchMiddleware") -> None:
PatchDataPool.pyrogram_patch_middlewares.append(middleware)
def include_outer_middleware(self, middleware: "PatchMiddleware") -> None:
PatchDataPool.pyrogram_patch_outer_middlewares.append(middleware)
def set_storage(self, storage: BaseStorage) -> None:
PatchDataPool.pyrogram_patch_fsm_storage = storage
def include_router(self, router: Router) -> None:
router.set_client(self.client)
def patch(app: Client) -> PatchManager:
"""app - instance of your pyrogram client
returns
MiddlewarePatchManager instance with methods:
include_middleware and include_outer_middleware
"""
app.__delattr__("dispatcher")
app.dispatcher = PatchedDispatcher(app)
return PatchManager(app)