From 7209c5eb86270a3969823f5932f26b5d5ad3a113 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 20 Dec 2015 20:30:42 +0100 Subject: [PATCH] Added purge --- README.md | 2 +- discord_bot.js | 49 ++++++++++++++++++++++++++++++++++++++++++------- package.json | 2 +- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a663ae1..d50610a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # DougleyBot -[![Version](https://img.shields.io/badge/Version-1.3.5-green.svg?style=flat-square)](https://github.com/SteamingMutt/DougleyBot/releases) +[![Version](https://img.shields.io/badge/Version-1.3.6-green.svg?style=flat-square)](https://github.com/SteamingMutt/DougleyBot/releases) [![Status](https://img.shields.io/badge/Status-Ready-green.svg?style=flat-square)]() [![Node](https://img.shields.io/badge/Node-4.2.2-blue.svg?style=flat-square)](http://nodejs.org) [![NPM](https://img.shields.io/badge/NPM-3.5.0-blue.svg?style=flat-square)](http://nodejs.org) diff --git a/discord_bot.js b/discord_bot.js index b43a789..56efe5d 100644 --- a/discord_bot.js +++ b/discord_bot.js @@ -268,10 +268,10 @@ var commands = { process: function(bot, msg, suffix) { var fs = require ("fs"); fs.appendFile('memes.txt', suffix + "\n", function(err) { - + }); bot.sendMessage(msg.channel, "Added '" + suffix + "' as a meme."); - + } }, "saymeme":{ @@ -286,6 +286,41 @@ var commands = { }); } }, + "purge": { + name: "purge", + extendedhelp: "I'll delete a certain ammount of messages.", + process: function(bot, msg, suffix) { + if (msg.isPrivate) { + return; + } + if (!msg.channel.permissionsOf(msg.sender).hasPermission("manageMessages")) { + bot.sendMessage(msg.channel, "Sorry, your permissions doesn't allow that."); + return; + } + if (!msg.channel.permissionsOf(bot.user).hasPermission("manageMessages")) { + bot.sendMessage(msg.channel, "I don't have permission to do that!"); + return; + } + bot.getChannelLogs(msg.channel, suffix, function(error, messages){ + if (error){ + bot.sendMessage(msg.channel, "Something went wrong while fetching logs."); + return; + } else { + CmdErrorLog.info("Beginning purge..."); + var todo = messages.length, + delcount = 0; + for (msg of messages){ + bot.deleteMessage(msg); + todo--; + delcount++; + if (todo === 0){ + bot.sendMessage(msg.channel, "Done! Deleted " + delcount + " messages."); + CmdErrorLog.info("Ending purge"); + return; + }} + } + } + );}}, "kappa": { name: "kappa", description: "Kappa all day long!", @@ -490,16 +525,16 @@ var commands = { try { data = JSON.parse(body); } catch (error) { - console.log(error) + CmdErrorLog.error(error); return; } if(!data){ - console.log(data); + CmdErrorLog.debug(data); bot.sendMessage(msg.channel, "Error:\n" + JSON.stringify(data)); return; } - else if (!data.items || data.items.length == 0){ - console.log(data); + else if (!data.items || data.items.length === 0){ + CmdErrorLog.debug(data); bot.sendMessage(msg.channel, "No result for '" + suffix + "'"); return; } @@ -638,7 +673,7 @@ var commands = { var continuation = function() { var paragraph = sumText.shift(); if (paragraph) { - bot.sendMessage(msg.channel, paragraph, continuation); + bot.sendMessage(msg.channel, paragraph); } }; continuation(); diff --git a/package.json b/package.json index 5aecf66..e653edd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "DougleyBot", - "version": "1.3.5", + "version": "1.3.6", "description": "Bot for Discord app", "readme": "README.md", "maintainers": [],