Skip to content

Commit

Permalink
feat(logging): add discord logging with yappybots-addons
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Dec 16, 2017
1 parent 7e8a790 commit 5c944c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WEB_PORT=
DISCORD_TOKEN=
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
DISCORD_CHANNEL_LOGGING=

DB_URL=

Expand Down
25 changes: 20 additions & 5 deletions lib/Discord/Modules/RunCommand.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
const Module = require('../Module');
const Logger = require('yappybots-addons').discord.logger;
let logger;

class RunCommandModule extends Module {
constructor(bot) {
super(bot);
logger = new Logger(bot, 'command');
}

get priority() {
return 10;
}

run(msg, args, next, command) {
let bot = this.bot;
let perms = bot.permissions(msg);
const bot = this.bot;
const perms = bot.permissions(msg);
let cmd;

if (bot.commands.has(command)) {
Expand All @@ -17,16 +24,24 @@ class RunCommandModule extends Module {
} else {
return next();
}

if (perms < cmd.conf.permLevel) return cmd.commandError(msg, `Insufficient permissions! Must be **${cmd._permLevelToWord(cmd.conf.permLevel)}** or higher`);
if (msg.channel.type === 'dm' && cmd.conf.guildOnly) return cmd.commandError(msg, `You can only run **${cmd.help.name}** in a guild.`);

const hasPermission = perms >= cmd.conf.permLevel;

logger.message(msg);

if (!hasPermission) return cmd.commandError(msg, `Insufficient permissions! Must be **${cmd._permLevelToWord(cmd.conf.permLevel)}** or higher`);

try {
let commandRun = cmd.run(msg, args);
if (commandRun && commandRun.catch) {
commandRun.catch(e => cmd.commandError(msg, e));
commandRun.catch(e => {
logger.error(msg, e);
return cmd.commandError(msg, e);
});
}
} catch (e) {
logger.error(msg, e);
cmd.commandError(msg, e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"snekfetch": "^3.5.1",
"snyk": "^1.42.6",
"winston": "^2.4.0",
"yappybots-addons": "git+https://github.com/YappyBots/yappy-addons.git"
"yappybots-addons": "github:YappyBots/yappy-addons"
},
"devDependencies": {
"discord.js-docgen": "github:hydrabolt/discord.js-docgen",
Expand Down

0 comments on commit 5c944c7

Please sign in to comment.