Python IRC bot

By supafreky on Jan 24, 2009

Connects to an IRC server you specify and idles. Basically this is a frame for an IRC bot.

import os
import re
import socket

os.fork()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('irc.kingskrown.com', 6667))

s.send('NICK %s \r\n' % 'py')
s.send('USER %s \'\' \'\' :%s\r\n' % ('svs', 'python'))
s.send('JOIN %s \r\n' % '#illuminati')

while 1:
   buffer = s.recv(512)

   if not buffer:
      break

   regex = re.match('(?i)^PING (:[^ ]+)$', buffer)

   if regex is not None:
      s.send('PONG %s\r\n' % regex.group(1))
      continue

s.close()

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.