From 4e516d097f31b65e411e8c21493a114014fe0a80 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 12 Oct 2018 14:32:35 +0200 Subject: [PATCH] Don't raise exceptions in case of non-existent plugins folder Don't even warn in case the default plugins folder doesn't exist --- pyrogram/client/client.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index b59469d2..0274e59f 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -231,22 +231,30 @@ class Client(Methods, BaseClient): ) if self.plugins_dir is not None: - for i in os.listdir(self.plugins_dir): - module = import_module("{}.{}".format(self.plugins_dir, i.split(".")[0])) + try: + dirs = os.listdir(self.plugins_dir) + except FileNotFoundError as e: + if self.plugins_dir == Client.PLUGINS_DIR: + pass + else: + log.warning(e) + else: + for i in dirs: + module = import_module("{}.{}".format(self.plugins_dir, i.split(".")[0])) - for j in dir(module): - # noinspection PyBroadException - try: - handler, group = getattr(module, j) + for j in dir(module): + # noinspection PyBroadException + try: + handler, group = getattr(module, j) - if isinstance(handler, Handler) and isinstance(group, int): - self.add_handler(handler, group) + if isinstance(handler, Handler) and isinstance(group, int): + self.add_handler(handler, group) - log.info('{}("{}") from "{}/{}" registered in group {}'.format( - type(handler).__name__, j, self.plugins_dir, i, group) - ) - except Exception: - pass + log.info('{}("{}") from "{}/{}" registered in group {}'.format( + type(handler).__name__, j, self.plugins_dir, i, group) + ) + except Exception: + pass self.session.start() self.is_started = True