Advertisement
thefinn93

Basic bot

Apr 29th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import socket
  5. import string
  6. import random
  7.  
  8. s=socket.socket( )
  9.  
  10. nickfile = "/home/finn/projects/irc/usernames.txt"
  11.  
  12. def nickgen():
  13.     if nickfile:
  14.         nicks = open(nickfile).read().split("\n")
  15.         nick = nicks[random.randint(0,len(nicks)-1)]
  16.     else:
  17.         chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  18.         nick = ""
  19.         for i in range(0,7):
  20.             nick = nick + chars[random.randint(0,len(chars)-1)]
  21.     return nick
  22.  
  23. def send(msg):
  24.     print ">" + msg
  25.     s.send(msg)
  26.  
  27.  
  28. def process(incoming):
  29.     print "<" + incoming
  30.     line=incoming.split(":")[1].split(" ")
  31.     if line[1] == "PRIVMSG": # Private message
  32.         user = line[0].split('!')[0].split(':')[0]
  33.         message = incoming.split(':',2)[2]
  34.         if message == "\01VERSION\01": # Version
  35.             print "<" + user + " wants to know what version we are"
  36.             send("PRIVMSG " + user + " :__________\r\n")
  37.             send("PRIVMSG " + user + " :< the game >\r\n")
  38.             send("PRIVMSG " + user + " : ----------\r\n")
  39.             send("PRIVMSG " + user + " :        \\   ^__^\r\n")
  40.             send("PRIVMSG " + user + " :         \\  (oo)\\_______\r\n")
  41.             send("PRIVMSG " + user + " :            (__)\\       )\\/\\\r\n")
  42.             send("PRIVMSG " + user + " :                ||----w |\r\n")
  43.             send("PRIVMSG " + user + " :                ||     ||\r\n")
  44.         else:
  45.             if user == "toastpenis":
  46.                 print "Commander sez:" + message
  47.                 send(message + "\r\n")
  48.             else:
  49.                 print "<" + user + ": " + message
  50.                 send("PRIVMSG " + user + " :\02" + message + "\02 to you to!\r\n")
  51.  
  52. HOST="power.anonops.eu"
  53. PORT=6667
  54. NICK=nickgen()
  55. IDENT=NICK
  56. REALNAME="durrrpp"
  57. CHANNELS=[]
  58. readbuffer=""
  59.  
  60. s.connect((HOST, PORT))
  61. send("NICK %s\r\n" % NICK)
  62. send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
  63. for channel in CHANNELS:
  64.     send("JOIN %s\r\n" % channel)
  65.  
  66. while 1:
  67.     readbuffer=readbuffer+s.recv(1024)
  68.     temp=string.split(readbuffer, "\n")
  69.     readbuffer=temp.pop( )
  70.  
  71.     for line in temp:
  72.         line=string.rstrip(line)
  73. #        line=string.split(line)
  74.         process(line)
  75.         if line.split(" ")[1] == "MODE":
  76.             send("PRIVMSG toastpenis :yo\r\n")
  77.        
  78.         if(string.split(line)[0]=="PING"):
  79.             send("PONG %s\r\n" % string.split(line)[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement