Created
January 12, 2014 04:55
-
-
Save RyanHirsch/8381114 to your computer and use it in GitHub Desktop.
IRC to MongoDB logger
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 mongoose = require('mongoose'), | |
util = require('util'), | |
config = require('./config.json'); | |
var connection_string = util.format( | |
'mongodb://%s:%s@%s:%d/%s', | |
config.mongo.user, | |
config.mongo.password, | |
config.mongo.hostname, | |
config.mongo.port, | |
config.mongo.database | |
); | |
mongoose.connect(connection_string); | |
var IRCLog = mongoose.model('IRCLog', { | |
ts: Date, | |
server: String, | |
channel: String, | |
message: String, | |
nick: String | |
}); | |
var addLogItem = function(data) { | |
var item = new IRCLog(data); | |
item.save(function(err) { | |
if(err) { | |
console.log(err); | |
} | |
}); | |
}; | |
exports.log = { | |
add: addLogItem | |
}; |
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 irc = require('irc'), | |
config = require('./config.json'), | |
util = require('util'), | |
db = require('./db'); | |
var client = new irc.Client(config.irc.server, config.irc.nick, { | |
channels: config.irc.channels | |
}); | |
client.addListener('error', function(message) { | |
console.log('error: ' + message); | |
}); | |
client.addListener('message', function(from, to, message) { | |
console.log(util.format('%s => %s: %s', from, to, message)); | |
db.log.add({ | |
ts: new Date(), | |
server: this.opt.server, | |
channel: to, | |
nick: from, | |
message: message | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now in GitHub - https://github.com/RyanHirsch/irc-logger