Merge branch 'refractor' of https://github.com/tcmofashi/MaiMBot into refractor
This commit is contained in:
@@ -11,18 +11,25 @@ from .cq_code import CQCode,cq_code_tool # 导入CQCode模块
|
||||
from .emoji_manager import emoji_manager # 导入表情包管理器
|
||||
from .llm_generator import ResponseGenerator
|
||||
from .message import MessageSending, MessageRecv, MessageThinking, MessageSet
|
||||
from .message import MessageSending, MessageRecv, MessageThinking, MessageSet
|
||||
from .message_cq import (
|
||||
MessageRecvCQ,
|
||||
MessageSendCQ,
|
||||
)
|
||||
from .chat_stream import chat_manager
|
||||
MessageRecvCQ,
|
||||
MessageSendCQ,
|
||||
)
|
||||
from .chat_stream import chat_manager
|
||||
from .message_sender import message_manager # 导入新的消息管理器
|
||||
from .relationship_manager import relationship_manager
|
||||
from .storage import MessageStorage
|
||||
from .utils import calculate_typing_time, is_mentioned_bot_in_txt
|
||||
from .utils_image import image_path_to_base64
|
||||
from .utils_image import image_path_to_base64
|
||||
from .willing_manager import willing_manager # 导入意愿管理器
|
||||
from .message_base import UserInfo, GroupInfo, Seg
|
||||
from .message_base import UserInfo, GroupInfo, Seg
|
||||
|
||||
class ChatBot:
|
||||
def __init__(self):
|
||||
@@ -47,6 +54,7 @@ class ChatBot:
|
||||
self.bot = bot # 更新 bot 实例
|
||||
|
||||
|
||||
|
||||
|
||||
group_info = await bot.get_group_info(group_id=event.group_id)
|
||||
sender_info = await bot.get_group_member_info(group_id=event.group_id, user_id=event.user_id, no_cache=True)
|
||||
@@ -54,11 +62,15 @@ class ChatBot:
|
||||
await relationship_manager.update_relationship(user_id = event.user_id, data = sender_info)
|
||||
await relationship_manager.update_relationship_value(user_id = event.user_id, relationship_value = 0.5)
|
||||
|
||||
message_cq=MessageRecvCQ(
|
||||
message_cq=MessageRecvCQ(
|
||||
message_id=event.message_id,
|
||||
user_id=event.user_id,
|
||||
raw_message=str(event.original_message),
|
||||
group_id=event.group_id,
|
||||
user_id=event.user_id,
|
||||
raw_message=str(event.original_message),
|
||||
group_id=event.group_id,
|
||||
reply_message=event.reply,
|
||||
platform='qq'
|
||||
)
|
||||
@@ -88,12 +100,15 @@ class ChatBot:
|
||||
return
|
||||
# 过滤词
|
||||
for word in global_config.ban_words:
|
||||
if word in message.processed_plain_text:
|
||||
logger.info(f"\033[1;32m[{groupinfo.group_name}]{userinfo.user_nickname}:\033[0m {message.processed_plain_text}")
|
||||
if word in message.processed_plain_text:
|
||||
logger.info(f"\033[1;32m[{groupinfo.group_name}]{userinfo.user_nickname}:\033[0m {message.processed_plain_text}")
|
||||
logger.info(f"\033[1;32m[过滤词识别]\033[0m 消息中含有{word},filtered")
|
||||
return
|
||||
|
||||
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(messageinfo.time))
|
||||
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(messageinfo.time))
|
||||
|
||||
|
||||
|
||||
@@ -124,6 +139,11 @@ class ChatBot:
|
||||
response = None
|
||||
|
||||
if random() < reply_probability:
|
||||
bot_user_info=UserInfo(
|
||||
user_id=global_config.BOT_QQ,
|
||||
user_nickname=global_config.BOT_NICKNAME,
|
||||
platform=messageinfo.platform
|
||||
)
|
||||
bot_user_info=UserInfo(
|
||||
user_id=global_config.BOT_QQ,
|
||||
user_nickname=global_config.BOT_NICKNAME,
|
||||
@@ -136,6 +156,11 @@ class ChatBot:
|
||||
message_id=think_id,
|
||||
reply=message
|
||||
)
|
||||
thinking_message = MessageThinking.from_chat_stream(
|
||||
chat_stream=chat,
|
||||
message_id=think_id,
|
||||
reply=message
|
||||
)
|
||||
|
||||
message_manager.add_message(thinking_message)
|
||||
|
||||
@@ -146,6 +171,7 @@ class ChatBot:
|
||||
response,raw_content = await self.gpt.generate_response(message)
|
||||
|
||||
if response:
|
||||
container = message_manager.get_container(chat.stream_id)
|
||||
container = message_manager.get_container(chat.stream_id)
|
||||
thinking_message = None
|
||||
# 找到message,删除
|
||||
@@ -163,6 +189,7 @@ class ChatBot:
|
||||
#记录开始思考的时间,避免从思考到回复的时间太久
|
||||
thinking_start_time = thinking_message.thinking_start_time
|
||||
message_set = MessageSet(chat, think_id)
|
||||
message_set = MessageSet(chat, think_id)
|
||||
#计算打字时间,1是为了模拟打字,2是避免多条回复乱序
|
||||
accu_typing_time = 0
|
||||
|
||||
@@ -174,6 +201,8 @@ class ChatBot:
|
||||
accu_typing_time += typing_time
|
||||
timepoint = tinking_time_point + accu_typing_time
|
||||
|
||||
message_segment = Seg(type='text', data=msg)
|
||||
bot_message = MessageSending(
|
||||
message_segment = Seg(type='text', data=msg)
|
||||
bot_message = MessageSending(
|
||||
message_id=think_id,
|
||||
@@ -182,6 +211,12 @@ class ChatBot:
|
||||
reply=message,
|
||||
is_head=not mark_head,
|
||||
is_emoji=False
|
||||
)
|
||||
chat_stream=chat,
|
||||
message_segment=message_segment,
|
||||
reply=message,
|
||||
is_head=not mark_head,
|
||||
is_emoji=False
|
||||
)
|
||||
if not mark_head:
|
||||
mark_head = True
|
||||
@@ -200,6 +235,7 @@ class ChatBot:
|
||||
if emoji_raw != None:
|
||||
emoji_path,discription = emoji_raw
|
||||
|
||||
emoji_cq = image_path_to_base64(emoji_path)
|
||||
emoji_cq = image_path_to_base64(emoji_path)
|
||||
|
||||
if random() < 0.5:
|
||||
@@ -207,6 +243,15 @@ class ChatBot:
|
||||
else:
|
||||
bot_response_time = bot_response_time + 1
|
||||
|
||||
message_segment = Seg(type='emoji', data=emoji_cq)
|
||||
bot_message = MessageSending(
|
||||
message_id=think_id,
|
||||
chat_stream=chat,
|
||||
message_segment=message_segment,
|
||||
reply=message,
|
||||
is_head=False,
|
||||
is_emoji=True
|
||||
)
|
||||
message_segment = Seg(type='emoji', data=emoji_cq)
|
||||
bot_message = MessageSending(
|
||||
message_id=think_id,
|
||||
@@ -237,6 +282,12 @@ class ChatBot:
|
||||
user_info=userinfo,
|
||||
group_info=groupinfo
|
||||
)
|
||||
|
||||
willing_manager.change_reply_willing_after_sent(
|
||||
platform=messageinfo.platform,
|
||||
user_info=userinfo,
|
||||
group_info=groupinfo
|
||||
)
|
||||
|
||||
# 创建全局ChatBot实例
|
||||
chat_bot = ChatBot()
|
||||
Reference in New Issue
Block a user