Пример #1
0
def test_can_execute_admin():
    mock_message = MockMessage(channel=MockChannel(_id=44,
                                                   guild=MockGuild(_id=3)),
                               author=MockUser(_id=2, is_admin=True))
    command = Command(name="test2", context=mock_message)

    assert permissions.can_execute(command)
Пример #2
0
async def receive_command(command: Command) -> bool:
    """Returns whether the received command was recognized and executed."""
    if command.name not in registered_aliases:
        return False
    
    name = registered_aliases[command.name]
    func_wrapper = registered_commands[name]
    
    # Let the user know the command was recognized, and that a response should follow.
    await command.trigger_typing()

    if not permissions.can_execute(command):
        await command.respond(
            response = f"✗ Lacking permission.",
            embed = permissions_embed(
                # Can only lack permission in a guild.
                guild_id         = command.guild_id(),
                command_wrappers = [func_wrapper]
            )
        )
        return False

    if len(func_wrapper.required_args) > len(command.args):
        missing_args = func_wrapper.required_args[len(command.args):]
        missing_arg_str = "`<" + "`>, <`".join(missing_args) + ">`"
        await command.respond_err(f"Missing required argument(s) {missing_arg_str}.")
        return False

    parsed_args = parse_args(command.args, arg_count=len(func_wrapper.required_args) + len(func_wrapper.optional_args))
    await func_wrapper.execute(command, *parsed_args)

    return True
Пример #3
0
def test_can_execute_user_perm_fail():
    command_wrapper = get_wrapper(name="test1")
    mock_message = MockMessage(channel=MockChannel(_id=44,
                                                   guild=MockGuild(_id=3)),
                               author=MockUser(_id=2, is_admin=False))
    command = Command(name="test2", context=mock_message)

    set_permission_filter(guild_id=3,
                          command_wrapper=command_wrapper,
                          permission_filter="user:<@88>")

    assert not permissions.can_execute(command)
Пример #4
0
def test_can_execute_role_perm():
    command_wrapper = get_wrapper(name="test1")
    mock_message = MockMessage(channel=MockChannel(_id=44,
                                                   guild=MockGuild(_id=3)),
                               author=MockUser(_id=2,
                                               roles=[MockRole(_id=66)],
                                               is_admin=False))
    command = Command(name="test2", context=mock_message)

    set_permission_filter(guild_id=3,
                          command_wrapper=command_wrapper,
                          permission_filter="role:<@&66>")

    assert permissions.can_execute(command)
Пример #5
0
def test_can_execute_dm():
    mock_message = MockMessage(channel=MockDMChannel(_id=44),
                               author=MockUser(_id=2, is_dm=True))
    command = Command(name="test2", context=mock_message)

    assert permissions.can_execute(command)