UNPKG

jishaku

Version:

PythonのJishakuをパクった

85 lines 3.57 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JishakuError = exports.Jishaku = void 0; const discord_js_1 = require("discord.js"); const child_process_1 = require("child_process"); const util_1 = require("util"); const simple_discord_pagination_1 = require("simple-discord-pagination"); require("./extends"); class JishakuError extends Error { /** * * @param {string} message */ constructor(message) { super(message); this.name = "JishakuError"; } } exports.JishakuError = JishakuError; function splitText(message, text) { return __awaiter(this, void 0, void 0, function* () { if (text.length > 1999) { if (message.channel.type !== "GUILD_TEXT" && message.channel.type !== "DM") throw new JishakuError("channel is not a textchannel or dmchannel"); const isTarget = (arg) => typeof arg === "object" && arg !== null; if (!isTarget(message.channel)) throw new JishakuError("channel is not a textchannel or dmchannel"); const pagination = new simple_discord_pagination_1.Pagination(text.chunk(1999), 60000); return pagination.sendTo(message.channel, message.author); } }); } const execProm = (0, util_1.promisify)(child_process_1.exec); class Jishaku { /** * * @param {Client} client The Discord Client */ constructor(client, commandDir) { if (!client) throw new JishakuError("Client is not defined"); if (!(client instanceof discord_js_1.Client)) throw new JishakuError("client is not a Client"); this.client = client; if (commandDir) { if (!commandDir.endsWith("/")) throw new JishakuError("commandDir not endsWith /"); this.commandDir = commandDir; } if (!this.commandDir) this.commandDir = "commands/"; } jsk(jskType, code, message) { return __awaiter(this, void 0, void 0, function* () { if (jskType === "git") { (0, child_process_1.exec)(`git ${code}`, (err, stdout, stderr) => { if (stderr) { message.react("❌"); splitText(message, `\`\`\`sh\n${(0, util_1.inspect)(stderr)}\n\`\`\``); } else if (err) { message.react("❌"); splitText(message, `\`\`\`sh\n${(0, util_1.inspect)(err)}\n\`\`\``); } else { message.react("✅"); splitText(message, `\`\`\`sh\n${(0, util_1.inspect)(stdout)}\n\`\`\``); } }); } }); } } exports.Jishaku = Jishaku; //# sourceMappingURL=index.js.map