Skip to content

Commit

Permalink
pyrofork: Ignore excluded plugins [2/2]
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Sep 25, 2024
1 parent f42b5f0 commit b41936b
Showing 1 changed file with 74 additions and 5 deletions.
79 changes: 74 additions & 5 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ async def load_session(self):
except Exception as e:
print(e)

def is_excluded(self, exclude, module):
for e in exclude:
if module == e or module.startswith(e + '.'):
return True
return False

def load_plugins(self):
if self.plugins:
plugins = self.plugins.copy()
Expand Down Expand Up @@ -952,7 +958,7 @@ def load_plugins(self):
else:
for path, handlers in include:
module_path = root.replace("/", ".") + "." + path
if module_path in exclude_plugins:
if self.is_excluded(exclude_plugins, module_path):
log.warning(
'[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path
)
Expand All @@ -971,10 +977,73 @@ def load_plugins(self):
continue

if "__path__" in dir(module):
log.warning(
'[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path
)
continue
for current_root, _, filenames in os.walk(module.replace(".", "/")):
namespace = current_root.replace("/", ".")
if "__pycache__" in namespace:
continue
if namespace in exclude_plugins:
log.warning(
'[%s] [LOAD] Ignoring namespace "%s"', self.name, namespace
)
continue
else:
for filename in filenames:
if filename.endswith(".py"):
module_path = namespace + "." + filename[:-3]
if module_path in exclude_plugins:
log.warning(
'[%s] [LOAD] Ignoring namespace "%s"',
self.name,
module_path,
)
continue
else:
module = import_module(module_path)

for name in vars(module).keys():

# noinspection PyBroadException
try:
for handler, group in getattr(
module, name
).handlers:
if isinstance(
handler, Handler
) and isinstance(group, int):

if (
module_path in exclude_handlers
and name
in exclude_handlers[module_path]
):
exclude_handlers[
module_path
].remove(name)
log.warning(
'[{}] [LOAD] Ignoring function "{}" from group {} in "{}"'.format(
self.name,
name,
group,
module_path,
)
)
continue

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 as e:
pass

if handlers is None:
handlers = vars(module).keys()
Expand Down

0 comments on commit b41936b

Please sign in to comment.