diff options
author | Kyomotoi <[email protected]> | 2021-03-07 15:24:17 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2021-03-07 15:24:17 +0800 |
commit | da888ff020805a38a17e5f83705aeb42ffa992ba (patch) | |
tree | 28fa5cc06c3b77970ced9136f12ed2bd94436926 /ATRI/service/banlist.py | |
parent | 51624483cb23e8922cbdf5f529e1dcb2342333a7 (diff) | |
download | ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.gz ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.bz2 ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.zip |
♻️⚡️ 重构 Service,优化部分代码
Diffstat (limited to 'ATRI/service/banlist.py')
-rw-r--r-- | ATRI/service/banlist.py | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/ATRI/service/banlist.py b/ATRI/service/banlist.py deleted file mode 100644 index e1ce6b7..0000000 --- a/ATRI/service/banlist.py +++ /dev/null @@ -1,53 +0,0 @@ -import json -import aiofiles -from typing import Optional - -from ATRI.exceptions import WriteError -from . import SERVICE_DIR - - -class BanSystem: - - file_name = "banlist.service.json" - path = SERVICE_DIR / file_name - path.parent.mkdir(exist_ok=True, parents=True) - try: - data = json.loads(path.read_bytes()) - except: - data = {} - - @classmethod - def get_list(cls) -> dict: - return cls.data - - @classmethod - def is_in_list(cls, user: Optional[str]) -> bool: - return False if user in cls.data else True - - @classmethod - async def add_to_list(cls, user: Optional[str]) -> None: - cls.data[user] = user - try: - async with aiofiles.open( - cls.path, 'w', encoding='utf-8') as target: - await target.write( - json.dumps( - cls.data, indent=4 - ) - ) - except WriteError: - raise WriteError("Writing file failed!") - - @classmethod - async def del_from_list(cls, user: Optional[str]) -> None: - del cls.data[user] - try: - async with aiofiles.open( - cls.path, 'w', encoding='utf-8') as target: - await target.write( - json.dumps( - cls.data, indent=4 - ) - ) - except WriteError: - raise WriteError("Writing file failed!") |