Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Commit

Permalink
Added purge
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco authored and Remco committed Dec 20, 2015
1 parent d0fd076 commit 7209c5e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
49 changes: 42 additions & 7 deletions discord_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":{
Expand All @@ -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!",
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DougleyBot",
"version": "1.3.5",
"version": "1.3.6",
"description": "Bot for Discord app",
"readme": "README.md",
"maintainers": [],
Expand Down

0 comments on commit 7209c5e

Please sign in to comment.