Example #1
0
def test_prefix_custom():
    command = Command("test",
                      context=MockMessage(
                          channel=MockChannel(_id=6, guild=MockGuild(_id=7))))

    set_prefix(guild_id=7, prefix="&")
    assert command.prefix() == "&"

    set_prefix(guild_id=7, prefix=None)
    assert command.prefix() == DEFAULT_PREFIX
Example #2
0
async def cmd_help(command: Command, name: str = None):
    if name:
        # Clean up the argument so that `+help +ping` works, as the user would expect.
        name = name.replace("+", "")

        embed = help_embed(name, prefix=command.prefix())
        content = f"Type `{command.prefix()}help` for a list of commands."
    else:
        embed = general_help_embed(prefix=command.prefix())
        content = f"Type `{command.prefix()}help <command>` for usage."

    if not embed:
        await command.respond_err(f"No command `{name}` exists.")
        return

    await command.respond(content, embed=embed)
Example #3
0
async def cmd_prefix(command: Command, symbol: str):
    if not command.guild_id():
        await command.respond_err("Cannot change prefix in DM channels.")
        return
    
    if " " in symbol:
        await command.respond_err("`<symbol>` cannot include whitespace.")
        return
    
    # The discord message character limit is 2000.
    # Need enough characters to write `{prefix}prefix +` to reset it.
    len_limit = 2000 - len("prefix +")
    if len(symbol) > len_limit:
        await command.respond_err(f"`<symbol>` cannot exceed {len_limit} characters.")
        return

    old_prefix = command.prefix()
    set_prefix(command.guild_id(), symbol)
    await command.respond(f"✓ Command prefix changed from `{old_prefix}` to `{command.prefix()}`.")
Example #4
0
def test_prefix_default():
    command = Command("test",
                      context=MockMessage(
                          channel=MockChannel(_id=6, guild=MockGuild(_id=7))))
    assert command.prefix() == DEFAULT_PREFIX
Example #5
0
def test_prefix_no_guild():
    command = Command("test",
                      context=MockMessage(channel=MockDMChannel(_id=6)))
    assert command.prefix() == DEFAULT_PREFIX
Example #6
0
def test_prefix_no_context():
    command = Command("test")
    assert command.prefix() == DEFAULT_PREFIX