Add an hint about which client is loading the plugins

This commit is contained in:
Dan 2019-05-06 17:39:57 +02:00
parent 47c4fae36d
commit 762ea3e62e

View File

@ -53,8 +53,8 @@ from pyrogram.errors import (
PasswordRecoveryNa, PasswordEmpty PasswordRecoveryNa, PasswordEmpty
) )
from pyrogram.session import Auth, Session from pyrogram.session import Auth, Session
from .ext.utils import ainput
from .ext import utils, Syncer, BaseClient, Dispatcher from .ext import utils, Syncer, BaseClient, Dispatcher
from .ext.utils import ainput
from .methods import Methods from .methods import Methods
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -1181,8 +1181,8 @@ class Client(Methods, BaseClient):
if isinstance(handler, Handler) and isinstance(group, int): if isinstance(handler, Handler) and isinstance(group, int):
self.add_handler(handler, group) self.add_handler(handler, group)
log.info('[LOAD] {}("{}") in group {} from "{}"'.format( log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
type(handler).__name__, name, group, module_path)) self.session_name, type(handler).__name__, name, group, module_path))
count += 1 count += 1
except Exception: except Exception:
@ -1195,11 +1195,13 @@ class Client(Methods, BaseClient):
try: try:
module = import_module(module_path) module = import_module(module_path)
except ImportError: except ImportError:
log.warning('[LOAD] Ignoring non-existent module "{}"'.format(module_path)) log.warning('[{}] [LOAD] Ignoring non-existent module "{}"'.format(
self.session_name, module_path))
continue continue
if "__path__" in dir(module): if "__path__" in dir(module):
log.warning('[LOAD] Ignoring namespace "{}"'.format(module_path)) log.warning('[{}] [LOAD] Ignoring namespace "{}"'.format(
self.session_name, module_path))
continue continue
if handlers is None: if handlers is None:
@ -1214,14 +1216,14 @@ class Client(Methods, BaseClient):
if isinstance(handler, Handler) and isinstance(group, int): if isinstance(handler, Handler) and isinstance(group, int):
self.add_handler(handler, group) self.add_handler(handler, group)
log.info('[LOAD] {}("{}") in group {} from "{}"'.format( log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format(
type(handler).__name__, name, group, module_path)) self.session_name, type(handler).__name__, name, group, module_path))
count += 1 count += 1
except Exception: except Exception:
if warn_non_existent_functions: if warn_non_existent_functions:
log.warning('[LOAD] Ignoring non-existent function "{}" from "{}"'.format( log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format(
name, module_path)) self.session_name, name, module_path))
if exclude is not None: if exclude is not None:
for path, handlers in exclude: for path, handlers in exclude:
@ -1231,11 +1233,13 @@ class Client(Methods, BaseClient):
try: try:
module = import_module(module_path) module = import_module(module_path)
except ImportError: except ImportError:
log.warning('[UNLOAD] Ignoring non-existent module "{}"'.format(module_path)) log.warning('[{}] [UNLOAD] Ignoring non-existent module "{}"'.format(
self.session_name, module_path))
continue continue
if "__path__" in dir(module): if "__path__" in dir(module):
log.warning('[UNLOAD] Ignoring namespace "{}"'.format(module_path)) log.warning('[{}] [UNLOAD] Ignoring namespace "{}"'.format(
self.session_name, module_path))
continue continue
if handlers is None: if handlers is None:
@ -1250,19 +1254,21 @@ class Client(Methods, BaseClient):
if isinstance(handler, Handler) and isinstance(group, int): if isinstance(handler, Handler) and isinstance(group, int):
self.remove_handler(handler, group) self.remove_handler(handler, group)
log.info('[UNLOAD] {}("{}") from group {} in "{}"'.format( log.info('[{}] [UNLOAD] {}("{}") from group {} in "{}"'.format(
type(handler).__name__, name, group, module_path)) self.session_name, type(handler).__name__, name, group, module_path))
count -= 1 count -= 1
except Exception: except Exception:
if warn_non_existent_functions: if warn_non_existent_functions:
log.warning('[UNLOAD] Ignoring non-existent function "{}" from "{}"'.format( log.warning('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"'.format(
name, module_path)) self.session_name, name, module_path))
if count > 0: if count > 0:
log.warning('Successfully loaded {} plugin{} from "{}"'.format(count, "s" if count > 1 else "", root)) log.warning('[{}] Successfully loaded {} plugin{} from "{}"'.format(
self.session_name, count, "s" if count > 1 else "", root))
else: else:
log.warning('No plugin loaded from "{}"'.format(root)) log.warning('[{}] No plugin loaded from "{}"'.format(
self.session_name, root))
def save_session(self): def save_session(self):
auth_key = base64.b64encode(self.auth_key).decode() auth_key = base64.b64encode(self.auth_key).decode()