Advertisement
Guest User

Untitled

a guest
May 5th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. from socket import *
  4.  
  5. #################################################
  6.  
  7. HOST = "irc.freenode.net" # Needed for the initial socket connection
  8. PORT = 6667 # This is the normal port used for IRC connections
  9. USERNAME = "Bubblebot" # Nick of the bot
  10. REALNAME = "Bubble bot" # Realname to pass to the IRC server
  11. PASS = "bubblebot" # Password for authentication to the server
  12. CHANNELS = "#ubuntu-beginners-dev"
  13.  
  14. irc_socket = socket(AF_INET, SOCK_STREAM) # This creates the socket used for connection
  15. irc_socket.connect((HOST, PORT)) # This makes the actual connection
  16.  
  17. def send(data): # This function is defined for sending a message to the server
  18. irc_socket.send(data + '\r\n')
  19. print "Sent: \"%s\"" % data
  20.  
  21. def receive(buffer_size = 1024): # This function is defined for receiving messages from the server
  22. return irc_socket.recv(buffer_size)
  23.  
  24. ################### IRC FUNCS ###################
  25.  
  26. class functions():
  27.  
  28. def join(self, channel, key=""):
  29. # Command: JOIN
  30. # Parameters: <channel>{,<channel>} [<key>{,<key>}]
  31. send("JOIN %s, %s" % (channel, key))
  32.  
  33.  
  34. irc_funcs = functions()
  35.  
  36. ################# END IRC FUNCS #################
  37.  
  38. # The correct order for registering a connection with an IRC server according to RFC 1459 is as follows:
  39. # 1) Pass message
  40. # 2) Nick message
  41. # 3) User message
  42.  
  43. # Pass message
  44. # Command: PASS
  45. # Parameters: <password>
  46. send("PASS %s" % PASS)
  47.  
  48. # Nick message
  49. # Command: NICK
  50. # Parameters: <nickname> [<hopcount>]
  51. send("NICK %s" % USERNAME)
  52.  
  53. # User message
  54. # Command: USER
  55. # Parameters <username> [<hostname>] [<servername>] <realname>
  56. send("USER %s NULL NULL :%s" % (USERNAME, REALNAME))
  57.  
  58. received = ""
  59. while "Thank you for" not in received:
  60. received = receive()
  61. print received
  62.  
  63. irc_funcs.join(CHANNELS)
  64.  
  65. while True:
  66. received = receive()
  67. print received
  68.  
  69. if "PERL!!!" in received:
  70. send("PRIVMSG %s PYTHON!!!" % CHANNELS)
  71.  
  72. if "!say" in received:
  73. message = received.split(":")[2].split("!say ")[1]
  74. print message
  75. message = message.replace(" ", "\ ")
  76. print message
  77. send("PRIVMSG %s %s" % (CHANNELS, message))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement