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

[FEATURES] Destruction of App.js #137

Merged
merged 6 commits into from
Feb 3, 2017
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Added a bunch of unusable configuration options that'll make their debut soon.
- All Bad Requests/Forbiddens.. etc, now properly give a human readable error in console or chat, depending on the error. (Not as of (0.17.0).. must be fixed) ***
- New Error Creator
- New CommandHandler (Removed it from message event)
Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- New Download Command

### Changed
- Broke down App.js Message Event into several smaller, changeable parts.
- newError changed to send arguments to awaitMessage when errors are from usage
- awaitMessage changed to work perfectly with the new system
- msg.author.permLevel is now available immediately on a message, instead of after inhibitors run correctly.
Expand All @@ -38,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- dataProviders renamed to Providers

### Fixed
- Fixed Typo in transfer command
- Fixed Usage not working properly with selective
- permissionLevels -> permissionLevel
- Unchanged Package.json links to the repository
Expand Down
22 changes: 4 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,13 @@ exports.start = async (config) => {
client.on("disconnect", e => client.funcs.log(e, "error"));

client.on("message", async (msg) => {
if (msg.author.bot) return;
await client.funcs.runMessageMonitors(client, msg);
msg.author.permLevel = await client.funcs.permissionLevel(client, msg.author, msg.guild);
msg.guildConf = Config.get(msg.guild);
client.i18n.use(msg.guildConf.lang);
await client.funcs.runMessageMonitors(client, msg);
if (client.config.selfbot && msg.author.id !== client.user.id) return;
const cmd = client.funcs.commandHandler(client, msg);
if (!cmd) return;
try {
const params = await client.funcs.runCommandInhibitors(client, msg, cmd);
cmd.run(client, msg, params);
} catch (error) {
if (error) {
if (error.code === 1 && client.config.cmdPrompt) {
client.funcs.awaitMessage(client, msg, cmd, [], error.message);
} else {
if (error.stack) client.emit("error", error.stack);
msg.channel.sendCode("JSON", (error.message || error)).catch(err => client.emit("error", err));
}
}
}
if (!client.funcs.handleMessage(client, msg)) return;
const command = client.funcs.parseCommand(client, msg);
client.funcs.handleCommand(client, msg, command);
});

client.login(client.config.botToken);
Expand Down
2 changes: 1 addition & 1 deletion commands/System/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.conf = {

exports.help = {
name: "transfer",
description: "Transfers a core command to the user folders",
description: "Transfers a core piece to its respected folder",
usage: "<command|function|inhibitor|event|monitor> <name:str>",
usageDelim: " ",
};
Expand Down
23 changes: 0 additions & 23 deletions functions/commandHandler.js

This file was deleted.

40 changes: 40 additions & 0 deletions functions/handleCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = async (client, msg, command, args = undefined) => {
const validCommand = this.getCommand(client, command);
if (!validCommand) return;
const response = this.runInhibitors(client, msg, validCommand);
if (response) return msg.reply(response);
try {
const params = await client.funcs.usage.run(client, msg, validCommand, args);
validCommand.run(client, msg, params);
} catch (error) {
if (error) {
if (error.code === 1 && client.config.cmdPrompt) {
client.funcs.awaitMessage(client, msg, validCommand, [], error.message);
} else {
if (error.stack) client.emit("error", error.stack);
msg.channel.sendCode("JSON", (error.message || error)).catch(err => client.emit("error", err));
}
}
}
};

exports.getCommand = (client, command) => {
if (client.commands.has(command)) {
return client.commands.get(command);
} else if (client.aliases.has(command)) {
return client.commands.get(client.aliases.get(command));
}
return false;
};

exports.runInhibitors = (client, msg, command) => {
const priority = client.commandInhibitors.array().sort((low, high) => low.conf.priority < high.conf.priority);
let response;
priority.some((inhibitor) => { // eslint-disable-line
if (inhibitor.conf.enabled) {
response = inhibitor.run(client, msg, command);
if (response) return true;
}
});
return response;
};
8 changes: 8 additions & 0 deletions functions/handleMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = (client, msg, edited = false) => {
if (client.config.ignoreBots && msg.author.bot) return false; // Ignore Bots if True
if (client.config.ignoreSelf && msg.author.id === client.user.id) return false; // Ignore Self if true
if (client.config.selfbot && msg.author.id !== client.user.id) return false; // Ignore other users if selfbot is true
if (!client.config.selfbot && msg.author.id === client.user.id) return false; // Ignore other users if selfbot but config option is false
if (!client.config.editableCommands && edited) return false; // Ignore message if owner doesn't allow editableCommands
return true;
}
30 changes: 30 additions & 0 deletions functions/parseCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = (client, msg, usage = false) => {
const prefix = this.getPrefix(client, msg);
if (!prefix) return;
const prefixLength = this.getLength(client, msg, prefix);
if (usage) return prefixLength;
return msg.content.slice(prefixLength).split(" ")[0].toLowerCase();
};

exports.getLength = (client, msg, prefix) => {
if (client.config.prefixMention === prefix) {
return prefix.exec(msg.content)[0].length + 1;
}
return prefix.exec(msg.content)[0].length;
};

exports.getPrefix = (client, msg) => {
if (client.config.prefixMention.test(msg.content)) {
return client.config.prefixMention;
}
const prefix = msg.guildConf.prefix;
if (prefix instanceof Array) {
prefix.forEach((prefix) => {
if (msg.content.startsWith(prefix)) prefix = RegExp(`^${prefix}`);
else prefix = false;
});
return prefix;
}
if (msg.content.startsWith(prefix)) return new RegExp(`^${prefix}`); // eslint-disable-line
return false;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "komada",
"version": "0.17.1",
"version": "0.17.2",
"author": "Evelyne Lachance",
"description": "Komada: Croatian for 'pieces', is a modular bot system including reloading modules and easy to use custom commands.",
"main": "app.js",
Expand Down