mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
🐛 群聊学习
修复连续主动发言概率失效的问题,延长主动发言判断间隔
This commit is contained in:
parent
1dc87aab97
commit
adbfe9436a
@ -60,7 +60,7 @@ async def _(event: GroupMessageEvent, answers=Arg('answers')):
|
||||
logger.info('群聊学习', f'{NICKNAME}向群<m>{event.group_id}</m>的回复<m>"{answer}"</m>发送<r>失败,可能处于风控中</r>')
|
||||
|
||||
|
||||
@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
|
||||
|
@ -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'主动发言:群<m>{group_id}</m>最后一条消息是{NICKNAME}发的{last_reply.message},不发言')
|
||||
logger.debug('群聊学习',
|
||||
f'主动发言:群<m>{group_id}</m>最后一条消息是{NICKNAME}发的{last_reply.message},不发言')
|
||||
continue
|
||||
elif cur_time - last_reply.time < config.speak_min_interval:
|
||||
logger.debug('群聊学习', f'主动发言:群<m>{group_id}</m>上次主动发言时间小于主动发言最小间隔,不发言')
|
||||
@ -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'主动发言:群<m>{group_id}</m>已沉默时间({silent_time})小于阈值({int(threshold)}),不发言')
|
||||
logger.debug('群聊学习',
|
||||
f'主动发言:群<m>{group_id}</m>已沉默时间({silent_time})小于阈值({int(threshold)}),不发言')
|
||||
continue
|
||||
|
||||
if contexts := await ChatContext.filter(count__gte=config.answer_threshold).all():
|
||||
@ -411,12 +413,13 @@ 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,
|
||||
speak_list) < config.speak_continuously_max_len:
|
||||
if answers := await ChatAnswer.filter(context=context,
|
||||
group_id=group_id,
|
||||
count__gte=config.answer_threshold)):
|
||||
count__gte=config.answer_threshold):
|
||||
answer = random.choices(answers,
|
||||
weights=[answer.count + 1 if answer.time >= today_time else answer.count
|
||||
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:
|
||||
@ -429,7 +432,8 @@ class LearningChat:
|
||||
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 (
|
||||
if (follow_context := await ChatContext.filter(
|
||||
keywords=follow_answers.keywords).first()) and (
|
||||
follow_answers := await ChatAnswer.filter(
|
||||
group_id=group_id,
|
||||
context=follow_context,
|
||||
@ -446,7 +450,7 @@ class LearningChat:
|
||||
speak_list.append(message)
|
||||
else:
|
||||
break
|
||||
elif len(speak_list) >= config.speak_continuously_max_len:
|
||||
else:
|
||||
break
|
||||
if speak_list:
|
||||
if random.random() < config.speak_poke_probability:
|
||||
|
Loading…
Reference in New Issue
Block a user