mirror of https://github.com/Mai-with-u/MaiBot.git
fix: 修复 question_maker 中 UnboundLocalError 的问题
- 在 get_random_unanswered_conflict() 方法中新增 else 分支 - 当所有冲突 raise_time >= 1 时,按 5% 概率随机选择 - 避免 chosen_conflict 未赋值导致的 UnboundLocalError 异常pull/1294/head
parent
d5f17b1f89
commit
ac41ca89a7
|
|
@ -70,11 +70,15 @@ class QuestionMaker:
|
|||
|
||||
# 按权重随机选择
|
||||
chosen_conflict = random.choices(conflicts, weights=weights, k=1)[0]
|
||||
else:
|
||||
# 所有冲突都已被提问过(raise_time ≥ 1),仅 5% 概率返回
|
||||
if random.random() > 0.05:
|
||||
return None
|
||||
chosen_conflict = random.choice(conflicts)
|
||||
|
||||
# 选中后,自增 raise_time 并保存
|
||||
chosen_conflict.raise_time = (getattr(chosen_conflict, "raise_time", 0) or 0) + 1
|
||||
chosen_conflict.save()
|
||||
|
||||
chosen_conflict.raise_time = (getattr(chosen_conflict, "raise_time", 0) or 0) + 1
|
||||
chosen_conflict.save()
|
||||
|
||||
return chosen_conflict
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue