daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from irc import IRC
  2. from botbrain import BotBrain
  3.  
  4. class IRCBot:
  5.     irc = None #IRC wrapper
  6.  
  7.     nick = ''
  8.     server = ''
  9.     port = 6667
  10.  
  11.     channels = [] #List of channels to join
  12.     keys = []     #The keys for the channels
  13.  
  14.     def __init__(self, nick='', server='', port=6667, channels=[], keys=[]):
  15.         """
  16.             Initialises stuff
  17.         """
  18.         self.nick = nick
  19.         self.server = server
  20.         self.port = port
  21.         self.channels = channels
  22.         self.keys = keys
  23.  
  24.         self.irc = IRC(nick,server,port)
  25.  
  26.         #callbacks
  27.         self.irc.on_connect = self.on_connect
  28.         self.irc.on_disconnect = self.on_disconnect
  29.         self.irc.on_privmsg = self.on_privmsg
  30.  
  31.         self.irc.start()
  32.  
  33.     def on_connect(self):
  34.         """
  35.             We connected to a server
  36.         """
  37.         for i in range(0, len(channels)):
  38.             self.irc.join(channels[i], key[i])
  39.            
  40.     def on_privmsg(self, usermask, channel, message):
  41.         """
  42.             We received a message from the usermask on channel
  43.         """
  44.         nick = usermask.split('!')[0]
  45.  
  46.         print(nick + " said: " + message)
  47.         self.irc.privmsg(channel, "Hi " + nick)
  48.  
  49.     def on_disconnect(self):
  50.         """
  51.             We got disconnected
  52.         """
  53.         print("*** Disconnected.")
  54.  
  55. if __name__ == "__main__":
  56.     bot = IRCBot("Hayden|Bot",
  57.                  "irc.killanet.net",
  58.                  6667,
  59.                  ["#haydentest"],
  60.                  [""])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top