Allow on_raw_update to be used as a static decorator

This commit is contained in:
Dan 2018-10-13 10:45:48 +02:00
parent 345ac6e16a
commit 1fdc757f2a

View File

@ -21,7 +21,7 @@ from ...ext import BaseClient
class OnRawUpdate(BaseClient):
def on_raw_update(self, group: int = 0):
def on_raw_update(self=None, group: int = 0):
"""Use this decorator to automatically register a function for handling
raw updates. This does the same thing as :meth:`add_handler` using the
:class:`RawUpdateHandler`.
@ -32,7 +32,14 @@ class OnRawUpdate(BaseClient):
"""
def decorator(func):
self.add_handler(pyrogram.RawUpdateHandler(func), group)
return func
handler = pyrogram.RawUpdateHandler(func)
if isinstance(self, int):
return handler, group if self is None else group
if self is not None:
self.add_handler(handler, group)
return handler, group
return decorator