Skip to content

Commit

Permalink
V2.2
Browse files Browse the repository at this point in the history
- Removed - reload-cmd command
- Removed - reload-event command
- Added - reload command
- Added - Reload all commands function
- Added - Reload all events function
  • Loading branch information
LordAlex2015 committed May 21, 2021
1 parent 5f1d1f9 commit ccd9d9c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CHANGELOGS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelogs

## V2.2
- Removed - `reload-cmd` command
- Removed - `reload-event` command
- Added - `reload` command
- Added - Reload all commands function
- Added - Reload all events function

## V2.1
- Optimised - Main.js (Reorganisation)
- Added - `reload-cmd` command (Function in main.js (`client.reloadCommand(commandName)`))
Expand Down
28 changes: 0 additions & 28 deletions commands/utils/reload-command.js

This file was deleted.

28 changes: 0 additions & 28 deletions commands/utils/reload-event.js

This file was deleted.

54 changes: 54 additions & 0 deletions commands/utils/reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const Command = require("../../structure/Command.js");

class ReloadCommand extends Command {
constructor() {
super({
name: 'reload',
category: 'owner',
description: 'reload files',
usage: 'reload <-all/-c/-e> <file-name-without-.js/-c/-all/-e>',
example: ['reload -c help','reload -c ping','reload -e message', 'reload -e ready', 'reload -all -c','reload -all -e','reload -all -all'],
perms: "owner",
aliases: ['rl']
});
}

async run(client, message, args) {
if(!args[1]) {
message.channel.send("> No type specified!");
} else if(args[1] === '-all') {
if(!args[2]) {
client.reloadAllCommands().then(res_c => {
client.reloadAllEvents().then(res_e => {
message.channel.send(`${res_c}\n${res_e}`)
})
})
} else if(args[2] === "-c") {
client.reloadAllCommands().then(res => {
message.channel.send(res)
})
} else if(args[2] === "-e") {
client.reloadAllEvents().then(res => {
message.channel.send(res)
})
}
} else if(!args[2]) {
message.channel.send("> No file specified!");
} else {
if(args[1] === '-c') {
client.reloadCommand(args[2]).then(async res => {
await message.channel.send(res);
});
} else if(args[1] === '-e') {
client.reloadEvent(args[2]).then(async res => {
await message.channel.send(res);
});
}

}
}
}

module.exports = new ReloadCommand;
37 changes: 37 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ class Class extends Client {
resolve(`> Event named: \`${reload_event}\` not found`)
})
}
this.reloadAllCommands = function() {
return new Promise((resolve) => {
let count = 0;
const folders = readdirSync(join(__dirname, "commands"));
for (let i = 0; i < folders.length; i++) {
const commands = readdirSync(join(__dirname, "commands", folders[i]));
count = count + commands.length;
for(const c of commands){
try {
this.reloadCommand(c.replace('.js',''));
} catch (error) {
console.log(`${red('[Commands Reload]')} Failed to reload command ${c}: ${error.stack || error}`)
throw new Error(`${red('[Commands Reload]')} Failed to load event ${e}: ${error.stack || error}`)
}
}
}
console.log(`${green('[Commands Reload]')} Reloaded ${this.commands.size}/${count} commands`);
resolve(`> Reloaded \`${this.commands.size}\`/\`${count}\` commands`)
})
}
this.reloadAllEvents = function() {
return new Promise((resolve) => {
let count = 0;
const files = readdirSync(join(__dirname, "events"));
files.forEach((e) => {
try {
count++;
const fileName = e.split('.')[0];
this.reloadEvent(fileName);
} catch (error) {
throw new Error(`${red('[Events Reload]')} Failed to load event ${e}: ${error.stack || error}`)
}
});
console.log(`${green('[Events Reload]')} Loaded ${count}/${files.length} events`);
resolve(`> Reloaded \`${count}\`/\`${files.length}\` events`)
})
}
try {
this.launch().then(() => { console.log(blue('All is launched, Connecting to Discord..')); })
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "handler-discord",
"version": "2..0",
"version": "2.2.0",
"description": "Handler in Class for Discord.js",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit ccd9d9c

Please sign in to comment.