[ create a new paste ] login | about

Link: http://codepad.org/P2WdjksA    [ raw code | fork ]

Python, pasted on Jul 25:
import socket

host = ('irc.freenode.net', 6667)
nick = 'somerobot'
channel = '#robotland'

def ircsplit(msg):
        lst = [] if msg and msg[0] == ':' else ['']
        params, colon, trailing = msg.partition(' :')
        lst += params.split() + ([trailing] if colon else [])
        if len(lst) == 1:
                lst += ['']
        return (lst[0], lst[1], lst[2:])

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(host)
f = s.makefile('r+b', 1)
f.write('NICK %s\r\nUSER %s 0 * :%s\r\n' % (nick, nick, nick))

for line in f:
        msg = filter(lambda c: not c in '\r\n', line)
        print msg
        prefix, cmd, args = ircsplit(line)
        if cmd == '001':
                f.write('JOIN %s\r\n' % channel)
        if cmd == 'PING' and len(args) == 1:
                f.write('PONG :%s\r\n' % args[0])
        if cmd == 'PRIVMSG' and len(args) == 2 and args[0] == channel:
                f.write('PRIVMSG %s :%s\r\n' % (channel, args[1]))


Create a new paste based on this one


Comments: