test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
mol
2023-12-14 14:59:41 +08:00
parent 16196c46ac
commit cf18fdf532
2 changed files with 23 additions and 15 deletions

View File

@ -4,7 +4,7 @@ import { getRandomRecipe } from './api/index.js';
import { genRecipeMessage } from './utils/index.js'; import { genRecipeMessage } from './utils/index.js';
import logger from '#root/utils/logger.js' import logger from '#root/utils/logger.js'
const { Middleware } = pkg; const { Middleware, Message } = pkg;
const cookCommand = command.cook; const cookCommand = command.cook;
let Bot; let Bot;
@ -15,12 +15,18 @@ const commandHandle = {
async function randomCook(text, data) { async function randomCook(text, data) {
const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5; const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5;
const recipeList = await getRandomRecipe(limit); const recipeList = await getRandomRecipe(limit);
logger(JSON.stringify(recipeList));
const message = genRecipeMessage(recipeList, '给你推荐'); const message = genRecipeMessage(recipeList, '给你推荐');
logger(message);
switch (data.type) { switch (data.type) {
case 'GroupMessage': 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; break;
case 'FriendMessage': case 'FriendMessage':
Bot.sendMessageToFriend(data.sender.id, message); Bot.sendMessageToFriend(data.sender.id, message);

View File

@ -1,19 +1,21 @@
import pkg from 'mirai-js'
const { Message } = pkg
export function genRecipeMessage(recipeList, header, footer) { export function genRecipeMessage(recipeList, header, footer) {
const textList = []; const msg = new Message()
for (let recipe of recipeList) {
textList.push(
`${recipe.name}\n材料:${recipe.stuff}\n厨具:${recipe.tools}\nhttps://www.bilibili.com/video/${recipe.bv}`,
);
}
if (header) { 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) { if (footer) {
textList.push(footer); msg.addText(`${footer}`);
} }
return textList.join('\n \n'); return msg
} }