Advertisement
thefinn93

Untitled

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