3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 12:42:51 +01:00
dbot/modules/crypto/crypto.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-12-26 07:44:13 +01:00
/**
2013-12-26 07:59:56 +01:00
* Module Name: Crypto
* Description: Allows the magic of cryptography to take place.
2013-12-26 07:44:13 +01:00
*/
var cr = require('crypto');
2013-12-26 07:44:13 +01:00
var crypto = function(dbot) {
this.commands = {
'~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);
}
2013-12-26 07:44:13 +01:00
},
2015-08-19 21:11:33 +02:00
'~randomdata': 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);
}
2013-12-26 07:44:13 +01:00
}
};
};
exports.fetch = function(dbot) {
return new crypto(dbot);
};