Advertisement
thefinn93

Untitled

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