Ejemplo n.º 1
0
    def perform_action(self, user, message):
        '''
        parses out the message. if it's a command, it calls do_command.
        if it's not a command, it gets the chat modules to try to overhear it if they can
        '''
        if not getattr(self, 'username', None) or user != self.username:
            try:
                message = unicodedata.normalize('NFKD',
                                                unicode(message)).encode(
                                                    'ascii', 'ignore').lower()

                was_answer = self.state.check_answer(user, message)

                parsed = match_grammars(str(message), self.command_grammars)
                if parsed and not was_answer:
                    self.do_command(user, parsed['phrase'].lower())
                else:
                    hit = False
                    for module in self._modules.values():
                        hit |= module.overhear(user, message)
                        if hit:
                            break

            except Exception:
                self.logger.error(traceback.format_exc())
                try:
                    self.speak(
                        user,
                        "Whoops, looks like that caused me to crash. Check my log files to see what happened!"
                    )
                except:
                    self.logger.error(traceback.format_exc())
Ejemplo n.º 2
0
 def perform_action(self, user, message):
     '''
     parses out the message. if it's a command, it calls do_command.
     if it's not a command, it gets the chat modules to try to overhear it if they can
     '''
     if not getattr(self,'username',None) or user != self.username:
         try:
             message = unicodedata.normalize('NFKD', unicode(message)).encode('ascii', 'ignore').lower()
             
             was_answer = self.state.check_answer(user, message)
 
             parsed = match_grammars(str(message), self.command_grammars)
             if parsed and not was_answer:
                 self.do_command(user, parsed['phrase'].lower())
             else:
                 hit = False
                 for module in self._modules.values():
                     hit |= module.overhear(user, message)
                     if hit:
                         break
 
         except Exception:
             self.logger.error(traceback.format_exc())
             try:
                 self.speak(user, "Whoops, looks like that caused me to crash. Check my log files to see what happened!")
             except:
                 self.logger.error(traceback.format_exc())
Ejemplo n.º 3
0
 def perform_command(self, user, command):
     '''
     This function is called on all chatmodules by the chatbot whenever it detects an incoming command.
     It runs through all registered commands and sees if the incoming message matches and of their syntaxes.
     If so, it runs that command function.
     '''
     hit = False
     storable = None
     for fun in self.command_functions:
         kwargs = match_grammars(command, fun.command_grammars)
         if kwargs is not False:
             self.bot.logger.info(
                 "Grammar Parsed:\n\t\t\t\tcommand: {0}\n\t\t\t\tmodule: {1}\n\t\t\t\targs: {2}"
                 .format(command,
                         self.__module_name__ + " - " + fun.__name__,
                         kwargs))
             fun(self, user, **kwargs)
             hit = True
             storable = fun.storable
     return hit, storable