Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- from socket import *
- #################################################
- HOST = "irc.freenode.net" # Needed for the initial socket connection
- PORT = 6667 # This is the normal port used for IRC connections
- USERNAME = "Bubblebot" # Nick of the bot
- REALNAME = "Bubble bot" # Realname to pass to the IRC server
- PASS = "bubblebot" # Password for authentication to the server
- CHANNELS = "#ubuntu-beginners"
- irc_socket = socket(AF_INET, SOCK_STREAM) # This creates the socket used for connection
- irc_socket.connect((HOST, PORT)) # This makes the actual connection
- def send(data): # This function is defined for sending a message to the server
- irc_socket.send(data + "\r\n")
- print "Sent: \"%s\"" % data
- def receive(buffer_size = 1024): # This function is defined for receiving messages from the server
- return irc_socket.recv(buffer_size)
- ################### IRC FUNCS ###################
- class functions():
- def join(self, channel, key=""):
- # Command: JOIN
- # Parameters: <channel>{,<channel>} [<key>{,<key>}]
- send("JOIN %s, %s" % (channel, key))
- irc_funcs = functions()
- ################# END IRC FUNCS #################
- # The correct order for registering a connection with an IRC server according to RFC 1459 is as follows:
- # 1) Pass message
- # 2) Nick message
- # 3) User message
- # Pass message
- # Command: PASS
- # Parameters: <password>
- send("PASS %s" % PASS)
- # Nick message
- # Command: NICK
- # Parameters: <nickname> [<hopcount>]
- send("NICK %s" % USERNAME)
- # User message
- # Command: USER
- # Parameters <username> [<hostname>] [<servername>] <realname>
- send("USER %s NULL NULL :%s" % (USERNAME, REALNAME))
- received = ""
- while "Thank you for" not in received:
- received = receive()
- print received
- irc_funcs.join(CHANNELS)
- while True:
- received = receive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement