Advertisement
triclops200

Tribot200

Jun 4th, 2011
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. #---------------bot.py----------------#
  2. import socket
  3. import string
  4. import commands
  5. import varsl
  6. varsl.channel = raw_input("Give me a channel: ")
  7. channel = varsl.channel
  8. print varsl.channel
  9. network = 'irc.freenode.net'
  10. nick="Tribot200"
  11. port = 6667
  12. irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  13. irc.connect ( ( network, port ) )
  14. irc.send ( 'NICK %s\r\n'%nick )
  15. irc.send ( 'USER %s %s %s :%s\r\n' %(nick,nick,nick,nick) )
  16. irc.send ( 'JOIN %s\r\n' %channel)
  17. irc.send ( "PRIVMSG "+channel+" :Triclops200's bot is in the house!\r\n" )
  18. varsl.irc=irc
  19. print "connected"
  20.  
  21.  
  22. a=True
  23. data=""
  24. f = open("logs/"+channel,"a")
  25. while(a):
  26.        
  27.     data += irc.recv ( 4096 )
  28.     temp = string.split(data,"\n")
  29.     data = temp.pop()
  30.     for line in temp:
  31.         line = string.rstrip(line)
  32.         line = string.split(line)
  33.         if(string.lower(line[0])=="ping"):
  34.             irc.send("PONG "+line[1])
  35.             print "<PING>"
  36.             line=("hi","bye","nye")
  37.             command=""
  38.         if (string.lower(line[1])=="kick"):
  39.             irc.send ( 'JOIN %s\r\n' %varsl.channel)
  40.         try:           
  41.             if(string.lower(line[1])=="privmsg"):
  42.                 command=""             
  43.                 user=string.split(line[0],"!")[0].lstrip(':')              
  44.                 message= "<"+user+">: "
  45.                 say = ""
  46.                 for x in range(3,len(line)):
  47.                     say+=line[x]+" "               
  48.                 f.write(message+say.lstrip(":")+"\r\n")
  49.                 f.flush()
  50.                 print message+say.lstrip(":")
  51.                 if(line[3].startswith(":-#")):
  52.                
  53.                     command = string.lower("cmd_"+string.split(line[3],"#")[1])
  54.                     if(command=="cmd_reload" and user=="triclops200"):
  55.                         channel=varsl.channel
  56.                         reload(varsl)
  57.                         reload(commands)
  58.                         varsl.channel = channel
  59.                         varsl.irc = irc                
  60.                     print "<"+string.upper(command)+">: USER: "+user
  61.                     varsl.user = user
  62.                     varsl.line = line
  63.                     a=commands.processcommand(command)
  64.         except Exception as inst:
  65.             print inst
  66.  
  67. irc.send ( "PART "+varsl.channel+"\r\n" )
  68. irc.send ( 'QUIT\r\n' )
  69.  
  70.  
  71. irc.close()
  72. #------------------------------------------#
  73. #-----------------commands.py--------------#
  74. import socket
  75. import string
  76. import varsl
  77. global channel
  78. global irc
  79. global line
  80. global user
  81. global owner
  82. owner = varsl.owner
  83.  
  84. def cmd_ping():
  85.     print irc  
  86.     irc.send("PRIVMSG "+channel+" :PONG\r\n")
  87.    
  88. def cmd_say():     
  89.     say="" 
  90.     if(len(line)<5):
  91.         irc.send("PRIVMSG "+channel+" :Usage: say <msg>\r\n")
  92.         return False
  93.     for x in range(4,len(line)):
  94.         say+=line[x]+" "
  95.     irc.send("PRIVMSG "+channel+" :"+say+"\r\n")
  96.    
  97. def cmd_disconnect():
  98.     if(user==owner):
  99.         return True
  100.     else:
  101.         irc.send("PRIVMSG "+channel+" :"+user+", you are not my master.\r\n")
  102. def cmd_switch():
  103.     global channel
  104.     if(len(line)<5):
  105.         irc.send("PRIVMSG "+channel+" :Usage: -#switch <channel>\r\n")
  106.         return False
  107.     if(user==owner):
  108.         irc.send ( "PART "+channel+"\r\n" )
  109.         irc.send ( 'JOIN %s\r\n' %line[4])
  110.         varsl.channel=line[4]
  111.         channel = line[4]
  112.     else:
  113.         irc.send("PRIVMSG "+channel+" :"+user+", you, are not my master.\r\n")
  114. def cmd_hello():
  115.     irc.send("PRIVMSG "+user+" :Hello there, "+user+"\r\n")
  116. def cmd_reload():
  117.     if(user==owner):
  118.         irc.send("PRIVMSG "+channel+" :"+user+": Reloaded!.\r\n")
  119. def cmd_cutwire():
  120.     if(len(line)<5):
  121.         irc.send("PRIVMSG "+channel+" :Usage: -#cutwire <letter>\r\n")
  122.         return False
  123.     irc.send("PRIVMSG "+channel+" :$"+line[4]+"\r\n")
  124.  
  125.    
  126.  
  127. def processcommand(cmd):
  128.     global channel
  129.     global line
  130.     global user
  131.     global irc 
  132.     channel = varsl.channel
  133.     line = varsl.line
  134.     user = varsl.user
  135.     irc = varsl.irc
  136.     a= not eval(cmd)()
  137.     return a
  138. #----------------------------------------#
  139. #--------------varsl.py------------------#
  140. channel= ""
  141. irc=""
  142. user=""
  143. line=""
  144. owner="triclops200"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement