IRC KickBan Bot
February 4, 2012
I wrote a simple IRC bot in Python. Whenever a user joins a channel, it immediately bans and kicks the user. It is useful for channel squatting and pranks. It can be easily expanded so that it kickbans under certain conditions.
You can PM the bot to make it join or leave a channel.
For example, /msg iKickban join #testchannel, /msg iKickban leave #testchannel
#!/usr/bin/python2
import socket, string, re
host="irc.freenode.net"
port=6667
nick="iKickban"
ident="iKickban"
realname="kickban"
readbuffer=""
kickmsg="hi"
channels=["#channel1", "#channel2"] #list of channnels to auto join
owner="daeyun" #the bot will ignore commands from other users
s=socket.socket()
s.connect((host,port))
s.send("NICK %s\n" % nick)
s.send("USER %s %s abc :%s\n" % (ident, host, realname))
for channel in channels:
s.send("JOIN %s\n" % channel)
while 1:
readbuffer=readbuffer+s.recv(1024)
temp=string.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
line=string.rstrip(line)
line=string.split(line)
try:
m = re.search(':([0-9a-zA-z-_\'`\^]+)!', line[0])
user=m.group(1)
except:
pass
if line[0]=="PING":
s.send("PONG %s\n" % line[1])
elif line[1]=="PRIVMSG" and line[2]==nick:
try:
if user==owner:
if line[3]==":join":
s.send("JOIN %s\n" % line[4])
if line[3]==":leave":
s.send("PART %s\n" % line[4])
except:
pass
elif line[1]=="JOIN":
if user!=nick:
channel=line[2]
s.send("MODE %s +b %s\n" % (channel,user))
s.send("KICK %s %s :%s\n" % (channel,user,kickmsg))
