summaryrefslogtreecommitdiff
path: root/ATRI/utils/utils_rule
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-11-28 21:23:22 +0800
committerKyomotoi <[email protected]>2020-11-28 21:23:22 +0800
commitf5059aeccfc646f53ee05a35baf447b152c3a6e1 (patch)
treef27c8de60b9c517443f154e727f5f0f4e5a41a6c /ATRI/utils/utils_rule
parenta6343b34472eed91b6fed8748ebcefd6c2f6b294 (diff)
downloadATRI-f5059aeccfc646f53ee05a35baf447b152c3a6e1.tar.gz
ATRI-f5059aeccfc646f53ee05a35baf447b152c3a6e1.tar.bz2
ATRI-f5059aeccfc646f53ee05a35baf447b152c3a6e1.zip
[Fix]
Diffstat (limited to 'ATRI/utils/utils_rule')
-rw-r--r--ATRI/utils/utils_rule/__init__.py46
-rw-r--r--ATRI/utils/utils_rule/ban_list_group.json1
-rw-r--r--ATRI/utils/utils_rule/switch.json2
3 files changed, 3 insertions, 46 deletions
diff --git a/ATRI/utils/utils_rule/__init__.py b/ATRI/utils/utils_rule/__init__.py
index dcaeedc..cddf93e 100644
--- a/ATRI/utils/utils_rule/__init__.py
+++ b/ATRI/utils/utils_rule/__init__.py
@@ -13,12 +13,11 @@ __author__ = 'kyomotoi'
import os
import json
from pathlib import Path
-from typing import Optional
from nonebot.rule import Rule
from nonebot.typing import Bot, Event
-def check_banlist(for_group: Optional[bool] = False) -> Rule:
+def check_banlist() -> Rule:
'''
检查目标是否存在于封禁名单
@@ -27,62 +26,21 @@ def check_banlist(for_group: Optional[bool] = False) -> Rule:
async def _chech_banlist(bot: Bot, event: Event, state: dict) -> bool:
# 获取目标信息
user = str(event.user_id)
- group = str(event.group_id)
# 名单目录
BAN_LIST_USER_PATH = Path(
'.') / 'ATRI' / 'utils' / 'utils_rule' / 'ban_list_user.json'
- BAN_LIST_GROUP_PATH = Path(
- '.') / 'ATRI' / 'utils' / 'utils_rule' / 'ban_list_group.json'
# 检查文件是否存在,如不存在,自动创建并写入默认值
if not BAN_LIST_USER_PATH.is_file():
with open(BAN_LIST_USER_PATH, 'w') as f:
f.write(json.dumps({}))
- if not BAN_LIST_GROUP_PATH.is_file():
- with open(BAN_LIST_GROUP_PATH, 'w') as f:
- f.write(json.dumps({}))
-
# 读取文件
with open(BAN_LIST_USER_PATH, 'r') as f:
data_user = json.load(f)
- with open(BAN_LIST_GROUP_PATH, 'r') as f:
- data_group = json.load(f)
-
- # 判断目标
- if not for_group:
- if user:
- if user not in data_user:
- if group:
- if group not in data_group:
- return True
- else:
- return False
- else:
- return True
- else:
- return False
-
- elif group:
- if group not in data_group:
- if user:
- if user not in data_user:
- return True
- else:
- return False
- else:
- return True
- else:
- return False
- else:
- return False
- else:
- if group not in data_group:
- return True
- else:
- return False
+ return user not in data_user
return Rule(_chech_banlist)
diff --git a/ATRI/utils/utils_rule/ban_list_group.json b/ATRI/utils/utils_rule/ban_list_group.json
deleted file mode 100644
index 9e26dfe..0000000
--- a/ATRI/utils/utils_rule/ban_list_group.json
+++ /dev/null
@@ -1 +0,0 @@
-{} \ No newline at end of file
diff --git a/ATRI/utils/utils_rule/switch.json b/ATRI/utils/utils_rule/switch.json
index 1717be3..d7ac35e 100644
--- a/ATRI/utils/utils_rule/switch.json
+++ b/ATRI/utils/utils_rule/switch.json
@@ -1 +1 @@
-{"anime-setu": "False", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True", "genshin-search": "True", "drifting-bottle": "True"} \ No newline at end of file
+{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True", "genshin-search": "True", "drifting-bottle": "True"} \ No newline at end of file