diff --git a/commandmanager.js b/commandmanager.js index 443793b..fe552fb 100644 --- a/commandmanager.js +++ b/commandmanager.js @@ -32,6 +32,7 @@ module.exports.loadCommands = function() { addCommand('Ping', 'ping', undefined, 'ping', 'returns round trip to discords servers', false, Commands.ping); addCommand('Cat', 'cat', undefined, 'cat', 'returns a picture of a cat', false, Commands.cat); addCommand('Dog', 'dog', undefined, 'dog', 'returns a picture of a dog', false, Commands.dog); + addCommand('Undo', 'undo', undefined, 'undo', 'deletes last message sent by Jeffery from the channel the command was issued in', false, Commands.undo); //rule commands addCommand('Rules', 'rules', undefined, 'rules', 'returns all the rules for the server the command was issued on', false, RuleCommands.rules); diff --git a/commands/commands.js b/commands/commands.js index 22887d6..720ac68 100644 --- a/commands/commands.js +++ b/commands/commands.js @@ -51,3 +51,17 @@ module.exports.dog = async function(message, msg, args, discordclient) { em.setImage(output); message.channel.send(em); } + +module.exports.undo = function (message, msg, args, discordclient) { + message.channel.fetchMessages({ limit: 50 }) + .then((_messages) => { + var messages = _messages.array(); + for (var i = 0; i < messages.length; i++) { + if (messages[i].author.id === discordclient.user.id) { + messages[i].delete(); + return; + } + } + }) + .catch(); +}; diff --git a/helper.js b/helper.js index d24ce58..c1a6054 100644 --- a/helper.js +++ b/helper.js @@ -9,9 +9,9 @@ const fs = require('fs'); const request = require('request'); const Discord = require('discord.js'); -module.exports.requestPromise = function (url) { +module.exports.requestPromise = function(url) { return new Promise((resolve, reject) => { - request(url, function (error, response, body) { + request(url, function(error, response, body) { if (error) { reject(error); } @@ -19,3 +19,7 @@ module.exports.requestPromise = function (url) { }); }); } + +module.exports.isUserAdmin = function(message) { + +}