From 59fab0a0923a62794782b9ea590aea6dd67c0bbb Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Wed, 3 Aug 2022 18:03:12 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- hikka/dispatcher.py | 2 +- hikka/loader.py | 23 ++++++++++------------- hikka/modules/help.py | 9 ++++----- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/hikka/dispatcher.py b/hikka/dispatcher.py index d8b4252..6d33051 100755 --- a/hikka/dispatcher.py +++ b/hikka/dispatcher.py @@ -249,7 +249,7 @@ class CommandDispatcher: message.out and len(message.message) > 2 and message.message.startswith(prefix * 2) - and not all(s == prefix for s in message.message) + and any(s != prefix for s in message.message) ): # Allow escaping commands using .'s if not watcher: diff --git a/hikka/loader.py b/hikka/loader.py index ca1e6ee..363d95f 100644 --- a/hikka/loader.py +++ b/hikka/loader.py @@ -764,7 +764,7 @@ class Modules: strict=True, ).values(): with contextlib.suppress(AttributeError, ValueError): - existing_watcher = next( + if existing_watcher := next( ( existing_watcher for existing_watcher in self.watchers @@ -775,9 +775,7 @@ class Modules: ) ), None, - ) - - if existing_watcher: + ): logger.debug(f"Removing watcher for update {existing_watcher}") self.watchers.remove(existing_watcher) @@ -799,10 +797,7 @@ class Modules: @property def get_approved_channel(self): - if not self.__approve: - return None - - return self.__approve.pop(0) + return self.__approve.pop(0) if self.__approve else None async def _approve( self, @@ -1061,11 +1056,12 @@ class Modules: ver = tuple( map( int, - re.search(r"# ?scope: ?hikka_min ((\d+\.){2}\d+)", code) - .group(1) - .split("."), + re.search(r"# ?scope: ?hikka_min ((\d+\.){2}\d+)", code)[ + 1 + ].split("."), ) ) + if version.__version__ < ver: _raise( RuntimeError( @@ -1149,8 +1145,9 @@ class Modules: _raise(ImportError("Invalid library. Class name must end with 'Lib'")) if ( - not any( - line.replace(" ", "") == "#scope:no_stats" for line in code.splitlines() + all( + line.replace(" ", "") != "#scope:no_stats" + for line in code.splitlines() ) and self._db.get("hikka.main", "stats", True) and url is not None diff --git a/hikka/modules/help.py b/hikka/modules/help.py index e9e6d57..9606e93 100755 --- a/hikka/modules/help.py +++ b/hikka/modules/help.py @@ -187,13 +187,12 @@ class HelpMod(loader.Module): name = getattr(module, "name", "ERROR") _name = ( - utils.escape_html(name) - if not hasattr(module, "__version__") - else ( - f"{utils.escape_html(name)} (v{module.__version__[0]}.{module.__version__[1]}.{module.__version__[2]})" - ) + f"{utils.escape_html(name)} (v{module.__version__[0]}.{module.__version__[1]}.{module.__version__[2]})" + if hasattr(module, "__version__") + else utils.escape_html(name) ) + reply = self.strings("single_mod_header").format(_name) if module.__doc__: reply += "\nℹ️ " + utils.escape_html(inspect.getdoc(module)) + "\n"