fix:修复发送api打字时间,现已成为可选参数。修复可能存在的回复图片问题,为数据库缺失字段提供警告
This commit is contained in:
@@ -107,6 +107,7 @@ class MessageRecv(Message):
|
||||
self.processed_plain_text = message_dict.get("processed_plain_text", "")
|
||||
self.detailed_plain_text = message_dict.get("detailed_plain_text", "")
|
||||
self.is_emoji = False
|
||||
self.is_picid = False
|
||||
|
||||
def update_chat_stream(self, chat_stream: "ChatStream"):
|
||||
self.chat_stream = chat_stream
|
||||
@@ -134,6 +135,7 @@ class MessageRecv(Message):
|
||||
elif segment.type == "image":
|
||||
# 如果是base64图片数据
|
||||
if isinstance(segment.data, str):
|
||||
self.is_picid = True
|
||||
image_manager = get_image_manager()
|
||||
# print(f"segment.data: {segment.data}")
|
||||
_, processed_text = await image_manager.process_image(segment.data)
|
||||
|
||||
@@ -199,11 +199,11 @@ class NormalChat:
|
||||
# 使用信号量控制并发数,最多同时处理5个消息
|
||||
semaphore = asyncio.Semaphore(5)
|
||||
|
||||
async def limited_process(task):
|
||||
async with semaphore:
|
||||
async def limited_process(task, sem):
|
||||
async with sem:
|
||||
await task
|
||||
|
||||
limited_tasks = [limited_process(task) for task in tasks]
|
||||
limited_tasks = [limited_process(task, semaphore) for task in tasks]
|
||||
await asyncio.gather(*limited_tasks, return_exceptions=True)
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"[{self.stream_name}] 兴趣监控任务被取消")
|
||||
|
||||
@@ -40,6 +40,11 @@ class ClassicalWillingManager(BaseWillingManager):
|
||||
else:
|
||||
is_emoji_not_reply = True
|
||||
|
||||
# 处理picid格式消息,直接不回复
|
||||
is_picid_not_reply = False
|
||||
if willing_info.is_picid:
|
||||
is_picid_not_reply = True
|
||||
|
||||
self.chat_reply_willing[chat_id] = min(current_willing, 3.0)
|
||||
|
||||
reply_probability = min(max((current_willing - 0.5), 0.01) * 2, 1)
|
||||
@@ -54,6 +59,9 @@ class ClassicalWillingManager(BaseWillingManager):
|
||||
if is_emoji_not_reply:
|
||||
reply_probability = 0
|
||||
|
||||
if is_picid_not_reply:
|
||||
reply_probability = 0
|
||||
|
||||
return reply_probability
|
||||
|
||||
async def before_generate_reply_handle(self, message_id):
|
||||
|
||||
@@ -180,6 +180,9 @@ class MxpWillingManager(BaseWillingManager):
|
||||
if w_info.is_emoji:
|
||||
probability *= global_config.normal_chat.emoji_response_penalty
|
||||
|
||||
if w_info.is_picid:
|
||||
probability = 0 # picid格式消息直接不回复
|
||||
|
||||
if w_info.group_info and w_info.group_info.group_id in global_config.normal_chat.talk_frequency_down_groups:
|
||||
probability /= global_config.normal_chat.down_frequency_rate
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ class WillingInfo:
|
||||
group_info: Optional[GroupInfo]
|
||||
is_mentioned_bot: bool
|
||||
is_emoji: bool
|
||||
is_picid: bool
|
||||
interested_rate: float
|
||||
# current_mood: float 当前心情?
|
||||
|
||||
@@ -102,6 +103,7 @@ class BaseWillingManager(ABC):
|
||||
group_info=chat.group_info,
|
||||
is_mentioned_bot=is_mentioned_bot,
|
||||
is_emoji=message.is_emoji,
|
||||
is_picid=message.is_picid,
|
||||
interested_rate=interested_rate,
|
||||
)
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class Images(BaseModel):
|
||||
emoji_hash = TextField(index=True) # 图像的哈希值
|
||||
description = TextField(null=True) # 图像的描述
|
||||
path = TextField(unique=True) # 图像文件的路径
|
||||
base64 = TextField(null=True) # 图片的base64编码(可选)
|
||||
# base64 = TextField() # 图片的base64编码
|
||||
count = IntegerField(default=1) # 图片被引用的次数
|
||||
timestamp = FloatField() # 时间戳
|
||||
type = TextField() # 图像类型,例如 "emoji"
|
||||
@@ -401,6 +401,10 @@ def initialize_database():
|
||||
model_fields = set(model._meta.fields.keys())
|
||||
|
||||
# 检查并添加缺失字段(原有逻辑)
|
||||
missing_fields = model_fields - existing_columns
|
||||
if missing_fields:
|
||||
logger.warning(f"表 '{table_name}' 缺失字段: {missing_fields}")
|
||||
|
||||
for field_name, field_obj in model._meta.fields.items():
|
||||
if field_name not in existing_columns:
|
||||
logger.info(f"表 '{table_name}' 缺失字段 '{field_name}',正在添加...")
|
||||
@@ -427,11 +431,16 @@ def initialize_database():
|
||||
alter_sql += f" DEFAULT {int(default_value)}"
|
||||
else:
|
||||
alter_sql += f" DEFAULT {default_value}"
|
||||
try:
|
||||
db.execute_sql(alter_sql)
|
||||
logger.info(f"字段 '{field_name}' 添加成功")
|
||||
except Exception as e:
|
||||
logger.error(f"添加字段 '{field_name}' 失败: {e}")
|
||||
|
||||
# 检查并删除多余字段(新增逻辑)
|
||||
extra_fields = existing_columns - model_fields
|
||||
if extra_fields:
|
||||
logger.warning(f"表 '{table_name}' 存在多余字段: {extra_fields}")
|
||||
for field_name in extra_fields:
|
||||
try:
|
||||
logger.warning(f"表 '{table_name}' 存在多余字段 '{field_name}',正在尝试删除...")
|
||||
|
||||
@@ -31,6 +31,7 @@ class MessageAPI:
|
||||
target_id: str,
|
||||
is_group: bool = True,
|
||||
display_message: str = "",
|
||||
typing: bool = False,
|
||||
) -> bool:
|
||||
"""直接向指定目标发送消息
|
||||
|
||||
@@ -113,7 +114,7 @@ class MessageAPI:
|
||||
)
|
||||
|
||||
# 发送消息
|
||||
sent_msg = await heart_fc_sender.send_message(bot_message, has_thinking=True, typing=False, set_reply=False)
|
||||
sent_msg = await heart_fc_sender.send_message(bot_message, has_thinking=False, typing=typing, set_reply=False)
|
||||
|
||||
if sent_msg:
|
||||
logger.info(f"{getattr(self, 'log_prefix', '')} 成功发送消息到 {platform}:{target_id}")
|
||||
|
||||
@@ -137,7 +137,7 @@ class BaseAction(ABC):
|
||||
text=content, user_id=str(chat_stream.user_info.user_id), platform=chat_stream.platform
|
||||
)
|
||||
|
||||
async def send_type(self, type: str, text: str) -> bool:
|
||||
async def send_type(self, type: str, text: str, typing: bool = False) -> bool:
|
||||
"""发送回复消息
|
||||
|
||||
Args:
|
||||
@@ -159,6 +159,7 @@ class BaseAction(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.group_info.group_id),
|
||||
is_group=True,
|
||||
typing=typing,
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
@@ -168,6 +169,7 @@ class BaseAction(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.user_info.user_id),
|
||||
is_group=False,
|
||||
typing=typing,
|
||||
)
|
||||
|
||||
async def send_command(self, command_name: str, args: dict = None, display_message: str = None) -> bool:
|
||||
|
||||
@@ -80,7 +80,7 @@ class BaseCommand(ABC):
|
||||
text=content, user_id=str(chat_stream.user_info.user_id), platform=chat_stream.platform
|
||||
)
|
||||
|
||||
async def send_type(self, message_type: str, content: str, display_message: str = None) -> bool:
|
||||
async def send_type(self, message_type: str, content: str, display_message: str = None, typing: bool = False) -> bool:
|
||||
"""发送指定类型的回复消息到当前聊天环境
|
||||
|
||||
Args:
|
||||
@@ -103,6 +103,7 @@ class BaseCommand(ABC):
|
||||
target_id=str(chat_stream.group_info.group_id),
|
||||
is_group=True,
|
||||
display_message=display_message,
|
||||
typing=typing,
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
|
||||
Reference in New Issue
Block a user