Created
February 26, 2012 07:41
-
-
Save wraithan/1914819 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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