ID:185991
 
I just finished writing the basics to a python irc bot.
So far you can specify on startup what server, port, and channel to join, plus nickname. There is also a !quit and !info command.

Im adding more commands when I get home from school today, does anyone want the source to this bot? It took me about 3 days to fix a stupid problem with data transfers so if you use this it may save you some time.
It sounds like a neat project to me. I'd like to see the source.
In response to PirateHead (#1)
Me too also.
In response to Artekia (#2)
Ok, ill post the source when I get home.
import sys
import socket
import string
import time

HOST="rsrevolution.ath.cx"
PORT=65015
NICK="Anaconda"
IDENT="Anaconda"
REALNAME="Python Bot"
CHANNEL ="#anaconda"
PASSWORD = ""
data = ""
SAY=""
EMOTE=""
NAME=""
JOINTHIS=""

HOST = raw_input("Enter Server Address: ")
PORT = input("Enter Port: ")
NICK = raw_input("Enter Bot Nick: ")
CHANNEL = raw_input("Enter Channel to join: ")
PASSWORD = raw_input("Enter password for this session: ")

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((HOST, PORT))
socket.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
socket.send('NICK %s\r\n' % NICK)
socket.send('JOIN %s\r\n' % CHANNEL)
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + NICK + ' Slithering In.\r\n')
print "Connected to irc server. Joining channel."
time.sleep( 2 )

while 1:
data = socket.recv(1024)
print data

############################################################################################
#COMMANDS BELOW#############################################################################
############################################################################################

##########################
#Dont move this! it makes below commands work
if data.split(" ")[1] == "JOIN":
print 'This isnt a command'
elif data.split(" ")[1] == "PART":
print 'This isnt a command'
elif data.startswith("PING"):
socket.send('PONG %s\r\n' % data.split(":")[1])
else:
command=data.split(" ")[3]
command2=data
#########################


#rejoin channel if kicked below
if data.split(" ")[1] == "KICK" and command.startswith(NICK):
socket.send('JOIN %s\r\n' % data.split(" ")[2])


##quit command, quits channel
if data.split(" ")[1] == "PRIVMSG" and command.startswith(':!quit:' + PASSWORD):
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + NICK + ' Slithering Out.\r\n')
time.sleep( 0.2 )
socket.send('PART ' + CHANNEL + '\r\n')
CHANNEL=""


##exit command, exits irc
if data.split(" ")[1] == "PRIVMSG" and command.startswith(':!exit:' + PASSWORD):
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + NICK + ' Slithering Out.\r\n')
time.sleep( 0.2 )
socket.shutdown(2)


##help Command
if data.split(" ")[1] == "PRIVMSG" and command.startswith(":!help"):
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] Commands: !say:, !emote:, !info, !help\r\n')
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] Commands: !exit:<password>, !quit:<password>, !boot:<password>:NAME, !join:<password>:#channel\r\n')
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] All commands do not need a space after them.\r\n')


#Info Command
if data.split(" ")[1] == "PRIVMSG" and command.startswith(":!info"):
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] This bot was created on september 9th 2005 by Jeremy Anderson.\r\n')
time.sleep( 0.2 )
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] Py Bot was written using python.\r\n')


#Emote command, Example: !emote: Hisses at you
if data.split(" ")[1] == "PRIVMSG" and command.startswith(":!emote:"):
EMOTE = data.split(":")[3]
socket.send('PRIVMSG ' + CHANNEL + ' :ACTION ' + EMOTE)


#Say command, must be like this: !say: Hello
if data.split(" ")[1] == "PRIVMSG" and command.startswith(":!say:"):
SAY = data.split(":")[3]
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + SAY)


##Boot command, syntax is !boot <password>:NAME
if data.split(" ")[1] == "PRIVMSG" and command.startswith(':!boot:' + PASSWORD + ':'):
NAME = data.split(":")[4]
REASON = "The bot hisses at you and swallows you whole!\r\n"
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + REASON)
socket.send(':' + NICK + ' KICK ' + CHANNEL + ' ' + NAME)

##join command, syntax is !join <password>:#channel
if data.split(" ")[1] == "PRIVMSG" and command.startswith(':!join:' + PASSWORD + ':'):
JOINTHIS = data.split(":")[4]
socket.send('JOIN ' + JOINTHIS)
CHANNEL=JOINTHIS
socket.send('PRIVMSG ' + CHANNEL + ' :[BOT] ' + NICK + ' Slithering In.\r\n')