UNPKG

@sern/cli

Version:

Official CLI for @sern/handler

59 lines (57 loc) 1.98 kB
import { create } from '../chunk-PAIOQOOR.js'; import assert from 'node:assert'; import dotenv from 'dotenv'; import ora from 'ora'; import { readFileSync, writeFile } from 'node:fs'; import { resolve } from 'node:path'; import prompts from 'prompts'; var getConfirmation = (args) => { if (args.yes) { return args.yes; } else { return prompts({ type: "confirm", name: "confirmation", message: "Are you sure you want to delete ALL your application commands?", initial: true }, { onCancel: () => (console.log("Cancelled operation (\uFFE3\u2530\uFFE3*)"), process.exit(1)) }).then((response) => response.confirmation); } }; async function commandClear(args) { dotenv.configDotenv({ path: args.env || resolve(".env") }); const token = process.env.token || process.env.DISCORD_TOKEN; assert(token, "Could not find a token for this bot in .env or commandline. Do you have DISCORD_TOKEN in env?"); const confirmation = await getConfirmation(args); if (confirmation) { const spin = ora({ text: `Deleting ALL application commands...`, spinner: "aesthetic" }).start(); const rest = await create(token); let guildCommands; try { guildCommands = JSON.parse(readFileSync(".sern/command-data-remote.json", "utf-8")); await rest.updateGlobal([]); delete guildCommands.global; for (const guildId in guildCommands) { await rest.putGuildCommands(guildId, []); } writeFile(".sern/command-data-remote.json", "{}", (err) => { if (err) { spin.fail("Error happened while writing to json:"); console.error(err); process.exit(1); } }); spin.succeed(); } catch (e) { spin.fail("Something went wrong. "); throw e; } } else { console.log("Operation canceled. (\uFFE3\u2530\uFFE3*)"); } } export { commandClear }; //# sourceMappingURL=out.js.map //# sourceMappingURL=command-clear.js.map