Skip to content

Commit

Permalink
start modmail with user
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamSH-LLK committed Dec 31, 2023
1 parent e6d4345 commit 134ff5f
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions dozer/cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ class StartModmailModal(ui.Modal):
subject = ui.TextInput(label='Subject', custom_id="subject")
message = ui.TextInput(label='Message', style=discord.TextStyle.paragraph, custom_id="message")

def __init__(self, *args, **kwargs):
subject = ui.TextInput(label='Subject', custom_id="subject")

super().__init__(title="New Modmail")
for key, value in kwargs.items():
setattr(self, key, value)

async def on_submit(self, interaction: discord.Interaction): # pylint: disable=arguments-differ
"""Handles when a modal is submitted"""
user = self.custom_user if hasattr(self, "custom_user") else interaction.user

subject = interaction.data['components'][0]['components'][0]['value']
message = interaction.data['components'][1]['components'][0]['value']

Expand All @@ -49,16 +58,16 @@ async def on_submit(self, interaction: discord.Interaction): # pylint: disable=
timestamp=datetime.datetime.utcnow(),
)
new_ticket_embed.set_footer(
text=f"{interaction.user.name}"
f"{'#' + interaction.user.discriminator if interaction.user.discriminator != '0' else ''} "
f"| {interaction.user.id}",
icon_url=interaction.user.avatar.url if interaction.user.avatar is not None else None,
text=f"{user.name}"
f"{'#' + user.discriminator if user.discriminator != '0' else ''} "
f"| {user.id}",
icon_url=user.avatar.url if user.avatar is not None else None,
)
target_record = await ModmailConfig.get_by(guild_id=interaction.guild_id)
mod_channel = interaction.client.get_channel(target_record[0].target_channel)
user_string = f"{interaction.user.name}" \
f"{'#' + interaction.user.discriminator if interaction.user.discriminator != '0' else ''} " \
f"({interaction.user.id})"
user_string = f"{user.name}" \
f"{'#' + user.discriminator if user.discriminator != '0' else ''} " \
f"({user.id})"
if len(user_string) > 100:
user_string = user_string[:96] + "..."
mod_message = await mod_channel.send(user_string)
Expand All @@ -67,7 +76,7 @@ async def on_submit(self, interaction: discord.Interaction): # pylint: disable=

await interaction.response.send_message("Creating private modmail thread!", ephemeral=True)
user_thread = await interaction.channel.create_thread(name=subject)
await user_thread.add_user(interaction.user)
await user_thread.add_user(user)
await user_thread.join()
await user_thread.send(embed=new_ticket_embed)
thread_record = ModmailThreads(user_thread=user_thread.id, mod_thread=mod_thread.id)
Expand Down Expand Up @@ -149,6 +158,17 @@ async def configure_modmail(self, ctx: DozerContext, target_channel):
await config.update_or_add()
await ctx.reply("Configuration saved!")

@command()
@has_permissions(manage_roles=True)
async def start_modmail_with_user(self, ctx: DozerContext, member: discord.Member):
"""Start modmail with a user, should be used in channel with modmail button"""
target_record = await ModmailConfig.get_by(guild_id=ctx.interaction.guild_id)
if len(target_record) == 0:
await ctx.reply("Sorry, this server has not configured modmail correctly yet!", ephemeral=True)
else:
await ctx.interaction.response.send_modal(StartModmailModal(custom_user=member))


@command()
@has_permissions(administrator=True)
async def create_modmail_button(self, ctx):
Expand Down

0 comments on commit 134ff5f

Please sign in to comment.