예제 #1
0
    def handle_command(self, event):
        """Handle command messages"""
        # Test if command handling is enabled
        if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'):
            return

        # Parse message
        line_args = shlex.split(event.text, posix=False)
        i = 0
        while i < len(line_args):
            line_args[i] = line_args[i].strip()
            if line_args[i] == '' or line_args[i] == '':
                line_args.remove(line_args[i])
            else:
                i += 1

        # Test if command length is sufficient
        if len(line_args) < 1:
            self.bot.send_message(event.conv,
                                  '{}: Not a valid command.'.format(event.user.full_name))
            return

        # Test if user has permissions for running command
        if self._check_if_can_run_command(event, line_args[0].lower().replace(self.command_char, '')):
            # Run command
            yield from DispatcherSingleton.run(self.bot, event, self.command_char, *line_args[0:])
        else:
            self.bot.send_message(event.conv,
                                  "Sorry {}, I can't let you do that.".format(event.user.full_name))
예제 #2
0
    def handle_command(self, event):
        """Handle command messages"""
        # Test if command handling is enabled
        if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'):
            return

        # Parse message
        line_args = shlex.split(event.text, posix=False)
        i = 0
        while i < len(line_args):
            line_args[i] = line_args[i].strip()
            if line_args[i] == '' or line_args[i] == '':
                line_args.remove(line_args[i])
            else:
                i += 1

        # Test if command length is sufficient
        if len(line_args) < 1:
            self.bot.send_message(event.conv,
                                  '{}: Not a valid command.'.format(event.user.full_name))
            return

        # Test if user has permissions for running command (and subcommand)
        if check_if_can_run_command(self.bot, event, line_args[0].lower().replace(self.command_char, '')):
            # Run command
            yield from DispatcherSingleton.run(self.bot, event, self.command_char, *line_args[0:])
        else:
            self.bot.send_message(event.conv,
                                  "Sorry {}, I can't let you do that.".format(event.user.full_name))
예제 #3
0
    def handle_command(self, event):
        """Handle command messages"""
        # Test if command handling is enabled
        if not self.bot.get_config_suboption(event.conv_id,
                                             'commands_enabled'):
            return

        # Parse message
        line_args = shlex.split(event.text, posix=False)
        i = 0
        while i < len(line_args):
            line_args[i] = line_args[i].strip()
            if line_args[i] == '' or line_args[i] == '':
                line_args.remove(line_args[i])
            else:
                i += 1

        # Test if command length is sufficient
        if len(line_args) < 1:
            self.bot.send_message(
                event.conv,
                '{}: Not a valid command.'.format(event.user.full_name))
            return

        for prev_command in self.command_cache:
            if prev_command[0] == event.user_id[0] and prev_command[
                    1] == line_args[0] and (datetime.now() - prev_command[2]
                                            ).seconds < self.TIME_OUT:
                self.bot.send_message(
                    event.conv, "Ignored duplicate command from %s." %
                    event.user.full_name)
                return
        self.command_cache.append(
            (event.user_id[0], line_args[0], datetime.now()))

        # Test if user has permissions for running command (and subcommand)
        if check_if_can_run_command(
                self.bot, event,
                line_args[0].lower().replace(self.command_char, '')):
            # Run command
            yield from DispatcherSingleton.run(self.bot, event,
                                               self.command_char,
                                               *line_args[0:])
        else:
            self.bot.send_message(
                event.conv, "Sorry {}, I can't let you do that.".format(
                    event.user.full_name))