Created
January 7, 2016 18:49
-
-
Save audstanley/a7981b82435eb26cacb4 to your computer and use it in GitHub Desktop.
Hubot Thing..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by audstanley on 01/06/16. | |
*/ | |
//need to change the path in jsonObj to /home/pi/slackberrypiratebot/json/botlist.json | |
module.exports = function(robot) | |
{ | |
robot.respond(/\/[Rr][Ee][Mm][Oo][Vv][Ee]\s+@(\S+)?/, function(res) | |
{ | |
var role = 'admin'; | |
// console.log(res); | |
if (!robot.auth.hasRole(res.envelope.user, role)) | |
{ | |
console.log('some console log for non-admin command'); | |
} | |
else | |
{ | |
var fs = require('fs'); | |
var _ = require('underscore'); | |
var jf = require('jsonfile'); | |
var util = require('util'); | |
var jsonObj = require('/home/audstanley/slackberrypiratebot/json/botlist.json'); | |
var file = '/home/audstanley/slackberrypiratebot/json/botlist.json'; | |
var bots = jsonObj.bots; | |
var isRemoved = false; | |
console.log("attempting to remove: " + res.match[1]); | |
function removeBot(anObj) { | |
for (var i = anObj.bots.length - 1; i >= 0; i--) { | |
if (anObj.bots[i] == undefined) { | |
delete anObj.bots[i]; | |
console.log("Got to the splice section."); | |
} | |
if (anObj.bots[i].name == res.match[1]) { | |
console.log(anObj.bots[i]); | |
anObj.bots[i] = {"name": undefined}; | |
isRemoved = true; | |
} | |
} | |
if (isRemoved) { | |
res.send('removed ' + res.match[1]); | |
function removeNulls(obj){ | |
var isArray = obj instanceof Array; | |
console.log("running removeNulls function."); | |
for (var k in obj){ | |
if (obj[k]===null) isArray ? obj.splice(k,1) : delete obj[k]; | |
else if (typeof obj[k]=="object") removeNulls(obj[k]); | |
} | |
} | |
removeNulls(anObj.bots); | |
} | |
jf.writeFileSync(file, anObj); | |
return anObj; | |
} | |
removeBot(jsonObj); | |
} | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment