Skip to content

Commit

Permalink
pyrofork: Don't load excluded plugins at all
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Sep 10, 2024
1 parent 0f3313a commit e514d32
Showing 1 changed file with 7 additions and 35 deletions.
42 changes: 7 additions & 35 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,16 @@ def load_plugins(self):
root = plugins["root"]
include = plugins.get("include", [])
exclude = plugins.get("exclude", [])
exclude_path = []
for path, _ in exclude:
exclude_path.append(path)

count = 0

if not include:
for path in sorted(Path(root.replace(".", "/")).rglob("*.py")):
if exclude_path and path.name.replace(".py", "") in exclude_path:
continue
module_path = '.'.join(path.parent.parts + (path.stem,))
module = import_module(module_path)

Expand All @@ -888,6 +893,8 @@ def load_plugins(self):
pass
else:
for path, handlers in include:
if exclude_path and path in exclude_path:
continue
module_path = root.replace("/",".") + "." + path
warn_non_existent_functions = True

Expand Down Expand Up @@ -921,41 +928,6 @@ def load_plugins(self):
log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
self.name, name, module_path))

if exclude:
for path, handlers in exclude:
module_path = root.replace("/",".") + "." + path
warn_non_existent_functions = True

try:
module = import_module(module_path)
except ImportError:
log.warning('[%s] [UNLOAD] Ignoring non-existent module "%s"', self.name, module_path)
continue

if "__path__" in dir(module):
log.warning('[%s] [UNLOAD] Ignoring namespace "%s"', self.name, module_path)
continue

if handlers is None:
handlers = vars(module).keys()
warn_non_existent_functions = False

for name in handlers:
# noinspection PyBroadException
try:
for handler, group in getattr(module, name).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))

if count > 0:
log.info('[{}] Successfully loaded {} plugin{} from "{}"'.format(
self.name, count, "s" if count > 1 else "", root))
Expand Down

0 comments on commit e514d32

Please sign in to comment.