MissKatyPyro/database/blacklist_db.py
Yasir Aris M 983db69864
'Refactored by Sourcery'
Co-authored-by: Sourcery AI <>
2024-01-15 07:33:05 +07:00

35 lines
1,008 B
Python

from typing import List
from database import dbname
blacklist_filtersdb = dbname["blacklistFilters"]
async def get_blacklisted_words(chat_id: int) -> List[str]:
_filters = await blacklist_filtersdb.find_one({"chat_id": chat_id})
return [] if not _filters else _filters["filters"]
async def save_blacklist_filter(chat_id: int, word: str):
word = word.lower().strip()
_filters = await get_blacklisted_words(chat_id)
_filters.append(word)
await blacklist_filtersdb.update_one(
{"chat_id": chat_id},
{"$set": {"filters": _filters}},
upsert=True,
)
async def delete_blacklist_filter(chat_id: int, word: str) -> bool:
filtersd = await get_blacklisted_words(chat_id)
word = word.lower().strip()
if word in filtersd:
filtersd.remove(word)
await blacklist_filtersdb.update_one(
{"chat_id": chat_id},
{"$set": {"filters": filtersd}},
upsert=True,
)
return True
return False