Created
February 9, 2012 10:28
-
-
Save SirPepe/1779121 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
irc = require 'irc' | |
http = require 'http' | |
# Client erstellen | |
bot_name = 'Hixie' | |
bot_channels = ['#webhonks'] | |
bot = new irc.Client 'irc.freenode.net', bot_name, { | |
userName: 'hixie' | |
realName: 'Ein Bot in CoffeeScript', | |
channels: bot_channels | |
} | |
# Nach q googlen und den ersten Link ausspucken | |
google = (q, success_callback, error_callback) -> | |
options = { | |
host: 'www.google.com' | |
port: 80 | |
path: '/' | |
} | |
http.get(options, (res) -> | |
success_callback res; | |
).on 'error', error_callback; | |
# Kommendoliste | |
commands = { | |
'!js' : (name, channel, command, args, original_msg) -> | |
args = args.join '' | |
bot.say channel, name + ', ich suche JavaScript-Docs für "' + args + '". Kleinen Moment...' | |
success_callback = (link) -> | |
bot.say channel, name + ': ' + link | |
error_callback = (err) -> | |
bot.say channel, name + ', ich habe aus diesem Grund nichts gefunden: ' + err.message | |
google 'mdn ' + args, success_callback, error_callback | |
} | |
# Nachrichten empfangen, in denen der Bot erwähnt wird | |
bot.addListener 'message', (from, to, msg) -> | |
tokens = msg.split /\s/ | |
command = tokens[0] | |
args = tokens.slice 1 | |
console.log tokens, command, args | |
if command of commands | |
commands[command].call null, from, to, command, args, msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment