From 21591df4276fa6fc145118d19b05fee603bc8fd7 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 27 Sep 2024 13:30:29 +0300 Subject: [PATCH] linter+fmt --- bot/announce.py | 1 - handlers/handle_join_request.py | 1 - handlers/messages_routing.py | 15 ++++++++------- nlp/normalize.py | 9 ++++++--- state/redis.py | 1 - state/scan.py | 1 - utils/graph.py | 1 - 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bot/announce.py b/bot/announce.py index b85ca79..8a93035 100644 --- a/bot/announce.py +++ b/bot/announce.py @@ -7,7 +7,6 @@ import logging logger = logging.getLogger(__name__) - def get_newcomer_message(msg): lang = msg["from"].get("language_code", "ru") r = "хочет присоединиться к нам здесь" if lang == "ru" else " wants to join us here" diff --git a/handlers/handle_join_request.py b/handlers/handle_join_request.py index 45add5b..5fbd3ce 100644 --- a/handlers/handle_join_request.py +++ b/handlers/handle_join_request.py @@ -8,7 +8,6 @@ from utils.mention import mention logger = logging.getLogger(__name__) - positive_reactions = [ "👍", "❤", diff --git a/handlers/messages_routing.py b/handlers/messages_routing.py index ce8a916..cd0b71d 100644 --- a/handlers/messages_routing.py +++ b/handlers/messages_routing.py @@ -11,7 +11,6 @@ from nlp.toxicity_detector import detector logger = logging.getLogger("handlers.messages_routing") - async def messages_routing(msg, state): cid = msg["chat"]["id"] uid = msg["from"]["id"] @@ -53,13 +52,13 @@ async def messages_routing(msg, state): # count average between all of messages toxic_pattern = f"toxic:{cid}:{uid}:*" toxic_score = await get_average_pattern(toxic_pattern) - except: + except Exception: pass # current mesasage toxicity if reply_to_msg_id: one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}") - reply_text = '' + reply_text = "" if one_score: logger.debug(one_score) reply_text += f"{int(one_score)}% токсичности\n" @@ -75,7 +74,9 @@ async def messages_routing(msg, state): if toxic_score > 20 else "😇" ) - reply_text += "Средняя токсичность сообщений: {toxic_score}% {emoji}" + reply_text += ( + f"Средняя токсичность сообщений: {toxic_score}% {emoji}" + ) if reply_text: await telegram_api( "sendMessage", @@ -85,12 +86,12 @@ async def messages_routing(msg, state): ) try: await telegram_api("deleteMessage", chat_id=cid, message_id=mid) - except: + except Exception: pass elif text == "/removed@welcomecenter_bot": try: await telegram_api("deleteMessage", chat_id=cid, message_id=mid) - except: + except Exception: pass else: toxic_score = detector(text) @@ -103,7 +104,7 @@ async def messages_routing(msg, state): await redis.set(f"removed:{uid}:{cid}:{mid}", text) try: await telegram_api("deleteMessage", chat_id=cid, message_id=mid) - except: + except Exception: pass else: await telegram_api( diff --git a/nlp/normalize.py b/nlp/normalize.py index 9e06230..11ab692 100644 --- a/nlp/normalize.py +++ b/nlp/normalize.py @@ -1,5 +1,8 @@ import torch from transformers import ByT5Tokenizer, T5ForConditionalGeneration +import logging + +logger = logging.getLogger("nlp.normalize") # Use ByT5 for the ByT5 model tokenizer = ByT5Tokenizer.from_pretrained("google/byt5-small") @@ -48,8 +51,8 @@ def normalize(text): if is_russian_wording(t): # Normalize the text by replacing characters - normalized_text = (t - .replace("e", "е") + normalized_text = ( + t.replace("e", "е") .replace("o", "о") .replace("x", "х") .replace("a", "а") @@ -73,7 +76,7 @@ def normalize(text): ) return normalized_text - logger.debug('normalized: ', t) + logger.debug("normalized: ", t) return t diff --git a/state/redis.py b/state/redis.py index 364fc2d..2f1f04e 100644 --- a/state/redis.py +++ b/state/redis.py @@ -6,7 +6,6 @@ import logging logger = logging.getLogger("state.redis") - class RedisService: def __init__(self, uri=REDIS_URL): self._uri: str = uri diff --git a/state/scan.py b/state/scan.py index a2eae9a..3271a2c 100644 --- a/state/scan.py +++ b/state/scan.py @@ -6,7 +6,6 @@ import math logger = logging.getLogger("state.scan") - async def get_all_pattern(uid): pattern = f"removed:{uid}:*" diff --git a/utils/graph.py b/utils/graph.py index 81e5e04..788e40e 100644 --- a/utils/graph.py +++ b/utils/graph.py @@ -3,7 +3,6 @@ import logging logger = logging.getLogger(__name__) - # Define SVG code generation function with member_id parameter def generate_chart(members, member_id=None): if not member_id: