Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---------------bot.py----------------#
- import socket
- import string
- import commands
- import varsl
- varsl.channel = raw_input("Give me a channel: ")
- channel = varsl.channel
- print varsl.channel
- network = 'irc.freenode.net'
- nick="Tribot200"
- port = 6667
- irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
- irc.connect ( ( network, port ) )
- irc.send ( 'NICK %s\r\n'%nick )
- irc.send ( 'USER %s %s %s :%s\r\n' %(nick,nick,nick,nick) )
- irc.send ( 'JOIN %s\r\n' %channel)
- irc.send ( "PRIVMSG "+channel+" :Triclops200's bot is in the house!\r\n" )
- varsl.irc=irc
- print "connected"
- a=True
- data=""
- f = open("logs/"+channel,"a")
- while(a):
- data += irc.recv ( 4096 )
- temp = string.split(data,"\n")
- data = temp.pop()
- for line in temp:
- line = string.rstrip(line)
- line = string.split(line)
- if(string.lower(line[0])=="ping"):
- irc.send("PONG "+line[1])
- print "<PING>"
- line=("hi","bye","nye")
- command=""
- if (string.lower(line[1])=="kick"):
- irc.send ( 'JOIN %s\r\n' %varsl.channel)
- try:
- if(string.lower(line[1])=="privmsg"):
- command=""
- user=string.split(line[0],"!")[0].lstrip(':')
- message= "<"+user+">: "
- say = ""
- for x in range(3,len(line)):
- say+=line[x]+" "
- f.write(message+say.lstrip(":")+"\r\n")
- f.flush()
- print message+say.lstrip(":")
- if(line[3].startswith(":-#")):
- command = string.lower("cmd_"+string.split(line[3],"#")[1])
- if(command=="cmd_reload" and user=="triclops200"):
- channel=varsl.channel
- reload(varsl)
- reload(commands)
- varsl.channel = channel
- varsl.irc = irc
- print "<"+string.upper(command)+">: USER: "+user
- varsl.user = user
- varsl.line = line
- a=commands.processcommand(command)
- except Exception as inst:
- print inst
- irc.send ( "PART "+varsl.channel+"\r\n" )
- irc.send ( 'QUIT\r\n' )
- irc.close()
- #------------------------------------------#
- #-----------------commands.py--------------#
- import socket
- import string
- import varsl
- global channel
- global irc
- global line
- global user
- global owner
- owner = varsl.owner
- def cmd_ping():
- print irc
- irc.send("PRIVMSG "+channel+" :PONG\r\n")
- def cmd_say():
- say=""
- if(len(line)<5):
- irc.send("PRIVMSG "+channel+" :Usage: say <msg>\r\n")
- return False
- for x in range(4,len(line)):
- say+=line[x]+" "
- irc.send("PRIVMSG "+channel+" :"+say+"\r\n")
- def cmd_disconnect():
- if(user==owner):
- return True
- else:
- irc.send("PRIVMSG "+channel+" :"+user+", you are not my master.\r\n")
- def cmd_switch():
- global channel
- if(len(line)<5):
- irc.send("PRIVMSG "+channel+" :Usage: -#switch <channel>\r\n")
- return False
- if(user==owner):
- irc.send ( "PART "+channel+"\r\n" )
- irc.send ( 'JOIN %s\r\n' %line[4])
- varsl.channel=line[4]
- channel = line[4]
- else:
- irc.send("PRIVMSG "+channel+" :"+user+", you, are not my master.\r\n")
- def cmd_hello():
- irc.send("PRIVMSG "+user+" :Hello there, "+user+"\r\n")
- def cmd_reload():
- if(user==owner):
- irc.send("PRIVMSG "+channel+" :"+user+": Reloaded!.\r\n")
- def cmd_cutwire():
- if(len(line)<5):
- irc.send("PRIVMSG "+channel+" :Usage: -#cutwire <letter>\r\n")
- return False
- irc.send("PRIVMSG "+channel+" :$"+line[4]+"\r\n")
- def processcommand(cmd):
- global channel
- global line
- global user
- global irc
- channel = varsl.channel
- line = varsl.line
- user = varsl.user
- irc = varsl.irc
- a= not eval(cmd)()
- return a
- #----------------------------------------#
- #--------------varsl.py------------------#
- channel= ""
- irc=""
- user=""
- line=""
- owner="triclops200"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement