UNPKG

kotori-bot

Version:

Cross-platform chatbot framework base on Node.js and TypeScript

137 lines (136 loc) 5.7 kB
/** * @Package kotori-bot * @Version 1.7.0 * @Author Arimura Sena <me@hotaru.icu> * @Copyright 2024-2025 Hotaru. All rights reserved. * @License BAN-ZHINESE-USING * @Link https://github.com/kotorijs/kotori * @Date 17:26:14 */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var gui_exports = {}; __export(gui_exports, { mainScope: () => mainScope }); module.exports = __toCommonJS(gui_exports); var import_core = require("@kotori-bot/core"); var import_prompts = require("@inquirer/prompts"); const c = new import_core.Colors(new import_core.TerminalAdapter()); const req = new import_core.Http(); req.response(void 0, (err) => console.error(c.dye("Get modules data occurred error:", "red"), err)); async function getOnlineModules() { const { list } = await req.get("https://kotori.js.org/assets/data_details.json"); return list; } async function mainScope() { console.log(c.dye("Welcome to Kotori Bot GUI!", "magenta")); const action = await (0, import_prompts.select)({ message: "What do you want to do?", choices: [ { name: "Install Module", value: "installModule" }, { name: "Install Adapter", value: "installAdapter" }, { name: "Uninstall Module", value: "uninstallModule" }, { name: "Update Module", value: "updateModule" }, { name: "Create Module", value: "createModule" }, { name: "Open Official Website", value: "openWebsite" } ] }); switch (action) { case "installModule": await installModuleScope(); break; case "installAdapter": await installAdapterScope(); break; case "uninstallModule": await uninstallModuleScope(); break; case "updateModule": await updateModuleScope(); break; case "createModule": console.log( `Please refer to ${c.dye("https://github.com/kotorijs/create-kotori", "cyan")} about creating and developing a new module.` ); break; default: console.log("Kotori Bot Official Website:", c.dye("https://kotori.js.org", "cyan")); (0, import_core.executeCommand)( `${process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open"} https://kotori.js.org` ); } } async function installModuleScope() { const moduleName = await (0, import_prompts.input)({ message: "Please input the module name you want to install:" }); const modules = (await getOnlineModules()).filter(({ name }) => name.includes(moduleName)); if (modules.length === 0) { console.log("No module found."); return; } const selectedModule = await (0, import_prompts.select)({ message: `There are ${modules.length} modules found, please select one to install:`, choices: modules.map((m) => ({ value: m.name, name: `${m.name} v${m.version} - ${m.description}` })) }); console.log(c.dye(`Installing ${selectedModule} module...`, "yellow")); (0, import_core.executeCommand)(`npm install ${selectedModule}`); } async function installAdapterScope() { const adapterName = await (0, import_prompts.select)({ message: "Please select the adapter you want to install:", choices: [ { name: "\u2699\uFE0F Command line adapter", value: "@kotori-bot/kotori-plugin-adapter-cmd" }, { name: "\u{1F9E9} Onebot QQ adapter", value: "@kotori-bot/kotori-plugin-adapter-onebot" }, { name: "\u{1F427} Official QQ adapter", value: "@kotori-bot/kotori-plugin-adapter-qq" }, { name: "\u2708 Telegram adapter", value: "@kotori-bot/adapter-telegram" }, { name: "\u{1F3AE} Discord adapter", value: "@kotori-bot/adapter-discord" }, { name: "\u{1F7E9} Slack adapter", value: "@kotori-bot/adapter-slack" }, { name: "\u{1F4ED} Email adapter", value: "@kotori-bot/adapter-mail" }, { name: "\u{1F38D} Minecraft bedrock adapter", value: "@kotori-bot/kotori-plugin-adapter-minecraft" }, { name: "\u{1F9F0} Sandbox adapter", value: "@kotori-bot/kotori-plugin-adapter-sandbox" }, { name: "\u{1F573}\uFE0F Nothing, and more...", value: "more" } ] }); if (adapterName === "more") { await installModuleScope(); return; } console.log(c.dye(`Installing ${adapterName} adapter...`, "yellow")); (0, import_core.executeCommand)(`npm install ${adapterName}`); } async function uninstallModuleScope() { const moduleName = await (0, import_prompts.input)({ message: "Please input the module name you want to uninstall:" }); console.log(c.dye(`Uninstalling ${moduleName} module...`, "yellow")); (0, import_core.executeCommand)(`npm uninstall ${moduleName}`); } async function updateModuleScope() { const moduleName = await (0, import_prompts.input)({ message: "Please input the module name you want to update:" }); console.log(c.dye(`Updating ${moduleName} module...`, "yellow")); (0, import_core.executeCommand)(`npm update ${moduleName}`); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { mainScope });