Ejemplo n.º 1
0
    def message_received(text):
        all_commands = runtime_utils.parse_message(text)
        if all_commands is None:
            return
        # Iterate through all commands provided and generate commands.
        for i, item in enumerate(all_commands):
            # Generate command with parameters
            new_text = deepcopy(text)
            new_text.message = item
            try:
                new_command = Command(item[1:].split()[0], new_text)
            except IndexError:
                continue
            all_aliases = aliases.get_all_aliases()
            all_alias_names = [x[0] for x in all_aliases]
            if len(all_aliases) != 0:
                if new_command.command in all_alias_names:
                    alias_item_index = all_alias_names.index(
                        new_command.command)
                    alias_commands = [
                        msg.strip()
                        for msg in all_aliases[alias_item_index][1].split('|')
                    ]
                    if len(alias_commands) > runtime_settings.multi_cmd_limit:
                        rprint(
                            f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        log(WARNING, f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        return
                    for x, sub_item in enumerate(alias_commands):
                        sub_text = deepcopy(text)
                        if len(item[1:].split()) > 1:
                            sub_text.message = f"{sub_item} {item[1:].split(' ', 1)[1]}"
                        else:
                            sub_text.message = sub_item
                        try:
                            sub_command = Command(sub_item[1:].split()[0],
                                                  sub_text)
                        except IndexError:
                            continue
                        global_settings.cmd_queue.insert(sub_command)
                else:
                    # Insert command into the command queue
                    global_settings.cmd_queue.insert(new_command)
            else:
                global_settings.cmd_queue.insert(new_command)

        # Process commands if the queue is not empty
        while not global_settings.cmd_queue.is_empty():
            # Process commands in the queue
            BotService.process_command_queue(global_settings.cmd_queue.pop())
            sleep(runtime_settings.tick_rate)
Ejemplo n.º 2
0
    def message_received(text, remote_cmd=False):
        all_commands = runtime_utils.parse_message(text)
        if all_commands is None:
            return
        # Iterate through all commands provided and generate commands.
        for i, item in enumerate(all_commands):
            # Generate command with parameters
            if not remote_cmd:
                new_text = deepcopy(text)
            else:
                new_text = RemoteTextMessage(
                    channel_id=global_settings.mumble_inst.users.
                    myself['channel_id'],
                    session=global_settings.mumble_inst.users.
                    myself['session'],
                    message=text.message,
                    actor=global_settings.mumble_inst.users.myself['session'])
            new_text.message = item
            try:
                new_command = Command(item[1:].split()[0], new_text)
            except IndexError:
                continue
            all_aliases = aliases.get_all_aliases()
            all_alias_names = [x[0] for x in all_aliases]
            if len(all_aliases) != 0:
                if new_command.command in all_alias_names:
                    alias_item_index = all_alias_names.index(
                        new_command.command)
                    alias_commands = [
                        msg.strip()
                        for msg in all_aliases[alias_item_index][1].split('|')
                    ]
                    if len(alias_commands) > runtime_settings.multi_cmd_limit:
                        rprint(
                            f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        log(WARNING, f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        return
                    for x, sub_item in enumerate(alias_commands):
                        if not remote_cmd:
                            sub_text = deepcopy(text)
                        else:
                            sub_text = RemoteTextMessage(
                                channel_id=global_settings.mumble_inst.users.
                                myself['channel_id'],
                                session=global_settings.mumble_inst.users.
                                myself['session'],
                                message=text.message,
                                actor=global_settings.mumble_inst.users.
                                myself['session'])
                        if len(item.split()) > 1:
                            sub_text.message = f"{sub_item} {item.split(' ', 1)[1]}"
                        else:
                            sub_text.message = sub_item
                        try:
                            com_parse = sub_item.split()[0]
                            if com_parse[0] != '(' and com_parse[-1] != ')':
                                return
                            sub_command = Command(com_parse[1:][:-1], sub_text)
                        except IndexError:
                            continue
                        global_settings.cmd_queue.insert_item(sub_command)
                else:
                    # Insert command into the command queue
                    global_settings.cmd_queue.insert_item(new_command)
            else:
                global_settings.cmd_queue.insert_item(new_command)

        # Process commands if the queue is not empty
        while not global_settings.cmd_queue.is_empty():
            # Process commands in the queue
            BotService.process_command_queue(
                global_settings.cmd_queue.pop_item())
            sleep(runtime_settings.tick_rate)