MissKatyPyro/database/blacklist_db.py
yasirarism 9cb6a7d77d
Major change with own custom client decorator (#170)
* Add kbbi and carbon

* add blacklist command

* style: format code with black and isort (#168)

Format code with black and isort

This commit fixes the style issues introduced in bffcf61 according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/4ddb51cc-a1ca-432a-95c4-1fb5388b405a/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

* okk

* style: format code with black and isort (#169)

Format code with black and isort

This commit fixes the style issues introduced in 9355c09 according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/172890f8-d001-4812-8380-9a666a9a3bd5/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

* jmm

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2023-07-05 13:10:44 +07:00

33 lines
No EOL
1 KiB
Python

from database import dbname
from typing import List
blacklist_filtersdb = dbname["blacklistFilters"]
async def get_blacklisted_words(chat_id: int) -> List[str]:
_filters = await blacklist_filtersdb.find_one({"chat_id": chat_id})
if not _filters:
return []
return _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