Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Eslint all the things! #70

Merged
merged 1 commit into from
Nov 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const Discord = require("discord.js");
const chalk = require("chalk");

const clk = new chalk.constructor({ enabled: true });

exports.start = (config) => {

const client = new Discord.Client(config.clientOptions);

client.config = config;

// Extend client
client.config["init"] = [];
client.config.init = [];
client.funcs = {};
client.helpStructure = new Map();
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.commandInhibitors = new Discord.Collection();
client.dataProviders = new Discord.Collection();

client.coreBaseDir = __dirname + "/";
client.clientBaseDir = process.cwd() + "/";
client.coreBaseDir = `${__dirname}/`;
client.clientBaseDir = `${__dirname}/`;

// Load core functions, then everything else
require("./functions/loadFunctions.js")(client).then(() => {
Expand All @@ -34,47 +34,46 @@ exports.start = (config) => {
});

client.once("confsRead", () => {
client.commands.forEach(command => {
if(command.init) {
client.commands.forEach((command) => {
if (command.init) {
command.init(client);
}
});
});

client.on("message", msg => {
let conf = client.funcs.confs.get(msg.guild);
client.on("message", (msg) => {
const conf = client.funcs.confs.get(msg.guild);
msg.guildConf = conf;
if (!msg.content.startsWith(conf.prefix) && !client.config.prefixMention.test(msg.content)) return;
let prefixLength = conf.prefix.length;
if(client.config.prefixMention.test(msg.content)) prefixLength = client.config.prefixMention.exec(msg.content)[0].length +1;
let command = msg.content.slice(prefixLength).split(" ")[0].toLowerCase();
let suffix = msg.content.slice(prefixLength).split(" ").slice(1).join(" ");
if (client.config.prefixMention.test(msg.content)) prefixLength = client.config.prefixMention.exec(msg.content)[0].length + 1;
const command = msg.content.slice(prefixLength).split(" ")[0].toLowerCase();
const suffix = msg.content.slice(prefixLength).split(" ").slice(1).join(" ");
let commandLog;
switch (msg.channel.type) {
case "text":
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgGreen(`${msg.guild.name}[${msg.guild.id}]`)}`;
break;
case "dm":
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgMagenta("[Direct Messages]")}`;
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgMagenta("[Direct Messages]")}`;
break;
case "group": //works for selfbots only
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgCyan(`${msg.channel.owner.username}[${msg.channel.owner.id}] in [GroupDM]`)}`;
case "group": // works for selfbots only
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgCyan(`${msg.channel.owner.username}[${msg.channel.owner.id}] in [GroupDM]`)}`;
break;
default: // text channels
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgGreen(`${msg.guild.name}[${msg.guild.id}]`)}`;
}
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
}
if(!cmd) return;
if (!cmd) return;
client.funcs.runCommandInhibitors(client, msg, cmd)
.then(params => {
.then((params) => {
client.funcs.log(commandLog);
cmd.run(client, msg, params);
})
.catch(reason => {
if(reason) {
.catch((reason) => {
if (reason) {
msg.channel.sendMessage(reason).catch(console.error);
}
});
Expand All @@ -84,6 +83,6 @@ exports.start = (config) => {
return client;
};

process.on("unhandledRejection", err => {
console.error("Uncaught Promise Error: \n" + err.stack);
process.on("unhandledRejection", (err) => {
console.error(`Uncaught Promise Error: \n${err.stack}`);
});
2 changes: 1 addition & 1 deletion commands/System/conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
exports.run = (client, msg, [action, key, ...value]) => {

if (action === "list") {
msg.channel.sendCode("json", require("util").inspect(msg.guildConf));
} else
Expand All @@ -26,6 +25,7 @@ exports.run = (client, msg, [action, key, ...value]) => {
client.funcs.confs.resetKey(msg.guild, key);
return msg.reply("The key has been reset.");
}
return false;
};

exports.conf = {
Expand Down
9 changes: 4 additions & 5 deletions commands/System/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ exports.run = (client, msg, [commandname]) => {
}
if (!command) {
return msg.channel.sendMessage(`I cannot find the command: ${commandname}`);
} else {
client.commands.get(command).conf.enabled = false;
return msg.channel.sendMessage(`Successfully disabled: ${commandname}`);
}
client.commands.get(command).conf.enabled = false;
return msg.channel.sendMessage(`Successfully disabled: ${commandname}`);
};

exports.conf = {
Expand All @@ -19,12 +18,12 @@ exports.conf = {
aliases: [],
permLevel: 10,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "disable",
description: "Temporarily disables the command. Resets upon reboot.",
usage: "<commandname:str>",
usageDelim: ""
usageDelim: "",
};
9 changes: 4 additions & 5 deletions commands/System/enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ exports.run = (client, msg, [commandname]) => {
}
if (!command) {
return msg.channel.sendMessage(`I cannot find the command: ${commandname}`);
} else {
client.commands.get(command).conf.enabled = true;
return msg.channel.sendMessage(`Successfully enabled: ${commandname}`);
}
client.commands.get(command).conf.enabled = true;
return msg.channel.sendMessage(`Successfully enabled: ${commandname}`);
};

exports.conf = {
Expand All @@ -19,12 +18,12 @@ exports.conf = {
aliases: [],
permLevel: 10,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "enable",
description: "Re-enables or temporarily enables a command. Default state restored on reboot.",
usage: "<commandname:str>",
usageDelim: ""
usageDelim: "",
};
9 changes: 5 additions & 4 deletions commands/System/eval.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
exports.run = (client, msg, [code]) => {
try {
var evaled = eval(code);
if (typeof evaled !== "string")
let evaled = eval(code);
if (typeof evaled !== "string") {
evaled = require("util").inspect(evaled);
}
msg.channel.sendCode("xl", client.funcs.clean(client, evaled));
} catch (err) {
msg.channel.sendMessage("`ERROR` ```xl\n" +
Expand All @@ -17,12 +18,12 @@ exports.conf = {
aliases: ["ev"],
permLevel: 10,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "eval",
description: "Evaluates arbitrary Javascript. Reserved for bot owner.",
usage: "<expression:str>",
usageDelim: ""
usageDelim: "",
};
4 changes: 2 additions & 2 deletions commands/System/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ exports.conf = {
aliases: ["details", "what"],
permLevel: 0,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "info",
description: "Provides some information about this bot.",
usage: "",
usageDelim: ""
usageDelim: "",
};
4 changes: 2 additions & 2 deletions commands/System/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.help = {
name: "invite",
description: "Displays the join server link of the bot.",
usage: "",
usageDelim: ""
usageDelim: "",
};

exports.conf = {
Expand All @@ -16,5 +16,5 @@ exports.conf = {
aliases: [],
permLevel: 0,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};
6 changes: 3 additions & 3 deletions commands/System/ping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports.run = (client, msg) => {
msg.channel.sendMessage("Ping?")
.then(message => {
.then((message) => {
message.edit(`Pong! (took: ${message.createdTimestamp - msg.createdTimestamp}ms)`);
});
};
Expand All @@ -11,12 +11,12 @@ exports.conf = {
aliases: [],
permLevel: 0,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "ping",
description: "Ping/Pong command. I wonder what this does? /sarcasm",
usage: "",
usageDelim: ""
usageDelim: "",
};
10 changes: 5 additions & 5 deletions commands/System/reboot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
exports.run = (client, msg) => {
const collector = msg.channel.createCollector(m => m.author === msg.author, {
time: 10000
time: 10000,
});
msg.channel.sendMessage("are you sure?");
collector.on("message", m => {
collector.on("message", (m) => {
if (m.content === "no") collector.stop("aborted");
if (m.content === "yes") collector.stop("success");
});
Expand All @@ -15,7 +15,7 @@ exports.run = (client, msg) => {
.then(() => {
process.exit();
})
.catch(e => {
.catch((e) => {
console.error(e);
});
}
Expand All @@ -28,12 +28,12 @@ exports.conf = {
aliases: [],
permLevel: 10,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "reboot",
description: "reboots the bot.",
usage: "",
usageDelim: ""
usageDelim: "",
};
22 changes: 11 additions & 11 deletions commands/System/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ exports.run = (client, msg, [commandname]) => {
}
if (!command) {
client.funcs.getFileListing(client, client.coreBaseDir, "commands")
.then(files => {
let newCommands = files.filter(f => f.name == command);
newCommands.forEach(file => {
.then((files) => {
const newCommands = files.filter(f => f.name === command);
newCommands.forEach((file) => {
msg.channel.sendMessage(`Loading New Command: ${commandname}`)
.then(m => {
client.funcs.loadSingleCommand(client, command, false, `${file.path}${require("path").sep}${file.base}`).then(cmd => {
.then((m) => {
client.funcs.loadSingleCommand(client, command, false, `${file.path}${require("path").sep}${file.base}`).then((cmd) => {
m.edit(`Successfully Loaded: ${cmd.help.name}`);
})
.catch(e => {
.catch((e) => {
m.edit(`Command load failed for ${command}: \n\`\`\`${e.stack}\`\`\``);
});
});
});
});
} else {
msg.channel.sendMessage(`Reloading: ${command}`)
.then(m => {
.then((m) => {
client.funcs.loadSingleCommand(client, command, true)
.then(cmd => {
.then((cmd) => {
m.edit(`Successfully reloaded: ${cmd.help.name}`);
})
.catch(e => {
.catch((e) => {
m.edit(`Command reload failed for ${command}: \n\`\`\`${e}\`\`\``);
});
});
Expand All @@ -46,11 +46,11 @@ exports.conf = {
aliases: ["r", "load"],
permLevel: 10,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "reload",
description: "Reloads the command file, if it's been updated or modified.",
usage: "<all:literal|commandname:str>"
usage: "<all:literal|commandname:str>",
};
6 changes: 3 additions & 3 deletions commands/System/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const moment = require("moment");
require("moment-duration-format");

exports.run = (client, msg) => {
let duration = moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]");
const duration = moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]");
msg.channel.sendCode("asciidoc", `= STATISTICS =

• Mem Usage :: ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB
Expand All @@ -20,12 +20,12 @@ exports.conf = {
aliases: ["details", "what"],
permLevel: 0,
botPerms: [],
requiredFuncs: []
requiredFuncs: [],
};

exports.help = {
name: "stats",
description: "Provides some details about the bot and stats.",
usage: "",
usageDelim: ""
usageDelim: "",
};
4 changes: 2 additions & 2 deletions functions/addCommas.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = (nStr) => {
nStr += "";
let x = nStr.split(".");
const x = nStr.split(".");
let x1 = x[0];
let x2 = x.length > 1 ? "." + x[1] : "";
const x2 = x.length > 1 ? `.${x[1]}` : "";
const rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, "$1" + "," + "$2");
Expand Down
Loading