diff --git a/install b/install index 2279732..4e7573d 100755 --- a/install +++ b/install @@ -14,7 +14,7 @@ then exit 1 fi -npm install googlemaps feedparser node-units tvdb crypto-js method-override 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash +npm install googlemaps feedparser node-units tvdb method-override 500px process async wordnik node-uuid underscore request sandbox express moment-timezone moment jade databank databank-redis ent passport passport-local password-hash connect-flash cd public/ wget https://github.com/twbs/bootstrap/releases/download/v3.3.2/bootstrap-3.3.2-dist.zip diff --git a/modules/crypto/README.md b/modules/crypto/README.md index d037b42..e866796 100644 --- a/modules/crypto/README.md +++ b/modules/crypto/README.md @@ -7,15 +7,9 @@ This module calculates different hashes or ciphertexts for some algorithms. ### Commands -#### ~md5 [text] -Calculate the MD5 hash of the given text. +#### ~hash [algorithm] [text] +Calculate the hash of the given text using [algorithm]. -#### ~sha1 [text] -Calculate the SHA1 hash of the given text. - -#### ~sha256 [text] -Calculate the SHA256 hash of the given text. - -#### ~aes "[text]" "[key]" -Calculates the hash of the given text. +#### ~random [number] +Gives [number] bytes of cryptographically strong pseudo-random data as hex string. diff --git a/modules/crypto/crypto.js b/modules/crypto/crypto.js index 842b720..2d25aac 100644 --- a/modules/crypto/crypto.js +++ b/modules/crypto/crypto.js @@ -3,32 +3,40 @@ * Description: Allows the magic of cryptography to take place. */ -var MD5 = require('crypto-js/md5'); -var SHA1 = require('crypto-js/sha1'); -var SHA256 = require('crypto-js/sha256'); -var SHA512 = require('crypto-js/sha512'); -var AES = require('crypto-js/aes'); +var cr = require('crypto'); var crypto = function(dbot) { this.commands = { - '~md5': function(event) { - event.reply("MD5 hash of "+event.input[1]+" is: "+MD5(event.input[1])); + '~hash': function(event) { + var hash = event.params[1]; + try { + var h = cr.createHash(hash); + var tohash = event.params.splice(2, event.params.length-1).join(' '); + h.update(tohash); + event.reply(hash+" of \""+tohash+"\" is: "+h.digest('hex')); + } catch(err) { + event.reply(err); + } }, - '~sha1': function(event) { - event.reply("SHA1 hash of "+event.input[1]+" is: "+SHA1(event.input[1])); - }, - '~sha256': function(event) { - event.reply("SHA256 hash of "+event.input[1]+" is: "+SHA256(event.input[1])); - }, - '~aes': function(event) { - event.reply("AES of "+event.input[1]+" is: "+AES.encrypt(event.input[1],event.input[2])); + '~random': function(event) { + try { + var count = parseInt(event.params[1]); + if(count > 222) { + event.reply("Sorry man, I can't paste that much random data."); + return; + } + cr.randomBytes(count, function(err,buf) { + if(err) { + event.reply(err); + return; + } + event.reply(buf.toString('hex')); + }); + } catch (err) { + event.reply(err); + } } }; - - this.commands['~md5'].regex = /^md5 ([^ ]+)$/; - this.commands['~sha1'].regex = /^sha1 ([^ ]+)$/; - this.commands['~sha256'].regex = /^sha256 ([^ ]+)$/; - this.commands['~aes'].regex = /^aes "(.*)" "(.*)"$/; }; exports.fetch = function(dbot) { diff --git a/modules/ctcp/ctcp.js b/modules/ctcp/ctcp.js index fe02dde..073ef77 100644 --- a/modules/ctcp/ctcp.js +++ b/modules/ctcp/ctcp.js @@ -1,22 +1,36 @@ var ctcp = function(dbot) { - var commands = { - "\x01VERSION\x01": function(event) { - // the current client version - event.replyNotice("\x01VERSION " + dbot.config.version + "\x01"); - }, - "\x01CLIENTINFO\x01": function(event){ - // a list of all supported CTCP commands - event.replyNotice("\x01CLIENTINFO SOURCE VERSION USERINFO\x01"); - }, - "\x01SOURCE\x01": function(event){ - event.replyNotice("\x01SOURCE https://github.com/reality/depressionbot\x01"); - }, - "\x01USERINFO\x01": function(event){ - // a "witty" saying set by the user - event.replyNotice("\z01USERINFO " + dbot.config.name + "\x01"); + this.listener = function(event) { + var matches = event.message.match(/\u0001[\w]+\u0001/); + if(matches) { + // We need the CTCP command + var question = matches[0]; + // Cut \u0001 characters from command + question = question.slice(1,question.length-1); + switch(question) { + case 'CLIENTINFO': + event.replyNotice("\u0001CLIENTINFO SOURCE VERSION USERINFO\u0001"); + break; + case 'FINGER': + event.replyNotice("\u0001FINGER STOP FINGERING ME BRO\u0001"); + break; + case 'SOURCE': + event.replyNotice("\u0001SOURCE "+dbot.config.repoRoot+"\u0001"); + break; + case 'TIME': + var d = new Date(); + event.replyNotice("\u0001TIME "+d.toISOString()+"\u0001"); + break; + case 'USERINFO': + event.replyNotice("\u0001USERINFO "+dbot.config.name+"\u0001"); + break; + case 'VERSION': + event.replyNotice("\u0001VERSION "+dbot.config.version+"\u0001"); + break; + default: + event.replyNotice("\u0001"+question+" Idk what you want. Try CLIENTINFO.\u0001"); + } } - } - this.commands = commands; + }; this.on = 'PRIVMSG'; };