Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,16 @@ def load_plugins(self):
module = import_module(module_path)

for name in vars(module).keys():
# noinspection PyBroadException
try:
for handler, group in getattr(module, name).handlers:
target_attr = getattr(module, name)
if hasattr(target_attr, "handlers"):
for handler, group in target_attr.handlers:
if isinstance(handler, Handler) and isinstance(group, int):
self.add_handler(handler, group)

log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
self.name, type(handler).__name__, name, group, module_path))

count += 1
except Exception:
pass
else:
for path, handlers in include:
module_path = root + "." + path
Expand All @@ -960,20 +958,19 @@ def load_plugins(self):
warn_non_existent_functions = False

for name in handlers:
# noinspection PyBroadException
try:
for handler, group in getattr(module, name).handlers:
target_attr = getattr(module, name)
if hasattr(target_attr, "handlers"):
for handler, group in target_attr.handlers:
if isinstance(handler, Handler) and isinstance(group, int):
self.add_handler(handler, group)

log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
self.name, type(handler).__name__, name, group, module_path))

count += 1
except Exception:
if warn_non_existent_functions:
log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
self.name, name, module_path))
elif warn_non_existent_functions:
log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
self.name, name, module_path))

if exclude:
for path, handlers in exclude:
Expand All @@ -995,20 +992,19 @@ def load_plugins(self):
warn_non_existent_functions = False

for name in handlers:
# noinspection PyBroadException
try:
for handler, group in getattr(module, name).handlers:
target_attr = getattr(module, name)
if hasattr(target_attr, "handlers"):
for handler, group in target_attr.handlers:
if isinstance(handler, Handler) and isinstance(group, int):
self.remove_handler(handler, group)

log.info('[{}] [UNLOAD] {}("{}") from group {} in "{}"'.format(
self.name, type(handler).__name__, name, group, module_path))

count -= 1
except Exception:
if warn_non_existent_functions:
log.warning('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"'.format(
self.name, name, module_path))
elif warn_non_existent_functions:
log.warning('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"'.format(
self.name, name, module_path))

if count > 0:
log.info('[{}] Successfully loaded {} plugin{} from "{}"'.format(
Expand Down