Skip to content

tux.ui.modals.report

Classes:

Name Description
ReportModal

Classes

ReportModal(*, title: str = 'Submit an anonymous report', bot: Tux)

Bases: Modal

Methods:

Name Description
on_submit

Sends the report to the moderation team.

Source code in tux/ui/modals/report.py
Python
def __init__(self, *, title: str = "Submit an anonymous report", bot: Tux) -> None:
    super().__init__(title=title)
    self.bot = bot
    self.config = DatabaseController().guild_config

Functions

on_submit(interaction: discord.Interaction) -> None async

Sends the report to the moderation team.

Parameters:

Name Type Description Default
interaction Interaction

The interaction that triggered the command.

required
Source code in tux/ui/modals/report.py
Python
async def on_submit(self, interaction: discord.Interaction) -> None:
    """
    Sends the report to the moderation team.

    Parameters
    ----------
    interaction : discord.Interaction
        The interaction that triggered the command.
    """

    if not interaction.guild:
        logger.error("Guild is None")
        return

    embed = EmbedCreator.create_embed(
        bot=self.bot,
        embed_type=EmbedCreator.INFO,
        user_name="tux",
        title=(f"Anonymous report for {self.short.value}"),  # type: ignore
        description=self.long.value,  # type: ignore
    )

    try:
        report_log_channel_id = await self.config.get_report_log_id(interaction.guild.id)
    except Exception as e:
        logger.error(f"Failed to get report log channel for guild {interaction.guild.id}. {e}")
        await interaction.response.send_message(
            "Failed to submit your report. Please try again later.",
            ephemeral=True,
            delete_after=30,
        )
        return

    if not report_log_channel_id:
        logger.error(f"Report log channel not set for guild {interaction.guild.id}")
        await interaction.response.send_message(
            "The report log channel has not been set up. Please contact an administrator.",
            ephemeral=True,
            delete_after=30,
        )
        return

    # Get the report log channel object
    report_log_channel = interaction.guild.get_channel(report_log_channel_id)
    if not report_log_channel or not isinstance(report_log_channel, discord.TextChannel):
        logger.error(f"Failed to get report log channel for guild {interaction.guild.id}")
        await interaction.response.send_message(
            "Failed to submit your report. Please try again later.",
            ephemeral=True,
            delete_after=30,
        )
        return

    # Send confirmation message to user
    await interaction.response.send_message(
        "Your report has been submitted.",
        ephemeral=True,
        delete_after=30,
    )

    message = await report_log_channel.send(embed=embed)
    await report_log_channel.create_thread(
        name=f"Anonymous report for {self.short.value}",  # type: ignore
        message=message,
        auto_archive_duration=10080,
    )