Created
October 4, 2013 17:44
-
-
Save codatory/6829794 to your computer and use it in GitHub Desktop.
Node.js based irc bot that checks spelling and corrects people. Highly annoying, but by request.
This file contains 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
{ | |
"author": "Alex Conner <[email protected]>", | |
"name": "spellbot", | |
"dependencies": { | |
"wordsworth": ">=0.1.0", | |
"irc": ">=0.3.6" | |
} | |
} |
This file contains 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'); | |
var sp = require('wordsworth').getInstance(); | |
var client = new irc.Client('chat.freenode.net', 'zzzz-spellbot', { channels: ['#citrt']}); | |
var fs = require('fs'); | |
function init(){ | |
client.say('#citrt','Loading dictionary'); | |
sp = require('wordsworth').getInstance(); | |
sp.initialize('seed.txt', 'training.txt', function(){ | |
client.say('#citrt','Dictionary loaded.'); | |
}); | |
} | |
init(); | |
function learn(word){ | |
fs.appendFile('seed.txt', word + "\r\n"); | |
init(); | |
} | |
client.addListener('message', function(from, to, message){ | |
var cmd = message.match(/^learn (.*)/) | |
if (cmd) { | |
learn(cmd[1]); | |
} else { | |
var errors = sp.analyze(message); | |
console.log("Message from " + from); | |
Object.keys(errors).forEach(function(wrong){ | |
var right = errors[wrong]; | |
if (typeof(right[0]) == 'undefined'){ | |
client.say('#citrt', from + ": I don't know the word " + wrong); | |
} else { | |
client.say('#citrt', from + ": I think what you meant by " + wrong + " was " + right[0]); | |
} | |
}); | |
} | |
}); | |
client.addListener('error', function(message) { | |
console.log('error: ', message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment