CommandManager functioning
This commit is contained in:
@@ -1 +1,33 @@
|
|||||||
// TODO: commandmanager
|
const Logger = require('./logger');
|
||||||
|
const Config = require('./config');
|
||||||
|
const Commands = require('./commands/commands')
|
||||||
|
const CommandManager = require('./main');
|
||||||
|
const http = require('http');
|
||||||
|
const ping = require('ping');
|
||||||
|
const fs = require('fs');
|
||||||
|
const Discord = require('discord.js');
|
||||||
|
|
||||||
|
var commands = {};
|
||||||
|
|
||||||
|
module.exports.commands = commands;
|
||||||
|
|
||||||
|
function addCommand(name, command, alt, usage, desc, requrePerms, functionReference) {
|
||||||
|
commands[name] = {
|
||||||
|
name: name,
|
||||||
|
command: command,
|
||||||
|
alt: alt,
|
||||||
|
usage: usage,
|
||||||
|
desc: desc,
|
||||||
|
requrePerms: requrePerms,
|
||||||
|
functionReference: functionReference
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*command name, command, alt, usage, description, require permission, reference*/
|
||||||
|
module.exports.loadCommands = function() {
|
||||||
|
//general commands
|
||||||
|
addCommand('say', 'say', undefined, 'say [input]', 'repeats the input', false, Commands.say);
|
||||||
|
addCommand('version', 'version', undefined, 'version', 'returns the version', false, Commands.version);
|
||||||
|
addCommand('ping', 'ping', undefined, 'ping', 'returns round trip to discords serves', false, Commands.ping);
|
||||||
|
//continue
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const Config = require('../config');
|
|||||||
/*message object, messaage full, message args, discord client*/
|
/*message object, messaage full, message args, discord client*/
|
||||||
|
|
||||||
module.exports.say = function(message, msg, args, discordclient) {
|
module.exports.say = function(message, msg, args, discordclient) {
|
||||||
|
message.channel.send(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.version = function(message, msg, args, discordclient) {
|
module.exports.version = function(message, msg, args, discordclient) {
|
||||||
@@ -15,7 +15,6 @@ module.exports.version = function(message, msg, args, discordclient) {
|
|||||||
em.setTitle('Version:');
|
em.setTitle('Version:');
|
||||||
em.setDescription(Config.getconfig().Version);
|
em.setDescription(Config.getconfig().Version);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.ping = function(message, msg, args, discordclient) {
|
module.exports.ping = function(message, msg, args, discordclient) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
var config = null;
|
var config = {};
|
||||||
|
var rules = {};
|
||||||
|
|
||||||
module.exports.getconfig = function() {
|
module.exports.getconfig = function() {
|
||||||
return config;
|
return config;
|
||||||
@@ -17,9 +17,8 @@ module.exports.loadDefaults = function() {
|
|||||||
NowPlaying: "RealLife.exe",
|
NowPlaying: "RealLife.exe",
|
||||||
Prefix: "+",
|
Prefix: "+",
|
||||||
Version: "2.0.1",
|
Version: "2.0.1",
|
||||||
|
|
||||||
Rules: ["Rule 0", "Rule 1"]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.loadFromFile = function() {
|
module.exports.loadFromFile = function() {
|
||||||
|
|||||||
38
main.js
38
main.js
@@ -1,5 +1,6 @@
|
|||||||
const Logger = require('./logger');
|
const Logger = require('./logger');
|
||||||
const Config = require('./config');
|
const Config = require('./config');
|
||||||
|
const Commands = require('./commands/commands')
|
||||||
const CommandManager = require('./commandmanager');
|
const CommandManager = require('./commandmanager');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const ping = require('ping');
|
const ping = require('ping');
|
||||||
@@ -26,11 +27,17 @@ if (!fs.existsSync('resources/config.json')) {
|
|||||||
Logger.log('Loading config...');
|
Logger.log('Loading config...');
|
||||||
try {
|
try {
|
||||||
Config.loadFromFile();
|
Config.loadFromFile();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Logger.failed(`Could not load the config: ${e.message}`);
|
Logger.failed(`Could not load the config: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
/*loads the commands*/
|
||||||
|
try {
|
||||||
|
Logger.log("Loading commands...");
|
||||||
|
CommandManager.loadCommands();
|
||||||
|
} catch (e) {
|
||||||
|
Logger.log(`Could not load the commands: ${e.message}`);
|
||||||
|
}
|
||||||
/*connects to discord*/
|
/*connects to discord*/
|
||||||
try {
|
try {
|
||||||
Logger.log("Starting discord client...");
|
Logger.log("Starting discord client...");
|
||||||
@@ -43,37 +50,24 @@ client.on('ready', () => {
|
|||||||
client.user.setPresence('online');
|
client.user.setPresence('online');
|
||||||
client.user.setActivity(Config.getconfig().NowPlaying);
|
client.user.setActivity(Config.getconfig().NowPlaying);
|
||||||
Logger.log(`Logged in as ${client.user.tag}`);
|
Logger.log(`Logged in as ${client.user.tag}`);
|
||||||
Logger.log('Ready!')
|
Logger.log('Ready!');
|
||||||
console.log();
|
console.log();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*on message event*/
|
/*on message event*/
|
||||||
client.on('message', async (message) => {
|
client.on('message', async (message) => {
|
||||||
/*if it starts with prefix*/
|
/*if it starts with prefix loaded from config*/
|
||||||
if (message.content.startsWith(Config.getconfig().Prefix)) {
|
if (message.content.startsWith(Config.getconfig().Prefix)) {
|
||||||
Logger.logMSG(message);
|
Logger.logMSG(message);
|
||||||
var msg = message.content.substring(Config.getconfig().Prefix.length);
|
var msg = message.content.substring(Config.getconfig().Prefix.length);
|
||||||
var args = msg.split(" ");
|
var args = msg.split(" ");
|
||||||
|
|
||||||
/*temp switch statement to manage commands*/
|
/*command manager checks if command exists*/
|
||||||
switch (args[0].toUpperCase()) {
|
if (CommandManager.commands[args[0]]) {
|
||||||
case 'PING':
|
/*sends command: message object, messaage full, message args, discord client*/
|
||||||
ping.promise.probe("discordapp.com", {
|
CommandManager.commands[args[0]].functionReference(message, msg, args, client);
|
||||||
timeout: 10
|
} else {
|
||||||
}).then((output) => {
|
message.channel.send(`:no_entry_sign: \`The command \'${args[0]}\' does not exist\``);
|
||||||
message.channel.send(`:white_check_mark: \`${output.avg}ms\``);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
case 'VERSION':
|
|
||||||
var em = new Discord.RichEmbed();
|
|
||||||
em.setColor('BLUE');
|
|
||||||
em.setTitle('Version:');
|
|
||||||
em.setDescription(Config.getconfig().Version);
|
|
||||||
message.channel.send(em);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
message.channel.send(`:no_entry: \`The command '${args[0]}' does not exist...\``);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user