Added Undo command

This commit is contained in:
plane000
2018-05-21 11:48:19 +01:00
parent d662ed6366
commit 2d1fd9e37a
3 changed files with 21 additions and 2 deletions

View File

@@ -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);

View File

@@ -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();
};

View File

@@ -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) {
}