名单作用域拆分
parent
f232a54c59
commit
eba49f7529
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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] # 发送语音设置
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue