Skip to content

Instantly share code, notes, and snippets.

@wraithan
Created February 26, 2012 07:41
Show Gist options
  • Select an option

  • Save wraithan/1914819 to your computer and use it in GitHub Desktop.

Select an option

Save wraithan/1914819 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var redis_lib = require('redis');
var pub = redis_lib.createClient();
module.exports = {
send_privmsg: function(to, message) {
return pub.publish('out', JSON.stringify({
version: 1,
type: 'privmsg',
data: {
to: to,
message: message
},
}));
},
register_commands: function(service, commands) {
console.log('called')
sub = redis_lib.createClient();
sub.subscribe('in');
sub.on('message', function(channel, message){
msg = JSON.parse(message)
if (msg.version == 1 && msg.type == 'privmsg') {
console.log('message received');
if (msg.data.message == "commands") {
console.log('commands message received');
for (var command in commands) {
this.send_privmsg(msg.data.sender,
service + ": " +
command.name + " - " +
command.description);
}
}
}
});
return sub
},
load_config: function(name) {
return JSON.parse(fs.readFileSync(name, 'utf8'));
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment