Guest User

Untitled

a guest
Dec 7th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. # Author: Hairr
  2.  
  3. import socket
  4.  
  5. class Bot: # Adding bot element
  6.     def __init__(self):        # Information to login in the account/IRC
  7.         self.NICK = "Nickname"               # Nickname
  8.         self.USER = "Username"               # Username
  9.         self.PASS = "Password"               # Password
  10.         self.HOST       = "irc.freenode.net" # IRC host
  11.         self.PORT       = 6667               # IRC port
  12.         self.IN_CHANNEL = False              # Checks if you are in channel
  13.         self.CHANNEL    = '##hairybot'       # Channel that logs in
  14.  
  15.     def connect(self): # Connecting to IRC
  16.         self.s = socket.socket() #^
  17.         self.s.connect( (self.HOST, self.PORT)) # Connecting
  18.  
  19.     def identify(self): # Identify the cloak for this section
  20.         self.s.sendall('USER %s %s server :%s\n' % (self.NICK,self.HOST,self.NICK))
  21.         self.s.sendall('NICK %s\n' % self.NICK)
  22.         self.s.sendall('PRIVMSG NickServ :IDENTIFY Namehere %s\n' % self.PASS)
  23.  
  24.     def join(self): # Connecting
  25.         while not self.IN_CHANNEL: # Not in channel
  26.             line = self.s.recv(500) # Receive messages
  27.             if "Welcome to the freenode Internet Relay Chat Network" in line: # When message comes,
  28.                 self.s.sendall('JOIN %s\n' % self.CHANNEL) # Connect to channel
  29.                 self.IN_CHANNEL = True # In the channel
  30.  
  31.     def loop(self): # Repeating 24-29
  32.         while True:
  33.             line = self.s.recv(500)
  34.             if 'PING' in line: # If a ping comes, it will do a Horizontal line
  35.                 line = line.rstrip() # ^
  36.                 line = line.split()  # ^
  37.                 self.s.send('PONG %s\n' % line[1]) # ^
  38.  
  39. def main():
  40.     bot = Bot() # It is a bot
  41.     bot.connect() # Connected
  42.     bot.identify() # Indentified
  43.     bot.join() # Joined
  44.     bot.loop() # Repeat (39-44)
  45.  
  46. if __name__ == "__main__": # If name = main, its in the main
  47.     main()
Add Comment
Please, Sign In to add comment