Refactoring: step3
- вся работа с shelve унесена в report - вся работа с БД унесена в моделс (крме команд админа) - ид книги лутца и звука вынесены в константы - исправлен баг в проверке на смешанный алфавит при определении спама, добавлены константы для более точного выявления - написаны новые тесты в том числе на цитаты и действия админов
This commit is contained in:
@@ -2,6 +2,7 @@ from pathlib import Path
|
||||
|
||||
from sqlalchemy import Column, String, Integer, Boolean, ForeignKey
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
||||
|
||||
Base = declarative_base()
|
||||
@@ -49,3 +50,29 @@ class Chat(Base):
|
||||
|
||||
def __repr__(self):
|
||||
return f'Chat({self.chat_id=}, {self.title=})'
|
||||
|
||||
|
||||
def is_antispam_enabled(chat_id: int) -> bool:
|
||||
try:
|
||||
return session.query(Chat.antispam).filter_by(chat_id=chat_id).first()[0]
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def is_quote_in_chat(text: str, chat_id: int) -> bool:
|
||||
result = session.query(Quote.text).filter_by(text=text, chat_id=chat_id).first()
|
||||
return bool(result)
|
||||
|
||||
|
||||
def delete_quote_in_chat(text: str, chat_id: int):
|
||||
session.execute(delete(Quote).filter_by(text=text, chat_id=chat_id))
|
||||
session.commit()
|
||||
|
||||
|
||||
def all_chat_quotes(chat_id: int) -> list:
|
||||
return session.query(Quote.text).filter(Quote.chat_id == chat_id).all()
|
||||
|
||||
|
||||
def add_quote(chat_id: int, text: str):
|
||||
session.add(Quote(chat_id=chat_id, text=text))
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user