From cf18fdf5324922376b6c4e6d581e7a000c86c3df Mon Sep 17 00:00:00 2001 From: mol Date: Thu, 14 Dec 2023 14:59:41 +0800 Subject: [PATCH] test --- plugins/cook/index.js | 14 ++++++++++---- plugins/cook/utils/index.js | 24 +++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/plugins/cook/index.js b/plugins/cook/index.js index e99c02e..06b5541 100644 --- a/plugins/cook/index.js +++ b/plugins/cook/index.js @@ -4,7 +4,7 @@ import { getRandomRecipe } from './api/index.js'; import { genRecipeMessage } from './utils/index.js'; import logger from '#root/utils/logger.js' -const { Middleware } = pkg; +const { Middleware, Message } = pkg; const cookCommand = command.cook; let Bot; @@ -15,12 +15,18 @@ const commandHandle = { async function randomCook(text, data) { const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5; const recipeList = await getRandomRecipe(limit); - logger(JSON.stringify(recipeList)); const message = genRecipeMessage(recipeList, '给你推荐'); - logger(message); + switch (data.type) { case 'GroupMessage': - Bot.sendMessageToGroup(data.sender.group.id, message); + const forwardMsg = Message.createForwardMessage(); + forwardMsg.addForwardNode({ + senderId: process.env.QQ, + time: 0, + senderName: '厨娘·模儿', + messageChain: message + }) + Bot.sendMessageToGroup(data.sender.group.id, forwardMsg); break; case 'FriendMessage': Bot.sendMessageToFriend(data.sender.id, message); diff --git a/plugins/cook/utils/index.js b/plugins/cook/utils/index.js index 58dd557..aca8812 100644 --- a/plugins/cook/utils/index.js +++ b/plugins/cook/utils/index.js @@ -1,19 +1,21 @@ +import pkg from 'mirai-js' +const { Message } = pkg + export function genRecipeMessage(recipeList, header, footer) { - const textList = []; - - for (let recipe of recipeList) { - textList.push( - `${recipe.name}\n材料:${recipe.stuff}\n厨具:${recipe.tools}\nhttps://www.bilibili.com/video/${recipe.bv}`, - ); - } - + const msg = new Message() if (header) { - textList.unshift(header); + msg.addText(`${header}\n`); } + recipeList.forEach((recipe, index)=> { + msg.addText(`${index}. ${recipe.name}\n`) + msg.addText(`\t· 材料:${recipe.stuff}\n`) + msg.addText(`\t· 厨具:${recipe.tools}\n`) + msg.addText(`\t· 制作视频:https://www.bilibili.com/video/${recipe.bv}\n`) + }) if (footer) { - textList.push(footer); + msg.addText(`${footer}`); } - return textList.join('\n \n'); + return msg }