Merge pull request #490 from RockChinQ/feat-global-group-private-enable

[Feat] 支持设置全局群聊/私聊消息禁用
This commit is contained in:
Rock Chin 2023-06-07 23:49:53 +08:00 committed by GitHub
commit 67d1ca8a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -102,6 +102,9 @@ class QQBotManager:
enable_banlist = False enable_banlist = False
enable_private = True
enable_group = True
ban_person = [] ban_person = []
ban_group = [] ban_group = []
@ -242,6 +245,11 @@ class QQBotManager:
self.ban_group = banlist.group self.ban_group = banlist.group
logging.info("加载禁用列表: person: {}, group: {}".format(self.ban_person, self.ban_group)) logging.info("加载禁用列表: person: {}, group: {}".format(self.ban_person, self.ban_group))
if hasattr(banlist, "enable_private"):
self.enable_private = banlist.enable_private
if hasattr(banlist, "enable_group"):
self.enable_group = banlist.enable_group
config = pkg.utils.context.get_config() config = pkg.utils.context.get_config()
if os.path.exists("sensitive.json") \ if os.path.exists("sensitive.json") \
and config.sensitive_word_filter is not None \ and config.sensitive_word_filter is not None \
@ -269,7 +277,9 @@ class QQBotManager:
import config import config
reply = '' reply = ''
if event.sender.id == self.bot_account_id: if not self.enable_private:
logging.debug("已在banlist.py中禁用所有私聊")
elif event.sender.id == self.bot_account_id:
pass pass
else: else:
if Image in event.message_chain: if Image in event.message_chain:
@ -342,8 +352,10 @@ class QQBotManager:
replys = [tips_custom.replys_message] replys = [tips_custom.replys_message]
return replys return replys
if Image in event.message_chain: if not self.enable_group:
logging.debug("已在banlist.py中禁用所有群聊")
elif Image in event.message_chain:
pass pass
else: else:
if At(self.bot_account_id) in event.message_chain and response_at(event.group.id): if At(self.bot_account_id) in event.message_chain and response_at(event.group.id):

View File

@ -1,3 +1,13 @@
# 是否处理群聊消息
# 为False时忽略所有群聊消息
# 优先级高于下方禁用列表
enable_group = True
# 是否处理私聊消息
# 为False时忽略所有私聊消息
# 优先级高于下方禁用列表
enable_private = True
# 是否启用禁用列表 # 是否启用禁用列表
enable = True enable = True

View File

@ -375,4 +375,5 @@ prompt_submit_length = <模型单次请求token数上限> - 情景预设中token
### 加入黑名单 ### 加入黑名单
编辑`banlist.py`,设置`enable = True`,并在其中的`person`或`group`列表中加入要封禁的人或群聊,修改完成后重启程序或进行热重载 - 支持禁用所有`私聊`或`群聊`,请查看`banlist.py`中的`enable_private`和`enable_group`字段
- 编辑`banlist.py`,设置`enable = True`,并在其中的`person`或`group`列表中加入要封禁的人或群聊,修改完成后重启程序或进行热重载