Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bot = require('../../commandclient.js')
- const config = require("../../config.json");
- const reload = require('require-reload')(require);
- const fs = require('fs');
- const unRequire = require("un-require");
- //
- module.exports = {
- label: 'load',
- enabled: true,
- isSubcommand: false,
- generator:async (msg, args) => {
- let eventaliases = ['e', 'ev', 'event']
- if(eventaliases.includes(args[0])) {
- try {
- let event = bot._events[args[1]];
- if (event) {
- delete bot._events[args[1]]
- }
- event = require('../events/' + args[1]);
- bot.on(event.event, event.handler);
- msg.channel.createMessage(`<:done:331250330367164437> Successfully loaded event \`${args[1]}\`!`)
- } catch (e) {
- console.warn(`Error while loading event ${args[1]}!\n${e.stack}.`)
- msg.channel.createMessage(`<:notdone:334852376034803714> Error: \`${e.message}\`.`)
- }
- return;
- }
- try {
- let getcmdname = args[0].split('bot/').join('').split('misc/').join('').split('dev/').join('').split('mod/').join('').split('music/').join('').split('currency/').join('').split('settings/').join('')
- bot.unregisterCommand(getcmdname);
- let c = reload(`../${args[0]}`);
- var filess = args.join(" ");
- if (c.enabled && !c.isSubcommand) {
- let cmd = bot.registerCommand(c.label, c.generator, c.options);
- function unloadSubcommands(args) {
- fs.readdir(`commands/${filess}`,async (err, files)=> {
- if (err) {
- //console.error(' Error:' + err);
- } else {
- try {
- let subcmds = files.filter(f => f.includes(`${args[1]}_`));
- if(subcmds !== []) {
- subcmds.forEach((subcmd) => {
- unload(require.resolve('../' + subcmd));
- });
- }
- } catch (e) {
- console.warn(`Error with unloading command (for reload) ${args[0]}:\n${e.stack}`);
- msg.channel.createMessage(`<:notdone:334852376034803714> Error: ${e.message}`)
- }
- }
- });
- }
- unloadSubcommands(args);
- registerSubcommands(c, cmd);
- function registerSubcommands(cmd, parent) {
- cmd.subcommands = cmd.subcommands || [];
- cmd.subcommands.forEach((subcmd)=> {
- if (subcmd.enabled) {
- let c = parent.registerSubcommand(subcmd.label, subcmd.generator, subcmd.options);
- registerSubcommands(subcmd, c);
- }
- });
- }
- }
- msg.channel.createMessage(`\`${args[0]}\` has been successfully reloaded! <:done:331250330367164437>`)
- } catch (e) {
- console.warn(`Error while loading command ${args[0]}!\n${e.stack}.`)
- msg.channel.createMessage(`<:notdone:334852376034803714> Error: \`${e.message}\`.`)
- }
- },
- options: {
- description: "Loads/Reloads commands.",
- fullDescription: "Makes the bot load/reload a command.",
- usage: `>load <folder/command> | >reload <folder/command>`,
- requirements: {
- "userIDs": [config.dev],
- },
- cooldown: null,
- aliases: ['reload', 'enable'],
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement