From adbfe9436a580dfe9f1bf8f70f81147c43b908d1 Mon Sep 17 00:00:00 2001
From: CMHopeSunshine <277073121@qq.com>
Date: Sat, 14 Jan 2023 23:51:51 +0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20`=E7=BE=A4=E8=81=8A=E5=AD=A6?=
=?UTF-8?q?=E4=B9=A0`=E4=BF=AE=E5=A4=8D=E8=BF=9E=E7=BB=AD=E4=B8=BB?=
=?UTF-8?q?=E5=8A=A8=E5=8F=91=E8=A8=80=E6=A6=82=E7=8E=87=E5=A4=B1=E6=95=88?=
=?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=BB=B6=E9=95=BF=E4=B8=BB?=
=?UTF-8?q?=E5=8A=A8=E5=8F=91=E8=A8=80=E5=88=A4=E6=96=AD=E9=97=B4=E9=9A=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../plugins/Learning_Chat/__init__.py | 2 +-
LittlePaimon/plugins/Learning_Chat/handler.py | 80 ++++++++++---------
2 files changed, 43 insertions(+), 39 deletions(-)
diff --git a/LittlePaimon/plugins/Learning_Chat/__init__.py b/LittlePaimon/plugins/Learning_Chat/__init__.py
index 163b73c..2ff2059 100644
--- a/LittlePaimon/plugins/Learning_Chat/__init__.py
+++ b/LittlePaimon/plugins/Learning_Chat/__init__.py
@@ -60,7 +60,7 @@ async def _(event: GroupMessageEvent, answers=Arg('answers')):
logger.info('群聊学习', f'{NICKNAME}向群{event.group_id}的回复"{answer}"发送失败,可能处于风控中')
-@scheduler.scheduled_job('interval', minutes=1, misfire_grace_time=5)
+@scheduler.scheduled_job('interval', minutes=3, misfire_grace_time=5)
async def speak_up():
if not config_manager.config.total_enable:
return
diff --git a/LittlePaimon/plugins/Learning_Chat/handler.py b/LittlePaimon/plugins/Learning_Chat/handler.py
index 5a7ee4b..b8c57a2 100644
--- a/LittlePaimon/plugins/Learning_Chat/handler.py
+++ b/LittlePaimon/plugins/Learning_Chat/handler.py
@@ -389,7 +389,8 @@ class LearningChat:
# 如果最后一条消息是自己发的,则不主动发言
if last_reply := await ChatMessage.filter(group_id=group_id, user_id=self_id).first():
if last_reply.time >= messages[0].time:
- logger.debug('群聊学习', f'主动发言:群{group_id}最后一条消息是{NICKNAME}发的{last_reply.message},不发言')
+ logger.debug('群聊学习',
+ f'主动发言:群{group_id}最后一条消息是{NICKNAME}发的{last_reply.message},不发言')
continue
elif cur_time - last_reply.time < config.speak_min_interval:
logger.debug('群聊学习', f'主动发言:群{group_id}上次主动发言时间小于主动发言最小间隔,不发言')
@@ -401,7 +402,8 @@ class LearningChat:
silent_time = cur_time - messages[0].time
threshold = avg_interval * config.speak_threshold
if silent_time < threshold:
- logger.debug('群聊学习', f'主动发言:群{group_id}已沉默时间({silent_time})小于阈值({int(threshold)}),不发言')
+ logger.debug('群聊学习',
+ f'主动发言:群{group_id}已沉默时间({silent_time})小于阈值({int(threshold)}),不发言')
continue
if contexts := await ChatContext.filter(count__gte=config.answer_threshold).all():
@@ -411,42 +413,44 @@ class LearningChat:
random.shuffle(contexts)
for context in contexts:
if (not speak_list or random.random() < config.speak_continuously_probability) and len(
- speak_list) < config.speak_continuously_max_len and (
- answers := await ChatAnswer.filter(context=context,
- group_id=group_id,
- count__gte=config.answer_threshold)):
- answer = random.choices(answers,
- weights=[answer.count + 1 if answer.time >= today_time else answer.count
- for answer in answers])[0]
- message = random.choice(answer.messages)
- if len(message) < 2:
- continue
- if message.startswith('[') and message.endswith(']'):
- continue
- if any(word in message for word in ban_words):
- continue
- speak_list.append(message)
- follow_answers = answer
- while random.random() < config.speak_continuously_probability and len(
- speak_list) < config.speak_continuously_max_len:
- if (follow_context := await ChatContext.filter(keywords=follow_answers.keywords).first()) and (
- follow_answers := await ChatAnswer.filter(
- group_id=group_id,
- context=follow_context,
- count__gte=config.answer_threshold)):
- answer = random.choices(follow_answers,
- weights=[a.count + 1 if a.time >= today_time else a.count
- for a in follow_answers])[0]
- message = random.choice(answer.messages)
- if len(message) < 2:
- continue
- if message.startswith('[') and message.endswith(']'):
- continue
- if all(word not in message for word in ban_words):
- speak_list.append(message)
- else:
- break
- elif len(speak_list) >= config.speak_continuously_max_len:
+ speak_list) < config.speak_continuously_max_len:
+ if answers := await ChatAnswer.filter(context=context,
+ group_id=group_id,
+ count__gte=config.answer_threshold):
+ answer = random.choices(answers,
+ weights=[
+ answer.count + 1 if answer.time >= today_time else answer.count
+ for answer in answers])[0]
+ message = random.choice(answer.messages)
+ if len(message) < 2:
+ continue
+ if message.startswith('[') and message.endswith(']'):
+ continue
+ if any(word in message for word in ban_words):
+ continue
+ speak_list.append(message)
+ follow_answers = answer
+ while random.random() < config.speak_continuously_probability and len(
+ speak_list) < config.speak_continuously_max_len:
+ if (follow_context := await ChatContext.filter(
+ keywords=follow_answers.keywords).first()) and (
+ follow_answers := await ChatAnswer.filter(
+ group_id=group_id,
+ context=follow_context,
+ count__gte=config.answer_threshold)):
+ answer = random.choices(follow_answers,
+ weights=[a.count + 1 if a.time >= today_time else a.count
+ for a in follow_answers])[0]
+ message = random.choice(answer.messages)
+ if len(message) < 2:
+ continue
+ if message.startswith('[') and message.endswith(']'):
+ continue
+ if all(word not in message for word in ban_words):
+ speak_list.append(message)
+ else:
+ break
+ else:
break
if speak_list:
if random.random() < config.speak_poke_probability: