diff --git a/plugins/cook/api/index.js b/plugins/cook/api/index.js index efa60fa..e815e9c 100644 --- a/plugins/cook/api/index.js +++ b/plugins/cook/api/index.js @@ -1,18 +1,23 @@ import getDb from '../db/index.js'; export async function getRandomRecipe(limit = 5) { + logger(`随机${limit}个食谱`) const data = await getDb(); const len = data.length; + logger(len) const list = []; const indexList = new Set(); while (indexList.size === limit) { const index = Math.floor(Math.random() * len); + logger(`index: ${index}`) if (!indexList.has(index)) { indexList.set(index); list.push(data[index]); } } + logger(list.length) + return list; } diff --git a/plugins/cook/index.js b/plugins/cook/index.js index 8c8100c..a57f42d 100644 --- a/plugins/cook/index.js +++ b/plugins/cook/index.js @@ -13,11 +13,12 @@ const commandHandle = { }; async function randomCook(text, data) { + logger(text, data.type, data.sender.id, data.sender.group.id); const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5; const recipeList = await getRandomRecipe(limit); - logger(JSON.stringify(recipeList)) + logger(JSON.stringify(recipeList)); const message = genRecipeMessage(recipeList, '给你推荐'); - logger(message) + logger(message); switch (data.type) { case 'GroupMessage': Bot.sendMessageToGroup(data.sender.group.id, message); diff --git a/plugins/cook/utils/index.js b/plugins/cook/utils/index.js index 7f7a60e..8bca1f5 100644 --- a/plugins/cook/utils/index.js +++ b/plugins/cook/utils/index.js @@ -8,7 +8,7 @@ export function genRecipeMessage(recipeList, header, footer) { } if (header) { - textList.shift(header); + textList.unshift(header); } if (footer) {