summaryrefslogtreecommitdiff
path: root/ATRI/service/banlist.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
committerKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
commitf5ceb8927f2e7f2a9e29d62c8e4cef876f917249 (patch)
tree40b9dcd6b7d3db486054e3aa9b5a04d25fa2284e /ATRI/service/banlist.py
parenteb52fab79ada7efe6191e3a5f90179766feaded0 (diff)
downloadATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.gz
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.bz2
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.zip
🏗 💩 更改项目结构,修复啥b BUG
Diffstat (limited to 'ATRI/service/banlist.py')
-rw-r--r--ATRI/service/banlist.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/ATRI/service/banlist.py b/ATRI/service/banlist.py
index 06cc381..e1ce6b7 100644
--- a/ATRI/service/banlist.py
+++ b/ATRI/service/banlist.py
@@ -2,32 +2,32 @@ import json
import aiofiles
from typing import Optional
-from ATRI.exceptions import InvalidWriteText
+from ATRI.exceptions import WriteError
+from . import SERVICE_DIR
-from . import SERVICE_PATH
-
-class BanList:
- filename = 'banlist.service.json'
- path = SERVICE_PATH / filename
+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_banlist(cls) -> dict:
+ 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_list(cls, user: Optional[str]) -> None:
+ async def add_to_list(cls, user: Optional[str]) -> None:
+ cls.data[user] = user
try:
- cls.data[user] = user
async with aiofiles.open(
cls.path, 'w', encoding='utf-8') as target:
await target.write(
@@ -35,13 +35,13 @@ class BanList:
cls.data, indent=4
)
)
- except InvalidWriteText:
- raise InvalidWriteText('Writing file failed!')
-
+ except WriteError:
+ raise WriteError("Writing file failed!")
+
@classmethod
- async def del_list(cls, user: Optional[str]) -> None:
+ async def del_from_list(cls, user: Optional[str]) -> None:
+ del cls.data[user]
try:
- del cls.data[user]
async with aiofiles.open(
cls.path, 'w', encoding='utf-8') as target:
await target.write(
@@ -49,5 +49,5 @@ class BanList:
cls.data, indent=4
)
)
- except InvalidWriteText:
- raise InvalidWriteText('List writing file failed!')
+ except WriteError:
+ raise WriteError("Writing file failed!")