def start(self): event = "" while not "you are now recognized" in event: event = ircapi.readEvent() self.handle_event(event) for channel in ircconfig.channels: ircapi.sendJoin(channel) while True: try: event = ircapi.readEvent() print "-*- Event: " + event self.handle_event(event) except KeyboardInterrupt: ircapi.disconnect() return
def handle_event(self, event): if event is None: return if "PING" in event: ircapi.handle_ping(event) if "please choose a different nick" in event: ircapi.identify(ircconfig.password) if "(Ping timeout" in event: ircapi.disconnect() return "FINISHED" if "PRIVMSG" in event: content = event.split("PRIVMSG")[1][1:] if not content.startswith("#"): continue msg = content.split()[1:] msg[0] = msg[0].replace(":", "") response = reply(self._strip_punctuation(" ".join(msg).lower()), self.words) if random.randint(0, 100) <= ircconfig.reply_chance and response is not None: print "Responding: " + response ircapi.sendMessage(content.split()[0], response)
def handle_event(self, event): if event is None: return if "PING" in event: ircapi.handle_ping(event) if "please choose a different nick" in event: ircapi.identify(ircconfig.password) if "(Ping timeout" in event: ircapi.disconnect() return "FINISHED" if "PRIVMSG" in event: content = event.split("PRIVMSG")[1][1:] if not content.startswith("#"): continue msg = content.split()[1:] msg[0] = msg[0].replace(":", "") response = reply(self._strip_punctuation(" ".join(msg).lower()), self.words) if random.randint( 0, 100) <= ircconfig.reply_chance and response is not None: print "Responding: " + response ircapi.sendMessage(content.split()[0], response)