This commit is contained in:
55
plugins/cook/index.js
Normal file
55
plugins/cook/index.js
Normal file
@ -0,0 +1,55 @@
|
||||
import pkg from 'mirai-js';
|
||||
import { cookSubs, command } from '#root/config/index.js';
|
||||
import { getRandomRecipe } from './api/index.js';
|
||||
import { genRecipeMessage } from './utils/index.js';
|
||||
|
||||
const { Middleware } = pkg;
|
||||
const cookCommand = command.cook;
|
||||
let Bot;
|
||||
let Queue;
|
||||
|
||||
const commandHandle = {
|
||||
random: randomCook,
|
||||
};
|
||||
|
||||
function randomCook(text, data) {
|
||||
const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5;
|
||||
const recipeList = getRandomRecipe(limit);
|
||||
const message = genRecipeMessage(recipeList, '给你推荐');
|
||||
|
||||
switch (data.type) {
|
||||
case 'GroupMessage':
|
||||
Bot.sendMessageToGroup(data.sender.group.id, message);
|
||||
break;
|
||||
case 'FriendMessage':
|
||||
Bot.sendMessageToFriend(data.sender.id, message);
|
||||
}
|
||||
}
|
||||
|
||||
function cookInit() {
|
||||
Bot.on(
|
||||
'GroupMessage',
|
||||
new Middleware().groupFilter(cookSubs.groups).done(dealCommon),
|
||||
);
|
||||
|
||||
Bot.on(
|
||||
'FriendMessage',
|
||||
new Middleware().friendFilter(cookSubs.users).done(dealCommon),
|
||||
);
|
||||
}
|
||||
|
||||
function dealCommon(data) {
|
||||
const [commandText, ...contentText] = data.text.trim().split(' ');
|
||||
for (let com of cookCommand.keys()) {
|
||||
if (cookCommand[com].includes(commandText)) {
|
||||
commandHandle[com](contentText, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function install(bot, queue) {
|
||||
Bot = bot;
|
||||
Queue = queue;
|
||||
cookInit();
|
||||
}
|
Reference in New Issue
Block a user