Spam words moved to DB. Add command: /add_spam

This commit is contained in:
Rykov7
2024-05-30 22:42:43 +03:00
parent 1a23d576ed
commit 034c05d957
14 changed files with 43 additions and 287 deletions
+15
View File
@@ -54,6 +54,15 @@ class Chat(Base):
return f'Chat({self.chat_id=}, {self.title=})'
class BadWord(Base):
__tablename__ = 'bad_words'
id = Column(Integer, primary_key=True)
word = Column(String)
def __repr__(self):
return f'BadWord({self.id}: {self.word=})'
CACHE: dict[int, Type[Chat]] = {}
@@ -95,6 +104,12 @@ def add_quote(chat_id: int, text: str):
_reload_chat(chat_id)
def add_spam(chat_id: int, text: str):
session.add(BadWord(word=text))
session.commit()
_reload_chat(chat_id)
def chat_by_id(chat_id: int) -> None | Chat:
return CACHE.get(chat_id)