refactor: Clean up unused variables and improve code readability
This commit is contained in:
2
bot.py
2
bot.py
@@ -130,9 +130,7 @@ def check_eula():
|
||||
privacy_file = Path("PRIVACY.md")
|
||||
|
||||
eula_updated = True
|
||||
eula_new_hash = None
|
||||
privacy_updated = True
|
||||
privacy_new_hash = None
|
||||
|
||||
eula_confirmed = False
|
||||
privacy_confirmed = False
|
||||
|
||||
@@ -76,7 +76,7 @@ def process_single_text(pg_hash, raw_data, llm_client_list):
|
||||
return doc_item, None
|
||||
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
def signal_handler(_signum, _frame):
|
||||
"""处理Ctrl+C信号"""
|
||||
logger.info("\n接收到中断信号,正在优雅地关闭程序...")
|
||||
shutdown_event.set()
|
||||
|
||||
@@ -26,7 +26,6 @@ def find_messages(
|
||||
"""
|
||||
try:
|
||||
query = db.messages.find(message_filter)
|
||||
results: List[dict[str, Any]] = []
|
||||
|
||||
if limit > 0:
|
||||
if limit_mode == "earliest":
|
||||
|
||||
@@ -113,7 +113,6 @@ class Individuality:
|
||||
p_pronoun = "我"
|
||||
prompt_personality = f"{p_pronoun}{self.personality.personality_core}"
|
||||
else: # x_person == 0
|
||||
p_pronoun = "" # 无人称
|
||||
# 对于无人称,直接描述核心特征
|
||||
prompt_personality = f"{self.personality.personality_core}"
|
||||
|
||||
|
||||
@@ -262,7 +262,6 @@ class ActionPlanner:
|
||||
# --- 知识信息字符串构建结束 ---
|
||||
|
||||
# 获取聊天历史记录 (chat_history_text)
|
||||
chat_history_text = ""
|
||||
try:
|
||||
if hasattr(observation_info, "chat_history") and observation_info.chat_history:
|
||||
chat_history_text = observation_info.chat_history_str
|
||||
|
||||
@@ -123,11 +123,7 @@ class ChatObserver:
|
||||
self.last_cold_chat_check = current_time
|
||||
|
||||
# 判断是否冷场
|
||||
is_cold = False
|
||||
if self.last_message_time is None:
|
||||
is_cold = True
|
||||
else:
|
||||
is_cold = (current_time - self.last_message_time) > self.cold_chat_threshold
|
||||
is_cold = True if self.last_message_time is None else (current_time - self.last_message_time) > self.cold_chat_threshold
|
||||
|
||||
# 如果冷场状态发生变化,发送通知
|
||||
if is_cold != self.is_cold_chat_state:
|
||||
|
||||
@@ -156,7 +156,7 @@ async def get_recent_group_messages(chat_id: str, limit: int = 12) -> list:
|
||||
return message_objects
|
||||
|
||||
|
||||
def get_recent_group_detailed_plain_text(chat_stream_id: int, limit: int = 12, combine=False):
|
||||
def get_recent_group_detailed_plain_text(chat_stream_id: str, limit: int = 12, combine=False):
|
||||
recent_messages = list(
|
||||
db.messages.find(
|
||||
{"chat_id": chat_stream_id},
|
||||
|
||||
@@ -50,8 +50,6 @@ class MaiEmoji:
|
||||
|
||||
async def initialize_hash_format(self):
|
||||
"""从文件创建表情包实例, 计算哈希值和格式"""
|
||||
image_base64 = None
|
||||
image_bytes = None
|
||||
try:
|
||||
# 使用 full_path 检查文件是否存在
|
||||
if not os.path.exists(self.full_path):
|
||||
|
||||
@@ -174,7 +174,7 @@ class HeartFChatting:
|
||||
self,
|
||||
chat_id: str,
|
||||
sub_mind: SubMind,
|
||||
observations: Observation,
|
||||
observations: list[Observation],
|
||||
on_consecutive_no_reply_callback: Callable[[], Coroutine[None, None, None]],
|
||||
):
|
||||
"""
|
||||
@@ -631,19 +631,18 @@ class HeartFChatting:
|
||||
observation = self.observations[0] if self.observations else None
|
||||
|
||||
try:
|
||||
dang_qian_deng_dai = 0.0 # 初始化本次等待时间
|
||||
with Timer("等待新消息", cycle_timers):
|
||||
# 等待新消息、超时或关闭信号,并获取结果
|
||||
await self._wait_for_new_message(observation, planner_start_db_time, self.log_prefix)
|
||||
# 从计时器获取实际等待时间
|
||||
dang_qian_deng_dai = cycle_timers.get("等待新消息", 0.0)
|
||||
current_waiting = cycle_timers.get("等待新消息", 0.0)
|
||||
|
||||
if not self._shutting_down:
|
||||
self._lian_xu_bu_hui_fu_ci_shu += 1
|
||||
self._lian_xu_deng_dai_shi_jian += dang_qian_deng_dai # 累加等待时间
|
||||
self._lian_xu_deng_dai_shi_jian += current_waiting # 累加等待时间
|
||||
logger.debug(
|
||||
f"{self.log_prefix} 连续不回复计数增加: {self._lian_xu_bu_hui_fu_ci_shu}/{CONSECUTIVE_NO_REPLY_THRESHOLD}, "
|
||||
f"本次等待: {dang_qian_deng_dai:.2f}秒, 累计等待: {self._lian_xu_deng_dai_shi_jian:.2f}秒"
|
||||
f"本次等待: {current_waiting:.2f}秒, 累计等待: {self._lian_xu_deng_dai_shi_jian:.2f}秒"
|
||||
)
|
||||
|
||||
# 检查是否同时达到次数和时间阈值
|
||||
|
||||
@@ -364,7 +364,6 @@ class Hippocampus:
|
||||
logger.debug(f"有效的关键词: {', '.join(valid_keywords)}")
|
||||
|
||||
# 从每个关键词获取记忆
|
||||
all_memories = []
|
||||
activate_map = {} # 存储每个词的累计激活值
|
||||
|
||||
# 对每个关键词进行扩散式检索
|
||||
@@ -536,7 +535,6 @@ class Hippocampus:
|
||||
logger.debug(f"有效的关键词: {', '.join(valid_keywords)}")
|
||||
|
||||
# 从每个关键词获取记忆
|
||||
all_memories = []
|
||||
activate_map = {} # 存储每个词的累计激活值
|
||||
|
||||
# 对每个关键词进行扩散式检索
|
||||
|
||||
@@ -137,7 +137,6 @@ class PersonInfoManager:
|
||||
@staticmethod
|
||||
def _extract_json_from_text(text: str) -> dict:
|
||||
"""从文本中提取JSON数据的高容错方法"""
|
||||
parsed_json = None
|
||||
try:
|
||||
# 尝试直接解析
|
||||
parsed_json = json.loads(text)
|
||||
|
||||
@@ -50,7 +50,6 @@ class DynamicWillingManager(BaseWillingManager):
|
||||
is_high_mode = self.chat_high_willing_mode.get(chat_id, False)
|
||||
|
||||
# 获取当前模式的持续时间
|
||||
duration = 0
|
||||
if is_high_mode:
|
||||
duration = self.chat_high_willing_duration.get(chat_id, 180) # 默认3分钟
|
||||
else:
|
||||
@@ -154,8 +153,6 @@ class DynamicWillingManager(BaseWillingManager):
|
||||
)
|
||||
|
||||
# 根据当前模式计算回复概率
|
||||
base_probability = 0.0
|
||||
|
||||
if in_conversation_context:
|
||||
# 在对话上下文中,降低基础回复概率
|
||||
base_probability = 0.5 if is_high_mode else 0.25
|
||||
|
||||
@@ -76,10 +76,8 @@ class LlmcheckWillingManager(MxpWillingManager):
|
||||
|
||||
current_date = time.strftime("%Y-%m-%d", time.localtime())
|
||||
current_time = time.strftime("%H:%M:%S", time.localtime())
|
||||
chat_talking_prompt = ""
|
||||
if chat_id:
|
||||
chat_talking_prompt = get_recent_group_detailed_plain_text(chat_id, limit=length, combine=True)
|
||||
else:
|
||||
if not chat_id:
|
||||
return 0
|
||||
|
||||
# if is_mentioned_bot:
|
||||
|
||||
Reference in New Issue
Block a user