mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-11 05:20:57 +00:00
fix: 无法根据ban_person忽略群内指定人消息 (#211)
This commit is contained in:
+21
-17
@@ -1,30 +1,34 @@
|
|||||||
import pkg.utils.context
|
import pkg.utils.context
|
||||||
|
|
||||||
|
|
||||||
def is_banned(launcher_type: str, launcher_id: int) -> bool:
|
def is_banned(launcher_type: str, launcher_id: int, sender_id: int) -> bool:
|
||||||
if not pkg.utils.context.get_qqbot_manager().enable_banlist:
|
if not pkg.utils.context.get_qqbot_manager().enable_banlist:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
if launcher_type == 'group':
|
if launcher_type == 'group':
|
||||||
for group_rule in pkg.utils.context.get_qqbot_manager().ban_group:
|
# 检查是否显式声明发起人QQ要被person忽略
|
||||||
if type(group_rule) == int:
|
if sender_id in pkg.utils.context.get_qqbot_manager().ban_person:
|
||||||
if group_rule == launcher_id: # 此群群号被禁用
|
result = True
|
||||||
result = True
|
else:
|
||||||
elif type(group_rule) == str:
|
for group_rule in pkg.utils.context.get_qqbot_manager().ban_group:
|
||||||
if group_rule.startswith('!'):
|
if type(group_rule) == int:
|
||||||
# 截取!后面的字符串作为表达式,判断是否匹配
|
if group_rule == launcher_id: # 此群群号被禁用
|
||||||
reg_str = group_rule[1:]
|
|
||||||
import re
|
|
||||||
if re.match(reg_str, str(launcher_id)): # 被豁免,最高级别
|
|
||||||
result = False
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# 判断是否匹配regexp
|
|
||||||
import re
|
|
||||||
if re.match(group_rule, str(launcher_id)): # 此群群号被禁用
|
|
||||||
result = True
|
result = True
|
||||||
|
elif type(group_rule) == str:
|
||||||
|
if group_rule.startswith('!'):
|
||||||
|
# 截取!后面的字符串作为表达式,判断是否匹配
|
||||||
|
reg_str = group_rule[1:]
|
||||||
|
import re
|
||||||
|
if re.match(reg_str, str(launcher_id)): # 被豁免,最高级别
|
||||||
|
result = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# 判断是否匹配regexp
|
||||||
|
import re
|
||||||
|
if re.match(group_rule, str(launcher_id)): # 此群群号被禁用
|
||||||
|
result = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# ban_person, 与群规则相同
|
# ban_person, 与群规则相同
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||||||
session_name = "{}_{}".format(launcher_type, launcher_id)
|
session_name = "{}_{}".format(launcher_type, launcher_id)
|
||||||
|
|
||||||
# 检查发送方是否被禁用
|
# 检查发送方是否被禁用
|
||||||
if banlist.is_banned(launcher_type, launcher_id):
|
if banlist.is_banned(launcher_type, launcher_id, sender_id):
|
||||||
logging.info("根据禁用列表忽略{}_{}的消息".format(launcher_type, launcher_id))
|
logging.info("根据禁用列表忽略{}_{}的消息".format(launcher_type, launcher_id))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user