新增关键词屏蔽

This commit is contained in:
2979302435 2022-08-05 01:24:50 +08:00
parent 3a552e3ee6
commit a6766f5b29
3 changed files with 91 additions and 4 deletions

View File

@ -330,7 +330,7 @@ upLearning = on_message(
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
upLearning.__paimon_help__ = {
"usage": "@派蒙 <派蒙快学>",
"usage": "@派蒙 <多说点话>",
"introduce": "增强派蒙的学习能力",
"priority": 98
}
@ -355,7 +355,7 @@ downLearning = on_message(
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
downLearning.__paimon_help__ = {
"usage": "@派蒙 <派蒙变笨>",
"usage": "@派蒙 <笨比派蒙>",
"introduce": "降低派蒙的学习能力",
"priority": 99
}
@ -370,3 +370,81 @@ async def _(bot: Bot, event: GroupMessageEvent):
Chat.speak_threshold += 1
Chat.answer_threshold = Chat.speak_threshold
await downLearning.finish("知道了知道了,旅行者就是嫌派蒙吵了")
add_ban_word = on_message(
rule=to_me() & Rule(checkGroup) & keyword('添加禁用词', '不准说'),
priority=4,
block=True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
add_ban_word.__paimon_help__ = {
"usage": "@派蒙 <不准说> (关键词)",
"introduce": "禁用某些不想让派蒙说的关键词, 括号(英语)内部为关键词内容",
"priority": 99
}
@add_ban_word.handle()
async def _(bot: Bot, event: GroupMessageEvent):
msg = str(event.message)
msg = re.findall(re.compile(r"[(](.*)[)]", re.S), msg)
if msg:
msg = str(msg[0])
if '&#91;' in msg:
msg = msg.replace('&#91;', '[')
if '&#93;' in msg:
msg = msg.replace('&#93;', ']')
Chat.chat_word_ban.append(msg)
await add_ban_word.finish('派蒙不会说这个词了')
else:
await add_ban_word.finish('那你倒是告诉派蒙什么不能说啊😡😡😡')
del_ban_word = on_message(
rule=to_me() & Rule(checkGroup) & keyword('删除禁用词', '可以说'),
priority=4,
block=True,
permission = permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
del_ban_word.__paimon_help__ = {
"usage": "@派蒙 <可以说> (关键词)",
"introduce": "让派蒙可以说某些关键词, 括号(英语)内部为关键词内容",
"priority": 99
}
@del_ban_word.handle()
async def _(bot: Bot, event: GroupMessageEvent):
msg = str(event.message)
msg = re.findall(re.compile(r"[(](.*)[)]", re.S), msg)
if msg:
msg = str(msg[0])
if '&#91;' in msg:
msg = msg.replace('&#91;', '[')
if '&#93;' in msg:
msg = msg.replace('&#93;', ']')
answer = '怎么又允许派蒙说了捏?'
try:
Chat.chat_word_ban.remove(msg)
except:
answer = '没有ban这个词, 不要耍我'
await del_ban_word.finish(answer)
else:
await del_ban_word.finish('可以说你是🤡吗')
check_ban_word = on_message(
rule=to_me() & Rule(checkGroup) & keyword('查看禁用词', '哪些不准说'),
priority=4,
block=True,
permission = permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
check_ban_word.__paimon_help__ = {
"usage": "@派蒙 <查看禁用词>",
"introduce": "查看当前的禁用词内容",
"priority": 99
}
@check_ban_word.handle()
async def _(bot: Bot, event: GroupMessageEvent):
msg = '当前的违禁词: '
if Chat.chat_word_ban:
for word in Chat.chat_word_ban:
msg += str(word) + ' | '
await check_ban_word.finish(msg)
else:
await check_ban_word.finish('当前还没有违禁词哦')

View File

@ -105,6 +105,8 @@ class Chat:
learningGroup = config.paimon_chat_group# 机器学习群组
chat_word_ban = config.paimon_chat_word_ban# 禁用关键词
def __init__(self, data: Union[ChatData, GroupMessageEvent, PrivateMessageEvent]):
if isinstance(data, ChatData):
@ -180,7 +182,7 @@ class Chat:
# # 不回复太短的对话,大部分是“?”、“草”
# if self.chat_data.is_plain_text and len(self.chat_data.plain_text) < 2:
# return None
if len(group_bot_replies):
latest_reply = group_bot_replies[-1]
# 限制发音频率,最多 6 秒一次
@ -196,6 +198,10 @@ class Chat:
results = self._context_find()
if results:
# 判断是否有被禁用的关键词
for word in self.chat_word_ban:
if word in results[0][0]:
return None
raw_message = self.chat_data.raw_message
keywords = self.chat_data.keywords
with Chat._reply_lock:

View File

@ -65,7 +65,10 @@ class PluginConfig(BaseModel):
paimon_speak_poke_probability: float = 0.5
# 连续主动说话最多几句话
paimon_speak_continuously_max_len: int = 3
# 禁用词 (如果需要禁用@某人的话格式为 '[CQ:at,qq=(这个人的QQ号)]'
# 如: paimon_chat_word_ban: List[str] = ['[CQ:at,qq=12345678]'])
# 如需禁用全部的@可以填写为 '[CQ:at' , 'at' 等等
paimon_chat_word_ban: List[str] = []
# 派蒙收到好友申请或群邀请时是否向超级管理员发通知
paimon_request_remind: bool = True
# 是否自动通过好友请求