Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context menu for notes #3272

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions bot/exts/moderation/infraction/infractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from discord import Member
from discord.ext import commands
from discord.ext.commands import Context, command
from discord import app_commands
from pydis_core.utils.members import get_or_fetch_member

from bot import constants
Expand Down Expand Up @@ -47,6 +48,31 @@
COMP_BAN_DURATION = timedelta(days=4)


class NoteModal(discord.ui.Modal, title="Add a Note"):
def __init__(self, user_id: int, message_link: str | None = None):
super().__init__()
self.user_id = user_id
self.message_link = message_link

note = discord.ui.TextInput(
label="Note",
style=discord.TextStyle.paragraph,
placeholder="Enter the note content here...",
required=True,
max_length=2000,
)

async def on_submit(self, interaction: discord.Interaction) -> None:
note_content = self.note.value
if self.message_link:
note_content += f"\n\nMessage link: {self.message_link}"

user = await interaction.client.get_or_fetch_user(self.user_id)
ctx = await interaction.client.get_context(interaction)
await ctx.invoke(ctx.bot.get_command("note"), user=user, reason=note_content)
await interaction.response.send_message(f"Note added for {user.mention}", ephemeral=True)


class Infractions(InfractionScheduler, commands.Cog):
"""Apply and pardon infractions on users for moderation purposes."""

Expand Down Expand Up @@ -674,6 +700,18 @@ async def action() -> None:
await member.edit(timed_out_until=expiry, reason=reason)
await self.reapply_infraction(timeout_infraction, action)

@app_commands.context_menu(name="Add Note to User")
async def add_note_to_user(self, interaction: discord.Interaction, user: discord.User) -> None:
"""Context menu command to add a note to a user."""
modal = NoteModal(user_id=user.id)
await interaction.response.send_modal(modal)

@app_commands.context_menu(name="Add Note to Message")
async def add_note_to_message(self, interaction: discord.Interaction, message: discord.Message) -> None:
"""Context menu command to add a note to a message."""
modal = NoteModal(user_id=message.author.id, message_link=message.jump_url)
await interaction.response.send_modal(modal)


async def setup(bot: Bot) -> None:
"""Load the Infractions cog."""
Expand Down