UNPKG

koishi-plugin-kbot

Version:
110 lines (109 loc) 5.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.apply = exports.logger = exports.Config = void 0; const jsx_runtime_1 = require("@satorijs/element/jsx-runtime"); /* * @Author: Kabuda-czh * @Date: 2023-01-29 14:28:53 * @LastEditors: Kabuda-czh * @LastEditTime: 2023-07-11 18:08:07 * @FilePath: \KBot-App\plugins\kbot\src\plugins\tarot\index.tsx * @Description: * * Copyright (c) 2023 by Kabuda-czh, All Rights Reserved. */ const node_url_1 = require("node:url"); const node_path_1 = __importDefault(require("node:path")); const koishi_1 = require("koishi"); const config_1 = __importDefault(require("../../config")); const shuffle_1 = __importDefault(require("./shuffle")); const tarot_config_1 = require("./tarot.config"); exports.Config = koishi_1.Schema.object({}); exports.logger = new koishi_1.Logger('KBot-plugin-tarot'); async function apply(ctx) { const cardLength = Object.keys(tarot_config_1.cards).length; const { tarotImagesDir } = config_1.default.getInstance(ctx.baseDir).getGeneratePathData(); ctx.command('kbot/抽塔罗牌', '抽单张塔罗牌', { checkArgCount: true, showWarning: false, }).action(async ({ session }) => { const randomIndex = Math.floor(Math.random() * cardLength); let cardKey = Object.keys(tarot_config_1.cards)[randomIndex]; let imageFile = `${(0, node_url_1.pathToFileURL)(node_path_1.default.join(`${tarotImagesDir}`, `${cardKey}.jpg`))}`; let cardValue = ''; // 特殊: 愚者有两张 if (cardKey === '愚者') { const rand = Math.floor(Math.random() * 2 + 1); imageFile = `${(0, node_url_1.pathToFileURL)(node_path_1.default.join(`${tarotImagesDir}`, `愚者${rand}.jpg`))}`; } // 特殊: 正位和逆位 if (typeof tarot_config_1.cards[cardKey] === 'object') { const rand = Math.floor(Math.random() * 2 + 1); cardValue = rand === 1 ? tarot_config_1.cards[cardKey].正位 : tarot_config_1.cards[cardKey].逆位; cardKey += rand === 1 ? '(正位)' : '(逆位)'; } else { cardValue = tarot_config_1.cards[cardKey]; } await session.send((0, jsx_runtime_1.jsx)("image", { url: imageFile })); (0, koishi_1.sleep)(1500); return (0, jsx_runtime_1.jsxs)("message", { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u9535\u9535\u9535\uFF0C\u5854\u7F57\u724C\u7684\u9884\u8A00\u662F~" }), (0, jsx_runtime_1.jsx)("p", { children: cardKey }), (0, jsx_runtime_1.jsxs)("p", { children: ["\u5176\u91CA\u4E49\u4E3A: ", cardValue] })] }); }); ctx.command('kbot/塔罗牌', '塔罗牌阵', { checkArgCount: true, showWarning: false, }).action(async ({ session }) => { const indiceArray = Array.from({ length: cardLength }, (_, i) => i + 1); const randomIndices = new Set(); while (randomIndices.size < 4) { const index = Math.floor(Math.random() * indiceArray.length + 1); if (!randomIndices.has(index)) randomIndices.add(index); } const indices = [...randomIndices]; const cardKeys = (0, shuffle_1.default)(Object.keys(tarot_config_1.cards)); const chain = []; const timesKeys = []; let rand, imageFile, cardKey, cardValue; for (let i = 0; i < indices.length; i++) { const index = indices[i]; cardKey = cardKeys[index - 1]; if (!cardKey) { exports.logger.error('cardKey is undefined', cardKey, indices); return '出现未知问题,请联系管理员'; } const meaningKey = Object.keys(tarot_config_1.meanings)[i]; const meaningValue = tarot_config_1.meanings[meaningKey]; imageFile = `${(0, node_url_1.pathToFileURL)(node_path_1.default.join(`${tarotImagesDir}`, `${cardKey}.jpg`))}`; // 特殊: 愚者有两张 if (cardKey === '愚者') { rand = Math.floor(Math.random() * 2 + 1); imageFile = `${(0, node_url_1.pathToFileURL)(node_path_1.default.join(`${tarotImagesDir}`, `愚者${rand}.jpg`))}`; } // 特殊: 正位和逆位 if (typeof tarot_config_1.cards[cardKey] === 'object') { rand = Math.floor(Math.random() * 2 + 1); cardValue = rand === 1 ? tarot_config_1.cards[cardKey].正位 : tarot_config_1.cards[cardKey].逆位; cardKey += rand === 1 ? '(正位)' : '(逆位)'; } else { cardValue = tarot_config_1.cards[cardKey]; } const msg = `${meaningKey}${meaningValue}\n${cardKey}${cardValue}`; timesKeys.push(cardKey); chain.push({ text: `第 ${i + 1} 轮`, msg, imageFile, }); } await session.send(`你抽到了:${timesKeys.join(' -- ')}`); return (0, jsx_runtime_1.jsx)("message", { forward: true, children: chain.map((msg) => { return (0, jsx_runtime_1.jsxs)("message", { children: [(0, jsx_runtime_1.jsx)("author", { "user-id": session.selfId }), (0, jsx_runtime_1.jsx)("p", { children: msg.text }), (0, jsx_runtime_1.jsx)("p", { children: msg.msg }), (0, jsx_runtime_1.jsx)("image", { url: msg.imageFile })] }); }) }); }); } exports.apply = apply;