linter+fmt

This commit is contained in:
Untone 2024-09-27 13:30:29 +03:00
parent eff5cdb394
commit 21591df427
7 changed files with 14 additions and 15 deletions

View File

@ -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"

View File

@ -8,7 +8,6 @@ from utils.mention import mention
logger = logging.getLogger(__name__)
positive_reactions = [
"👍",
"",

View File

@ -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(

View File

@ -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

View File

@ -6,7 +6,6 @@ import logging
logger = logging.getLogger("state.redis")
class RedisService:
def __init__(self, uri=REDIS_URL):
self._uri: str = uri

View File

@ -6,7 +6,6 @@ import math
logger = logging.getLogger("state.scan")
async def get_all_pattern(uid):
pattern = f"removed:{uid}:*"

View File

@ -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: