This commit is contained in:
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user