Spam words moved to DB. Add command: /add_spam
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user