refactor: Clean up unused variables and improve code readability

This commit is contained in:
晴猫
2025-05-01 07:24:52 +09:00
parent e4959f0386
commit 45c64208b4
13 changed files with 9 additions and 29 deletions

2
bot.py
View File

@@ -130,9 +130,7 @@ def check_eula():
privacy_file = Path("PRIVACY.md") privacy_file = Path("PRIVACY.md")
eula_updated = True eula_updated = True
eula_new_hash = None
privacy_updated = True privacy_updated = True
privacy_new_hash = None
eula_confirmed = False eula_confirmed = False
privacy_confirmed = False privacy_confirmed = False

View File

@@ -76,7 +76,7 @@ def process_single_text(pg_hash, raw_data, llm_client_list):
return doc_item, None return doc_item, None
def signal_handler(signum, frame): def signal_handler(_signum, _frame):
"""处理Ctrl+C信号""" """处理Ctrl+C信号"""
logger.info("\n接收到中断信号,正在优雅地关闭程序...") logger.info("\n接收到中断信号,正在优雅地关闭程序...")
shutdown_event.set() shutdown_event.set()

View File

@@ -26,7 +26,6 @@ def find_messages(
""" """
try: try:
query = db.messages.find(message_filter) query = db.messages.find(message_filter)
results: List[dict[str, Any]] = []
if limit > 0: if limit > 0:
if limit_mode == "earliest": if limit_mode == "earliest":

View File

@@ -113,7 +113,6 @@ class Individuality:
p_pronoun = "" p_pronoun = ""
prompt_personality = f"{p_pronoun}{self.personality.personality_core}" prompt_personality = f"{p_pronoun}{self.personality.personality_core}"
else: # x_person == 0 else: # x_person == 0
p_pronoun = "" # 无人称
# 对于无人称,直接描述核心特征 # 对于无人称,直接描述核心特征
prompt_personality = f"{self.personality.personality_core}" prompt_personality = f"{self.personality.personality_core}"

View File

@@ -262,7 +262,6 @@ class ActionPlanner:
# --- 知识信息字符串构建结束 --- # --- 知识信息字符串构建结束 ---
# 获取聊天历史记录 (chat_history_text) # 获取聊天历史记录 (chat_history_text)
chat_history_text = ""
try: try:
if hasattr(observation_info, "chat_history") and observation_info.chat_history: if hasattr(observation_info, "chat_history") and observation_info.chat_history:
chat_history_text = observation_info.chat_history_str chat_history_text = observation_info.chat_history_str

View File

@@ -123,11 +123,7 @@ class ChatObserver:
self.last_cold_chat_check = current_time self.last_cold_chat_check = current_time
# 判断是否冷场 # 判断是否冷场
is_cold = False is_cold = True if self.last_message_time is None else (current_time - self.last_message_time) > self.cold_chat_threshold
if self.last_message_time is None:
is_cold = True
else:
is_cold = (current_time - self.last_message_time) > self.cold_chat_threshold
# 如果冷场状态发生变化,发送通知 # 如果冷场状态发生变化,发送通知
if is_cold != self.is_cold_chat_state: if is_cold != self.is_cold_chat_state:

View File

@@ -156,7 +156,7 @@ async def get_recent_group_messages(chat_id: str, limit: int = 12) -> list:
return message_objects 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( recent_messages = list(
db.messages.find( db.messages.find(
{"chat_id": chat_stream_id}, {"chat_id": chat_stream_id},

View File

@@ -50,8 +50,6 @@ class MaiEmoji:
async def initialize_hash_format(self): async def initialize_hash_format(self):
"""从文件创建表情包实例, 计算哈希值和格式""" """从文件创建表情包实例, 计算哈希值和格式"""
image_base64 = None
image_bytes = None
try: try:
# 使用 full_path 检查文件是否存在 # 使用 full_path 检查文件是否存在
if not os.path.exists(self.full_path): if not os.path.exists(self.full_path):

View File

@@ -174,7 +174,7 @@ class HeartFChatting:
self, self,
chat_id: str, chat_id: str,
sub_mind: SubMind, sub_mind: SubMind,
observations: Observation, observations: list[Observation],
on_consecutive_no_reply_callback: Callable[[], Coroutine[None, None, None]], 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 observation = self.observations[0] if self.observations else None
try: try:
dang_qian_deng_dai = 0.0 # 初始化本次等待时间
with Timer("等待新消息", cycle_timers): with Timer("等待新消息", cycle_timers):
# 等待新消息、超时或关闭信号,并获取结果 # 等待新消息、超时或关闭信号,并获取结果
await self._wait_for_new_message(observation, planner_start_db_time, self.log_prefix) 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: if not self._shutting_down:
self._lian_xu_bu_hui_fu_ci_shu += 1 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( logger.debug(
f"{self.log_prefix} 连续不回复计数增加: {self._lian_xu_bu_hui_fu_ci_shu}/{CONSECUTIVE_NO_REPLY_THRESHOLD}, " 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}"
) )
# 检查是否同时达到次数和时间阈值 # 检查是否同时达到次数和时间阈值

View File

@@ -364,7 +364,6 @@ class Hippocampus:
logger.debug(f"有效的关键词: {', '.join(valid_keywords)}") logger.debug(f"有效的关键词: {', '.join(valid_keywords)}")
# 从每个关键词获取记忆 # 从每个关键词获取记忆
all_memories = []
activate_map = {} # 存储每个词的累计激活值 activate_map = {} # 存储每个词的累计激活值
# 对每个关键词进行扩散式检索 # 对每个关键词进行扩散式检索
@@ -536,7 +535,6 @@ class Hippocampus:
logger.debug(f"有效的关键词: {', '.join(valid_keywords)}") logger.debug(f"有效的关键词: {', '.join(valid_keywords)}")
# 从每个关键词获取记忆 # 从每个关键词获取记忆
all_memories = []
activate_map = {} # 存储每个词的累计激活值 activate_map = {} # 存储每个词的累计激活值
# 对每个关键词进行扩散式检索 # 对每个关键词进行扩散式检索

View File

@@ -137,7 +137,6 @@ class PersonInfoManager:
@staticmethod @staticmethod
def _extract_json_from_text(text: str) -> dict: def _extract_json_from_text(text: str) -> dict:
"""从文本中提取JSON数据的高容错方法""" """从文本中提取JSON数据的高容错方法"""
parsed_json = None
try: try:
# 尝试直接解析 # 尝试直接解析
parsed_json = json.loads(text) parsed_json = json.loads(text)

View File

@@ -50,7 +50,6 @@ class DynamicWillingManager(BaseWillingManager):
is_high_mode = self.chat_high_willing_mode.get(chat_id, False) is_high_mode = self.chat_high_willing_mode.get(chat_id, False)
# 获取当前模式的持续时间 # 获取当前模式的持续时间
duration = 0
if is_high_mode: if is_high_mode:
duration = self.chat_high_willing_duration.get(chat_id, 180) # 默认3分钟 duration = self.chat_high_willing_duration.get(chat_id, 180) # 默认3分钟
else: else:
@@ -154,8 +153,6 @@ class DynamicWillingManager(BaseWillingManager):
) )
# 根据当前模式计算回复概率 # 根据当前模式计算回复概率
base_probability = 0.0
if in_conversation_context: if in_conversation_context:
# 在对话上下文中,降低基础回复概率 # 在对话上下文中,降低基础回复概率
base_probability = 0.5 if is_high_mode else 0.25 base_probability = 0.5 if is_high_mode else 0.25

View File

@@ -76,10 +76,8 @@ class LlmcheckWillingManager(MxpWillingManager):
current_date = time.strftime("%Y-%m-%d", time.localtime()) current_date = time.strftime("%Y-%m-%d", time.localtime())
current_time = time.strftime("%H:%M:%S", time.localtime()) current_time = time.strftime("%H:%M:%S", time.localtime())
chat_talking_prompt = "" chat_talking_prompt = get_recent_group_detailed_plain_text(chat_id, limit=length, combine=True)
if chat_id: if not chat_id:
chat_talking_prompt = get_recent_group_detailed_plain_text(chat_id, limit=length, combine=True)
else:
return 0 return 0
# if is_mentioned_bot: # if is_mentioned_bot: