mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Allow registering handlers using decorators
This commit is contained in:
parent
ede627de52
commit
90a4e4c411
@ -36,6 +36,7 @@ from queue import Queue
|
||||
from signal import signal, SIGINT, SIGTERM, SIGABRT
|
||||
from threading import Event, Thread
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import functions, types
|
||||
from pyrogram.api.core import Object
|
||||
from pyrogram.api.errors import (
|
||||
@ -188,6 +189,25 @@ class Client:
|
||||
self.dispatcher = Dispatcher(self, workers)
|
||||
self.update_handler = None
|
||||
|
||||
def on(self, handler, group: int):
|
||||
def decorator(f):
|
||||
self.add_handler(handler(f), group)
|
||||
return f
|
||||
|
||||
return decorator
|
||||
|
||||
def on_message(self, group: int = 0):
|
||||
return self.on(pyrogram.MessageHandler, group)
|
||||
|
||||
def on_edited_message(self, group: int = 0):
|
||||
return self.on(pyrogram.EditedMessageHandler, group)
|
||||
|
||||
def on_channel_post(self, group: int = 0):
|
||||
return self.on(pyrogram.ChannelPostHandler, group)
|
||||
|
||||
def on_edited_channel_post(self, group: int = 0):
|
||||
return self.on(pyrogram.EditedChannelPostHandler, group)
|
||||
|
||||
def add_handler(self, handler: Handler, group: int = 0):
|
||||
self.dispatcher.add_handler(handler, group)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user