Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author: Hairr
- import socket
- class Bot: # Adding bot element
- def __init__(self): # Information to login in the account/IRC
- self.NICK = "Nickname" # Nickname
- self.USER = "Username" # Username
- self.PASS = "Password" # Password
- self.HOST = "irc.freenode.net" # IRC host
- self.PORT = 6667 # IRC port
- self.IN_CHANNEL = False # Checks if you are in channel
- self.CHANNEL = '##hairybot' # Channel that logs in
- def connect(self): # Connecting to IRC
- self.s = socket.socket() #^
- self.s.connect( (self.HOST, self.PORT)) # Connecting
- def identify(self): # Identify the cloak for this section
- self.s.sendall('USER %s %s server :%s\n' % (self.NICK,self.HOST,self.NICK))
- self.s.sendall('NICK %s\n' % self.NICK)
- self.s.sendall('PRIVMSG NickServ :IDENTIFY Namehere %s\n' % self.PASS)
- def join(self): # Connecting
- while not self.IN_CHANNEL: # Not in channel
- line = self.s.recv(500) # Receive messages
- if "Welcome to the freenode Internet Relay Chat Network" in line: # When message comes,
- self.s.sendall('JOIN %s\n' % self.CHANNEL) # Connect to channel
- self.IN_CHANNEL = True # In the channel
- def loop(self): # Repeating 24-29
- while True:
- line = self.s.recv(500)
- if 'PING' in line: # If a ping comes, it will do a Horizontal line
- line = line.rstrip() # ^
- line = line.split() # ^
- self.s.send('PONG %s\n' % line[1]) # ^
- def main():
- bot = Bot() # It is a bot
- bot.connect() # Connected
- bot.identify() # Indentified
- bot.join() # Joined
- bot.loop() # Repeat (39-44)
- if __name__ == "__main__": # If name = main, its in the main
- main()
Add Comment
Please, Sign In to add comment