2023-02-07 01:35:05 +00:00
|
|
|
|
import re
|
2023-02-07 06:37:14 +00:00
|
|
|
|
import ujson as json
|
2023-02-07 01:35:05 +00:00
|
|
|
|
from core.builtins import Bot
|
|
|
|
|
from core.component import on_command
|
2023-02-07 05:27:25 +00:00
|
|
|
|
from core.logger import Logger
|
2023-02-07 06:37:14 +00:00
|
|
|
|
from core.utils.http import post_url
|
2023-02-07 01:35:05 +00:00
|
|
|
|
|
2023-02-07 06:37:14 +00:00
|
|
|
|
s = on_command('summary', developers=['Dianliang233'], desc='生成聊天记录摘要', available_for=['QQ|Group'])
|
2023-02-07 01:35:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@s.handle()
|
|
|
|
|
async def _(msg: Bot.MessageSession):
|
2023-02-07 06:37:14 +00:00
|
|
|
|
f_msg = await msg.waitNextMessage('请发送要生成摘要的合并转发消息。', append_instruction=False)
|
2023-02-07 05:27:25 +00:00
|
|
|
|
f = re.search(r'\[Ke:forward,id=(.*?)\]', f_msg.asDisplay()).group(1)
|
2023-02-07 06:37:14 +00:00
|
|
|
|
if not f:
|
|
|
|
|
await msg.finish('未检测到合并转发消息。')
|
|
|
|
|
return
|
2023-02-07 05:27:25 +00:00
|
|
|
|
Logger.info(f)
|
|
|
|
|
data = await f_msg.call_api('get_forward_msg', message_id=f)
|
|
|
|
|
msgs = data['messages']
|
2023-02-07 01:51:40 +00:00
|
|
|
|
text = ''
|
2023-02-07 01:35:05 +00:00
|
|
|
|
for m in msgs:
|
2023-02-07 01:51:40 +00:00
|
|
|
|
text += f'\n{m["sender"]["nickname"]}(ID:{m["sender"]["user_id"]},Unix时间:{m["time"]}):{m["content"]}'
|
2023-02-07 06:37:14 +00:00
|
|
|
|
msg.sendMessage(f'正在生成摘要。您的聊天记录共 {len(text)} 个字符,大约需要 {round(len(text) / 33.5, 1)} 秒请稍候……')
|
|
|
|
|
res = await post_url('https://chat-simplifier.imzbb.cc/api/generate', data=json.dumps({'promt': f'''把以下聊天记录概括为一段完整的纪要。当遇到!!!CHATENDS时,聊天记录结束,请在下方续写其摘要:
|
|
|
|
|
|
|
|
|
|
{text}
|
|
|
|
|
!!!CHATENDS'''}), headers={'Content-Type': 'application/json'})
|
|
|
|
|
await msg.finish(res.removesuffix('<|im_end|>'), disable_secret_check=True)
|