Fix some stuff for deepsource

pull/1/head
hikariatama 2022-04-29 17:57:56 +00:00
parent df3a2befd3
commit 02fd9ad602
6 changed files with 19 additions and 19 deletions

View File

@ -213,6 +213,9 @@ class CommandDispatcher:
change = str.maketrans(ru_keys + en_keys, en_keys + ru_keys) change = str.maketrans(ru_keys + en_keys, en_keys + ru_keys)
message = utils.censor(event.message) message = utils.censor(event.message)
if not event.message.message:
return False
if event.message.message.startswith(prefix): if event.message.message.startswith(prefix):
pass pass
elif event.message.message.startswith(str.translate(prefix, change)): elif event.message.message.startswith(str.translate(prefix, change)):
@ -295,7 +298,6 @@ class CommandDispatcher:
and initiator not in self._db.get(main.__name__, "nonickusers", []) and initiator not in self._db.get(main.__name__, "nonickusers", [])
and utils.get_chat_id(event) not in self._db.get(main.__name__, "nonickchats", []) and utils.get_chat_id(event) not in self._db.get(main.__name__, "nonickchats", [])
): ):
logging.debug("Ignoring message without nickname")
return False return False
txt, func = self._modules.dispatch(tag[0]) txt, func = self._modules.dispatch(tag[0])
@ -322,7 +324,6 @@ class CommandDispatcher:
f"{str(utils.get_chat_id(message))}.{func.__self__.__module__}" f"{str(utils.get_chat_id(message))}.{func.__self__.__module__}"
in blacklist_chats in blacklist_chats
): ):
logging.debug("Command is blacklisted in chat")
return False return False
if ( if (
@ -330,7 +331,6 @@ class CommandDispatcher:
and f"{utils.get_chat_id(message)}.{func.__self__.__module__}" and f"{utils.get_chat_id(message)}.{func.__self__.__module__}"
not in whitelist_modules not in whitelist_modules
): ):
logging.debug("Command is not whitelisted in chat")
return False return False
if self._db.get(main.__name__, "grep", False): if self._db.get(main.__name__, "grep", False):

View File

@ -750,5 +750,5 @@ class Modules:
async def log(self, type_, *, group=None, affected_uids=None, data=None): async def log(self, type_, *, group=None, affected_uids=None, data=None):
return await asyncio.gather(*[fun(type_, group, affected_uids, data) for fun in self._log_handlers]) # fmt: skip return await asyncio.gather(*[fun(type_, group, affected_uids, data) for fun in self._log_handlers]) # fmt: skip
def register_logger(self, logger): def register_logger(self, _logger):
self._log_handlers.append(logger) self._log_handlers.append(_logger)

View File

@ -117,7 +117,7 @@ class HelpMod(loader.Module):
module = self.allmodules.commands[args].__self__ module = self.allmodules.commands[args].__self__
if not module: if not module:
module_name = next( module_name = next( # skipcq: PTC-W0063
reversed( reversed(
sorted( sorted(
[ [
@ -133,7 +133,7 @@ class HelpMod(loader.Module):
) )
) )
module = next( module = next( # skipcq: PTC-W0063
module module
for module in self.allmodules.modules for module in self.allmodules.modules
if module.strings["name"] == module_name if module.strings["name"] == module_name

View File

@ -35,8 +35,8 @@ import logging
import os import os
import re import re
import sys import sys
import urllib
import uuid import uuid
from urllib.parse import urlparse
from importlib.machinery import ModuleSpec from importlib.machinery import ModuleSpec
import telethon import telethon
from telethon.tl.types import Message from telethon.tl.types import Message
@ -190,7 +190,7 @@ class LoaderMod(loader.Module):
async def dlmodcmd(self, message: Message) -> None: async def dlmodcmd(self, message: Message) -> None:
"""Downloads and installs a module from the official module repo""" """Downloads and installs a module from the official module repo"""
if args := utils.get_args(message): if args := utils.get_args(message):
args = args[0] if urllib.parse.urlparse(args[0]).netloc else args[0].lower() args = args[0] if urlparse(args[0]).netloc else args[0].lower()
await self.download_and_install(args, message) await self.download_and_install(args, message)
self._update_modules_in_db() self._update_modules_in_db()
@ -202,10 +202,10 @@ class LoaderMod(loader.Module):
+ f"\n☁️ {repo.strip('/')}\n\n" + f"\n☁️ {repo.strip('/')}\n\n"
+ "\n".join( + "\n".join(
[ [
" ".join(chunk).strip(" | ") " | ".join(chunk)
for chunk in utils.chunks( for chunk in utils.chunks(
[ [
f"<code>{i}</code> | " f"<code>{i}</code>"
for i in sorted( for i in sorted(
[ [
utils.escape_html( utils.escape_html(
@ -291,7 +291,7 @@ class LoaderMod(loader.Module):
async def download_and_install(self, module_name, message=None): async def download_and_install(self, module_name, message=None):
try: try:
if urllib.parse.urlparse(module_name).netloc: if urlparse(module_name).netloc:
url = module_name url = module_name
else: else:
links = list( links = list(
@ -582,7 +582,7 @@ class LoaderMod(loader.Module):
save_fs, save_fs,
) # Try again ) # Try again
except loader.LoadError as e: except loader.LoadError as e:
self.allmodules.modules.remove(instance) self.allmodules.modules.remove(instance) # skipcq: PYL-E0601
if message: if message:
await utils.answer(message, f"🚫 <b>{utils.escape_html(str(e))}</b>") await utils.answer(message, f"🚫 <b>{utils.escape_html(str(e))}</b>")
return return
@ -826,4 +826,4 @@ class LoaderMod(loader.Module):
}, },
) )
await self._update_modules() asyncio.ensure_future(self._update_modules())

View File

@ -84,9 +84,9 @@ class TestMod(loader.Module):
async def watchdog(self): async def watchdog(self):
while True: while True:
try: try:
for mod in os.scandir(DEBUG_MODS_DIR): for module in os.scandir(DEBUG_MODS_DIR):
last_modified = os.stat(mod.path).st_mtime last_modified = os.stat(module.path).st_mtime
cls_ = mod.path.split("/")[-1].split(".py")[0] cls_ = module.path.split("/")[-1].split(".py")[0]
if cls_ not in self._memory: if cls_ not in self._memory:
self._memory[cls_] = last_modified self._memory[cls_] = last_modified
@ -97,7 +97,7 @@ class TestMod(loader.Module):
self._memory[cls_] = last_modified self._memory[cls_] = last_modified
logger.debug(f"Reloading debug module {cls_}") logger.debug(f"Reloading debug module {cls_}")
with open(mod.path, "r") as f: with open(module.path, "r") as f:
try: try:
await next( await next(
module module

View File

@ -77,7 +77,7 @@ function finish_login() {
method: "POST", method: "POST",
credentials: "include" credentials: "include"
}) })
.then((response) => { .then(() => {
window.expanse = true; window.expanse = true;
$(".blur").fadeOut(1500); $(".blur").fadeOut(1500);
setTimeout(() => { setTimeout(() => {