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,8 +717,7 @@ class Client(Methods, Scaffold):
|
|||||||
for name in vars(module).keys():
|
for name in vars(module).keys():
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
handler, group = getattr(module, name).handler
|
for handler, group in getattr(module, name).handlers:
|
||||||
|
|
||||||
if isinstance(handler, Handler) and isinstance(group, int):
|
if isinstance(handler, Handler) and isinstance(group, int):
|
||||||
self.add_handler(handler, group)
|
self.add_handler(handler, group)
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnCallbackQuery(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.CallbackQueryHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.CallbackQueryHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.CallbackQueryHandler(func, self),
|
pyrogram.handlers.CallbackQueryHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnChosenInlineResult(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.ChosenInlineResultHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.ChosenInlineResultHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.ChosenInlineResultHandler(func, self),
|
pyrogram.handlers.ChosenInlineResultHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnDeletedMessages(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.DeletedMessagesHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.DeletedMessagesHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.DeletedMessagesHandler(func, self),
|
pyrogram.handlers.DeletedMessagesHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnInlineQuery(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.InlineQueryHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.InlineQueryHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.InlineQueryHandler(func, self),
|
pyrogram.handlers.InlineQueryHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnMessage(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.MessageHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.MessageHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.MessageHandler(func, self),
|
pyrogram.handlers.MessageHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -47,10 +47,15 @@ class OnPoll(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.PollHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.PollHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.PollHandler(func, self),
|
pyrogram.handlers.PollHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -41,10 +41,15 @@ class OnRawUpdate(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.RawUpdateHandler(func), group)
|
self.add_handler(pyrogram.handlers.RawUpdateHandler(func), group)
|
||||||
else:
|
else:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.RawUpdateHandler(func),
|
pyrogram.handlers.RawUpdateHandler(func),
|
||||||
group if self is None else group
|
group if self is None else group
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
@ -45,10 +45,15 @@ class OnUserStatus(Scaffold):
|
|||||||
if isinstance(self, pyrogram.Client):
|
if isinstance(self, pyrogram.Client):
|
||||||
self.add_handler(pyrogram.handlers.UserStatusHandler(func, filters), group)
|
self.add_handler(pyrogram.handlers.UserStatusHandler(func, filters), group)
|
||||||
elif isinstance(self, Filter) or self is None:
|
elif isinstance(self, Filter) or self is None:
|
||||||
func.handler = (
|
if not hasattr(func, "handlers"):
|
||||||
|
func.handlers = []
|
||||||
|
|
||||||
|
func.handlers.append(
|
||||||
|
(
|
||||||
pyrogram.handlers.UserStatusHandler(func, self),
|
pyrogram.handlers.UserStatusHandler(func, self),
|
||||||
group if filters is None else filters
|
group if filters is None else filters
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user