def loop(self): while 1: self.buffer += self.irc.recv(4096) temp_buffer = self.buffer.split("\n") self.buffer = temp_buffer.pop() for line in temp_buffer: responses = [] # Stubbing out functionality for custom functions. Eventually the big block below will be gone. for function in flatten(self.functions): try: responses.append(function(self, line)) except IndexError: # I put this in here just to be safe. (Dirk) pass # Standard control library try: message = Message(line) except IndexError: pass line = line.strip().split() if line[0] == "PING": self.irc.send("PONG %s\r\n" % line[1]) else: try: # Disconnect functionality (revisited) command = message.command(self.command) if command.__str__() == 'disconnect': if not message.argv(self.command) == self.password: if message.is_public(): koomar.send_message('Incorrect password.') else: koomar.send_private_message("Dear %s, you gave an invalid password." % message.sender, message.sender) else: koomar.send_message('Correct password. Disconnecting...') self.disconnect() return if line[3] == ":%s" % (self.command): if len(line) <= 4: self.send_message("Type `%s quote`" % (self.command)) else: pass #if line[4] == "disconnect": # if line[5] == self.password: # self.disconnect() # return # else: # if not line[2].startswith('#'): # matches = re.match(':([A-Za-z0-9_-]+)!', line[0]) # sender = matches.groups()[0] # self.send_private_message("Dear %s, you gave an invalid password." % sender, sender) # else: # self.send_message("Invalid password.") #if not responses.__contains__(True): #self.send_message("I don't know that command!") except IndexError: pass # Each line may not be a conversation
def quote_parser(koomar, line): message = Message(line) command = message.command(koomar.command) if command == 'quote': rand = random.randint(0, len(quotes)-1) quote = quotes[rand] if message.is_public(): koomar.send_message("\"%s\"" % quote) else: koomar.send_private_message("\"%s\"" % quote, message.sender) return True
def help_parser(koomar, line): message = Message(line) command = message.command(koomar.command) help = \ """Koomar is a currently in development IRC bot. Type in 'koomar quote' to get a random Futurama quote.""" if command == 'help': if message.is_public(): for line in help.split('\n'): koomar.send_message(line) else: for line in help.split('\n'): koomar.send_private_message(line, message.sender) return True