Advertisement
Googleinurl

Hellobot IRC python

Nov 17th, 2013
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #Greets whoever joins the channel.
  3.  
  4. import sys, socket, string
  5.  
  6. if len(sys.argv) != 5:
  7.     print "Usage: ./hellobot.py <host> <port> <nick> <channel>"
  8.     sys.exit(1)
  9.  
  10. HOST = sys.argv[1]
  11. PORT = int(sys.argv[2])
  12. NICK = sys.argv[3]
  13. CHAN = sys.argv[4]
  14. readbuffer = ""
  15.  
  16. s=socket.socket( )
  17. s.connect((HOST, PORT))
  18. s.send("NICK %s\r\n" % NICK)
  19. s.send("USER %s %s bla :%s\r\n" % (NICK, NICK, NICK))
  20. s.send("JOIN :%s\r\n" % CHAN)
  21.  
  22. while 1:
  23.     readbuffer=readbuffer+s.recv(1024)
  24.         temp=string.split(readbuffer, "\n")
  25.         readbuffer=temp.pop( )
  26.  
  27.         for line in temp:
  28.             line=string.rstrip(line)
  29.             line=string.split(line)
  30.        
  31.         try:
  32.             if line[1] == "JOIN":
  33.                 name = str(line[0].split("!")[0])
  34.                 s.send("PRIVMSG %s :%s%s\r\n" % (CHAN, "Welcome, ", name.replace(":","")))
  35.         except(IndexError):
  36.             pass
  37.    
  38.             if(line[0]=="PING"):
  39.                 s.send("PONG %s\r\n" % line[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement