Advertisement
thefinn93

Untitled

May 9th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 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. ## This code is run every time a message is received. Use send(message) to send a message. Pings are handled lower down ##
  24.  
  25. def process(incoming):
  26.     print "<" + incoming
  27.     try:
  28.         line=incoming.split(":")[1].split(" ")
  29.         if line[1] == "PRIVMSG": # Private message
  30.             user = line[0].split('!')[0].split(':')[0]
  31.             message = incoming.split(':',2)[2]
  32.             if message == "\01VERSION\01": # Version
  33.                 print "<" + user + " wants to know what version we are"
  34.                 send("PRIVMSG " + user + " :__________\r\n")
  35.                 send("PRIVMSG " + user + " :< the game >\r\n")
  36.                 send("PRIVMSG " + user + " : ----------\r\n")
  37.                 send("PRIVMSG " + user + " :        \\   ^__^\r\n")
  38.                 send("PRIVMSG " + user + " :         \\  (oo)\\_______\r\n")
  39.                 send("PRIVMSG " + user + " :            (__)\\       )\\/\\\r\n")
  40.                 send("PRIVMSG " + user + " :                ||----w |\r\n")
  41.                 send("PRIVMSG " + user + " :                ||     ||\r\n")
  42.             else:
  43.                 if user == COMMANDER:
  44.                     print "Commander sez:" + message
  45.                     send(message + "\r\n")
  46.                 else:
  47.                     print "<" + user + ": " + message
  48.                     send("PRIVMSG " + user + " :\02" + message + "\02 to you to!\r\n")
  49.  
  50.     except:
  51.           print "What the shit just happened??"
  52.  
  53. ## End ##
  54.  
  55. readbuffer=""
  56.  
  57. import sys
  58. import socket
  59. import string
  60. import random
  61.  
  62. s=socket.socket( )
  63. # nickfile = "/home/finn/Dropbox/projects/irc/usernames.txt"
  64. nickfile = False
  65.  
  66. def send(msg):
  67.     print ">" + msg
  68.     s.send(msg)
  69.  
  70. def login():
  71.     s.send("PRIVMSG thefinn93 :checkin")
  72.  
  73. s.connect((HOST, PORT))
  74. send("NICK %s\r\n" % NICK)
  75. send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
  76. for channel in CHANNELS:
  77.     send("JOIN %s\r\n" % channel)
  78.  
  79. while 1:
  80.     readbuffer=readbuffer+s.recv(1024)
  81.     temp=string.split(readbuffer, "\n")
  82.     readbuffer=temp.pop( )
  83.  
  84.     for line in temp:
  85.         line=string.rstrip(line)
  86. #        line=string.split(line)
  87.         process(line)
  88.         if(string.split(line)[0]=="PING"):
  89.             send("PONG %s\r\n" % string.split(line)[1])
  90.         elif line.split(" ")[1] == "MODE":
  91.             send("PRIVMSG " + COMMANDER + " :Hello\r\n")
  92.             login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement