#!/usr/bin/env python import sys import socket import string import os HOST="irc.freenode.net" PORT=6667 NICK="pyNanobot" IDENT="pyNanobot" OWNER="vileda" REALNAME="NanometasBot" CHANNELINIT='#nanometa' readbuffer="" s=socket.socket( ) s.connect((HOST, PORT)) s.send("NICK %s\r\n" % NICK) s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME)) def parsemsg(msg): complete=msg[1:].split(':',1) #Parse the message into useful data info=complete[0].split(' ') msgpart=complete[1] sender=info[0].split('!') if msgpart[0]=='!' and sender[0]==OWNER: #Treat all messages starting with '`' as command cmd=msgpart[1:].split(' ') channel=string.rstrip(info[2]) command=string.rstrip(cmd[0]) print "got cmd: "+command + " " +channel if cmd[0]=='op': s.send('MODE '+info[2]+' +o '+cmd[1]+'n') if cmd[0]=='deop': s.send('MODE '+info[2]+' -o '+cmd[1]+'n') if cmd[0]=='voice': s.send('MODE '+info[2]+' +v '+cmd[1]+'n') if cmd[0]=='devoice': s.send('MODE '+info[2]+' -v '+cmd[1]+'n') if cmd[0]=='join' and cmd[1]: s.send('JOIN '+cmd[1]+'\r\n') if command=='sayhello': s.send('MSG '+channel+" hello folks!" + '\r\n') print 'MSG '+channel+" hello folks!" + '\r\n' if msgpart[0]=='-' and sender[0]==OWNER : #Treat msgs with - as explicit command to send to server cmd=msgpart[1:] s.send(cmd+'n') print 'cmd='+cmd while 1: readbuffer=readbuffer+s.recv(1024) if(readbuffer.find('PRIVMSG')): parsemsg(readbuffer) temp=string.split(readbuffer, "\n") readbuffer=temp.pop( ) for line in temp: line=string.rstrip(line) line=string.split(line) if(line[0]=="PING"): s.send("PONG %s\r\n" % line[1])