From 804510ec47b4473d55e2ecf1ce319550ab4272de Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Thu, 4 Apr 2019 23:12:14 +1100 Subject: [PATCH] DM changes.. --- index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a17b030..7245c04 100644 --- a/index.js +++ b/index.js @@ -93,7 +93,7 @@ client.on("message", (msg) => { function onMessage(msg, again = true) { if (msg.channel.type = "dm") { - doCommand(msg, "") + doPMCommand(msg, "") } else { @@ -116,6 +116,26 @@ function onMessage(msg, again = true) { } } +function doPMCommand(msg, prefix) { + const command = message.substring(prefix.length).split(/[ \n]/)[0].trim().toLowerCase() + msg.suffix = message.substring(prefix.length + command.length).trim() + + var cmds = client.cachedcommands.filter(cmd => cmd.alias == command); + if (cmds.length > 0) { + console.log("CMD:".green + " ".reset + msg.author.user.username.bold + "#".reset + msg.author.user.discriminator.reset + " " + prefix.grey + command.green.bold + " ".reset + msg.suffix + " | PM") + var reqcommand = require('./commands/' + cmds[0].file) + msg.react('✅') + try { + reqcommand.command(client, msg) + } catch (err) { + console.error('There was an error running: ' + command); + console.error(err.stack); + } + } + + delete require.cache[require.resolve('./commands/' + cmds[0].file)] +} +} function doCommand(msg, prefix) { var message = msg.cleanContent