Skip to content

discord_lfg.lfg

Controls the LFG system.

logger = logging.getLogger(__name__) module-attribute #

LFGValidationError(messages) #

Bases: Exception

LFG validation error message handler.

Initialisation.

Source code in src\discord_lfg\lfg.py
def __init__(self, messages):
    """Initialisation."""
    self.messages = messages

messages = messages instance-attribute #

lfg(interaction, activity, creator_role, filled_spots, listed_as, creator_notes, config, **options) async #

Creates a GroupBuilder instance from a slash command.

Source code in src\discord_lfg\lfg.py
async def lfg(
    interaction: discord.Interaction,
    activity: str,
    creator_role: str,
    filled_spots: str,
    listed_as: str,
    creator_notes: str,
    config: CommandConfig,
    **options,
):
    """Creates a GroupBuilder instance from a slash command."""
    logger.debug("".join([str((key, value)) for key, value in locals().items()]))
    filled_spots_dict = _convert_short_filled_spots_to_full(config.roles, filled_spots)
    try:
        _validate_lfg_inputs(creator_role, filled_spots_dict, config.roles)
    except LFGValidationError as e:
        response = "\n".join(e.messages)
        message_func = (
            interaction.followup.send
            if interaction.response.is_done()
            else interaction.response.send_message
        )
        await message_func(response, ephemeral=True)
        return None

    user_inputs = {
        "activity_name": activity,
        "listed_as": listed_as,
        "creator_notes": creator_notes,
        **options,
    }
    logger.debug(user_inputs)

    instance = GroupBuilder(
        interaction=interaction,
        group_info=user_inputs,
        config=config,
        creator_role=creator_role,
        filled_spots=filled_spots_dict,
    )
    await instance.send_message(interaction)
    await instance.send_passphrase(interaction)

lfgdebug(interaction, debug_type) async #

Creates a listing for debugging purposes.

Source code in src\discord_lfg\lfg.py
async def lfgdebug(interaction: discord.Interaction, debug_type: int):
    """Creates a listing for debugging purposes."""
    roles = {
        "tank": RoleDefinition("tank", 1, "🛡️", "t"),
        "healer": RoleDefinition("healer", 1, "🪄", "h"),
        "dps": RoleDefinition("dps", 3, "⚔️", "d"),
    }
    config = CommandConfig(
        [],
        roles,
        "lfgdebug",
        "Multiple LFG for debug purposes",
        True,
        "Debug",
        1,
        1,
        ["kick user"],
        [],
        {},
        [],
    )
    if debug_type == 0:
        difficulty = 3
        filled_spots = "tdd"
        await interaction.channel.send("Difficulty 3 group with 1 healer spot")  # type: ignore

    if debug_type == 1:
        difficulty = 5
        filled_spots = ""
        await interaction.channel.send("Difficulty 5 group with all spots open")  # type: ignore

    if debug_type == 2:
        difficulty = 0
        filled_spots = "tdd"
        await interaction.channel.send("Difficulty 0 group with 1 healer spot")  # type: ignore

    if debug_type == 3:
        difficulty = 3
        filled_spots = "ddd"
        await interaction.channel.send("Invalid group (3 filled dps spots)")  # type: ignore

    if debug_type == 4:
        difficulty = 4
        filled_spots = "thdd"
        await interaction.channel.send("Invalid group (no available spots)")  # type: ignore

    return await lfg(
        interaction=interaction,
        activity="test",
        difficulty=difficulty,
        creator_role="dps",
        timing_aim="Time but complete",
        listed_as=f"Dungeon Debug Test {debug_type}",
        creator_notes="debug creator notes blah blah",
        filled_spots=filled_spots,
        config=config,
    )