名单作用域拆分

pull/31/head
UnCLAS-Prommer 2025-05-19 22:49:45 +08:00
parent f232a54c59
commit eba49f7529
3 changed files with 23 additions and 16 deletions

View File

@ -55,13 +55,17 @@ class Config:
logger.critical("请在配置文件中指定平台") logger.critical("请在配置文件中指定平台")
sys.exit(1) sys.exit(1)
self.list_type: str = raw_config["Chat"].get("list_type") self.group_list_type: str = raw_config["Chat"].get("group_list_type")
self.group_list: list = raw_config["Chat"].get("group_list", []) self.group_list: list = raw_config["Chat"].get("group_list", [])
self.private_list_type: str = raw_config["Chat"].get("private_list_type")
self.private_list: list = raw_config["Chat"].get("private_list", []) self.private_list: list = raw_config["Chat"].get("private_list", [])
self.ban_user_id: list = raw_config["Chat"].get("ban_user_id", []) self.ban_user_id: list = raw_config["Chat"].get("ban_user_id", [])
self.enable_poke: bool = raw_config["Chat"].get("enable_poke", True) self.enable_poke: bool = raw_config["Chat"].get("enable_poke", True)
if not self.list_type or self.list_type not in ["whitelist", "blacklist"]: if self.group_list_type not in ["whitelist", "blacklist"]:
logger.critical("请在配置文件中指定list_type或list_type填写错误") logger.critical("请在配置文件中指定group_list_type或group_list_type填写错误")
sys.exit(1)
if self.private_list_type not in ["whitelist", "blacklist"]:
logger.critical("请在配置文件中指定private_list_type或private_list_type填写错误")
sys.exit(1) sys.exit(1)
self.use_tts = raw_config["Voice"].get("use_tts", False) self.use_tts = raw_config["Voice"].get("use_tts", False)

View File

@ -76,21 +76,21 @@ class RecvHandler:
bool: 是否允许聊天 bool: 是否允许聊天
""" """
if group_id: if group_id:
if global_config.list_type == "whitelist" and group_id not in global_config.group_list: if global_config.group_list_type == "whitelist" and group_id not in global_config.group_list:
logger.warning("群聊不在白名单中,消息被丢弃") logger.warning("群聊不在聊天白名单中,消息被丢弃")
return False return False
elif global_config.list_type == "blacklist" and group_id in global_config.group_list: elif global_config.group_list_type == "blacklist" and group_id in global_config.group_list:
logger.warning("群聊在黑名单中,消息被丢弃") logger.warning("群聊在聊天黑名单中,消息被丢弃")
return False return False
else: else:
if global_config.list_type == "whitelist" and user_id not in global_config.private_list: if global_config.private_list_type == "whitelist" and user_id not in global_config.private_list:
logger.warning("用户不在白名单中,消息被丢弃") logger.warning("用户不在聊天白名单中,消息被丢弃")
return False return False
elif global_config.list_type == "blacklist" and user_id in global_config.private_list: elif global_config.private_list_type == "blacklist" and user_id in global_config.private_list:
logger.warning("用户在黑名单中,消息被丢弃") logger.warning("用户在聊天黑名单中,消息被丢弃")
return False return False
if user_id in global_config.ban_user_id: if user_id in global_config.ban_user_id:
logger.warning("用户在黑名单中,消息被丢弃") logger.warning("用户在全局黑名单中,消息被丢弃")
return False return False
return True return True

View File

@ -12,12 +12,15 @@ host = "localhost" # 麦麦在.env文件中设置的主机地址即HOST字
port = 8000 # 麦麦在.env文件中设置的端口即PORT字段 port = 8000 # 麦麦在.env文件中设置的端口即PORT字段
[Chat] # 黑白名单功能 [Chat] # 黑白名单功能
list_type = "whitelist" # 使用的白名单类型可选为whitelist, blacklist group_list_type = "whitelist" # 群组名单类型可选为whitelist, blacklist
# 当list_type为whitelist时使用白名单模式以下两个列表的含义是仅允许名单中的人聊天
# 当list_type为blacklist时使用黑名单模式以下两个列表的含义是禁止名单中的人聊天
group_list = [] # 群组名单 group_list = [] # 群组名单
# 当group_list_type为whitelist时群组名单中的群组可以聊天
# 当group_list_type为blacklist时群组名单中的群组无法聊天
private_list_type = "whitelist" # 私聊名单类型可选为whitelist, blacklist
private_list = [] # 私聊名单 private_list = [] # 私聊名单
ban_user_id = [] # 禁止名单(禁止名单中的人无法使用任何功能) # 当private_list_type为whitelist时私聊名单中的人可以聊天
# 当private_list_type为blacklist时私聊名单中的人无法聊天
ban_user_id = [] # 禁止名单(禁止名单中的人无法进行任何聊天)
enable_poke = true # 是否启用戳一戳功能 enable_poke = true # 是否启用戳一戳功能
[Voice] # 发送语音设置 [Voice] # 发送语音设置