Created
February 21, 2013 01:28
-
-
Save agrif/5001188 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
import hesperus | |
import irc | |
import asyncore | |
import sys | |
# | |
# the irc node | |
# | |
irc = irc.IRCHandler.connect_to('irc.freenode.net', 6667) | |
node = hesperus.Node(('localhost', 3000)) | |
def on_send_message(node, action, message, headers, data): | |
irc.send_command('privmsg', '#overviewer', data['message']) | |
def on_get_message(channel, message): | |
node.downstream.channel_recv(dict(message=message)) | |
node.register_event('channel.recv', sender='channel_recv', encoder=hesperus.bdumps) | |
node.register_event('channel.send', handler=send_message, decoder=hesperus.bloads) | |
irc.on_get_message = on_get_message | |
irc.send_command('nick', 'hesperus') | |
irc.send_command('user', 'hesperus', 0, '*', 'Hesperus') | |
irc.send_command('join', '#overviewer') | |
asyncore.loop() | |
# | |
# the fnord node | |
# | |
def on_recv_message(node, action, message, headers, data): | |
txt = data['message'].lower() | |
if 'fnord' in txt: | |
node.upstream.channel_send(dict(message=txt.replace('fnord', ''))) | |
client = hesperus.Node() | |
client.connect('localhost', 3000) | |
client.register_event('channel.recv', handler=on_recv_message, decoder=hesperus.bloads) | |
client.register_event('channel.send', sender='channel_send', encoder=hesperus.bdumps) | |
asyncore.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment