mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Ignore excluded plugins [2/2]
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
45e2872fab
commit
3ee16dac4e
1 changed files with 74 additions and 5 deletions
|
|
@ -848,6 +848,12 @@ class Client(Methods):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(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):
|
def load_plugins(self):
|
||||||
if self.plugins:
|
if self.plugins:
|
||||||
plugins = self.plugins.copy()
|
plugins = self.plugins.copy()
|
||||||
|
|
@ -952,7 +958,7 @@ class Client(Methods):
|
||||||
else:
|
else:
|
||||||
for path, handlers in include:
|
for path, handlers in include:
|
||||||
module_path = root.replace("/", ".") + "." + path
|
module_path = root.replace("/", ".") + "." + path
|
||||||
if module_path in exclude_plugins:
|
if self.is_excluded(exclude_plugins, module_path):
|
||||||
log.warning(
|
log.warning(
|
||||||
'[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path
|
'[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path
|
||||||
)
|
)
|
||||||
|
|
@ -971,10 +977,73 @@ class Client(Methods):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if "__path__" in dir(module):
|
if "__path__" in dir(module):
|
||||||
|
for current_root, _, filenames in os.walk(module_path.replace(".", "/")):
|
||||||
|
namespace = current_root.replace("/", ".")
|
||||||
|
if "__pycache__" in namespace:
|
||||||
|
continue
|
||||||
|
if namespace in exclude_plugins:
|
||||||
log.warning(
|
log.warning(
|
||||||
'[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path
|
'[%s] [LOAD] Ignoring namespace "%s"', self.name, namespace
|
||||||
)
|
)
|
||||||
continue
|
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:
|
if handlers is None:
|
||||||
handlers = vars(module).keys()
|
handlers = vars(module).keys()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue