Allow decorators in plugins to be stacked (#642)
This allows registering the same callback function more than once by using different handlers.
This commit is contained in:
parent
c72bbcf9e1
commit
f0b1cc41f3
@ -717,13 +717,12 @@ class Client(Methods, Scaffold):
|
||||
for name in vars(module).keys():
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
handler, group = getattr(module, name).handler
|
||||
for handler, group in getattr(module, name).handlers:
|
||||
if isinstance(handler, Handler) and isinstance(group, int):
|
||||
self.add_handler(handler, group)
|
||||
|
||||
if isinstance(handler, Handler) and isinstance(group, int):
|
||||
self.add_handler(handler, group)
|
||||
|
||||
log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
|
||||
self.session_name, type(handler).__name__, name, group, module_path))
|
||||
log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
|
||||
self.session_name, type(handler).__name__, name, group, module_path))
|
||||
|
||||
count += 1
|
||||
except Exception:
|
||||
|
@ -47,9 +47,14 @@ class OnCallbackQuery(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.CallbackQueryHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.CallbackQueryHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.CallbackQueryHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -47,9 +47,14 @@ class OnChosenInlineResult(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.ChosenInlineResultHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.ChosenInlineResultHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.ChosenInlineResultHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -47,9 +47,14 @@ class OnDeletedMessages(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.DeletedMessagesHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.DeletedMessagesHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.DeletedMessagesHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -47,9 +47,14 @@ class OnInlineQuery(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.InlineQueryHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.InlineQueryHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.InlineQueryHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -47,9 +47,14 @@ class OnMessage(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.MessageHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.MessageHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.MessageHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -47,9 +47,14 @@ class OnPoll(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.PollHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.PollHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.PollHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -41,9 +41,14 @@ class OnRawUpdate(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.RawUpdateHandler(func), group)
|
||||
else:
|
||||
func.handler = (
|
||||
pyrogram.handlers.RawUpdateHandler(func),
|
||||
group if self is None else group
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.RawUpdateHandler(func),
|
||||
group if self is None else group
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
@ -45,9 +45,14 @@ class OnUserStatus(Scaffold):
|
||||
if isinstance(self, pyrogram.Client):
|
||||
self.add_handler(pyrogram.handlers.UserStatusHandler(func, filters), group)
|
||||
elif isinstance(self, Filter) or self is None:
|
||||
func.handler = (
|
||||
pyrogram.handlers.UserStatusHandler(func, self),
|
||||
group if filters is None else filters
|
||||
if not hasattr(func, "handlers"):
|
||||
func.handlers = []
|
||||
|
||||
func.handlers.append(
|
||||
(
|
||||
pyrogram.handlers.UserStatusHandler(func, self),
|
||||
group if filters is None else filters
|
||||
)
|
||||
)
|
||||
|
||||
return func
|
||||
|
Loading…
Reference in New Issue
Block a user