mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Fix plugins not getting reloaded properly when restarting a client
This commit is contained in:
parent
7baa00353d
commit
fd0a40442a
@ -1085,29 +1085,34 @@ class Client(Methods, BaseClient):
|
|||||||
self._proxy["password"] = parser.get("proxy", "password", fallback=None) or None
|
self._proxy["password"] = parser.get("proxy", "password", fallback=None) or None
|
||||||
|
|
||||||
if self.plugins:
|
if self.plugins:
|
||||||
self.plugins["enabled"] = bool(self.plugins.get("enabled", True))
|
self.plugins = {
|
||||||
self.plugins["include"] = "\n".join(self.plugins.get("include", [])) or None
|
"enabled": bool(self.plugins.get("enabled", True)),
|
||||||
self.plugins["exclude"] = "\n".join(self.plugins.get("exclude", [])) or None
|
"root": self.plugins.get("root", None),
|
||||||
|
"include": self.plugins.get("include", []),
|
||||||
|
"exclude": self.plugins.get("exclude", [])
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
section = parser["plugins"]
|
section = parser["plugins"]
|
||||||
|
|
||||||
self.plugins = {
|
self.plugins = {
|
||||||
"enabled": section.getboolean("enabled", True),
|
"enabled": section.getboolean("enabled", True),
|
||||||
"root": section.get("root"),
|
"root": section.get("root", None),
|
||||||
"include": section.get("include") or None,
|
"include": section.get("include", []),
|
||||||
"exclude": section.get("exclude") or None
|
"exclude": section.get("exclude", [])
|
||||||
}
|
}
|
||||||
except KeyError:
|
|
||||||
self.plugins = {}
|
|
||||||
|
|
||||||
if self.plugins:
|
include = self.plugins["include"]
|
||||||
for option in ["include", "exclude"]:
|
exclude = self.plugins["exclude"]
|
||||||
if self.plugins[option] is not None:
|
|
||||||
self.plugins[option] = [
|
if include:
|
||||||
(i.split()[0], i.split()[1:] or None)
|
self.plugins["include"] = include.strip().split("\n")
|
||||||
for i in self.plugins[option].strip().split("\n")
|
|
||||||
]
|
if exclude:
|
||||||
|
self.plugins["exclude"] = exclude.strip().split("\n")
|
||||||
|
|
||||||
|
except KeyError:
|
||||||
|
self.plugins = None
|
||||||
|
|
||||||
def load_session(self):
|
def load_session(self):
|
||||||
try:
|
try:
|
||||||
@ -1142,14 +1147,26 @@ class Client(Methods, BaseClient):
|
|||||||
self.peers_by_phone[k] = peer
|
self.peers_by_phone[k] = peer
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
if self.plugins.get("enabled", False):
|
if self.plugins:
|
||||||
root = self.plugins["root"]
|
plugins = self.plugins.copy()
|
||||||
include = self.plugins["include"]
|
|
||||||
exclude = self.plugins["exclude"]
|
for option in ["include", "exclude"]:
|
||||||
|
if plugins[option]:
|
||||||
|
plugins[option] = [
|
||||||
|
(i.split()[0], i.split()[1:] or None)
|
||||||
|
for i in self.plugins[option]
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
if plugins.get("enabled", False):
|
||||||
|
root = plugins["root"]
|
||||||
|
include = plugins["include"]
|
||||||
|
exclude = plugins["exclude"]
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
if include is None:
|
if not include:
|
||||||
for path in sorted(Path(root).rglob("*.py")):
|
for path in sorted(Path(root).rglob("*.py")):
|
||||||
module_path = '.'.join(path.parent.parts + (path.stem,))
|
module_path = '.'.join(path.parent.parts + (path.stem,))
|
||||||
module = import_module(module_path)
|
module = import_module(module_path)
|
||||||
@ -1206,7 +1223,7 @@ class Client(Methods, BaseClient):
|
|||||||
log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
|
log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
|
||||||
self.session_name, name, module_path))
|
self.session_name, name, module_path))
|
||||||
|
|
||||||
if exclude is not None:
|
if exclude:
|
||||||
for path, handlers in exclude:
|
for path, handlers in exclude:
|
||||||
module_path = root + "." + path
|
module_path = root + "." + path
|
||||||
warn_non_existent_functions = True
|
warn_non_existent_functions = True
|
||||||
|
@ -106,6 +106,7 @@ class Dispatcher:
|
|||||||
worker.join()
|
worker.join()
|
||||||
|
|
||||||
self.workers_list.clear()
|
self.workers_list.clear()
|
||||||
|
self.groups.clear()
|
||||||
|
|
||||||
def add_handler(self, handler, group: int):
|
def add_handler(self, handler, group: int):
|
||||||
if group not in self.groups:
|
if group not in self.groups:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user