Use new send to admins method in infractions
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Vegard Berg 2023-03-03 07:08:48 +01:00
parent bf7d4ba23f
commit 7a70bd37e7
1 changed files with 24 additions and 23 deletions

View File

@ -22,11 +22,12 @@ from database import (
GuildSettings, GuildSettings,
Infractions as InfractionsModel, Infractions as InfractionsModel,
) )
from heimdallr.Heimdallr import HeimdallrClient
class Infractions(Extension): class Infractions(Extension):
def __init__(self, client): def __init__(self, client):
self.client: Client = client self.client: HeimdallrClient = client
@slash_command( @slash_command(
name="infractions", description="View your infractions", dm_permission=False name="infractions", description="View your infractions", dm_permission=False
@ -218,32 +219,32 @@ class Infractions(Extension):
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
warning_msg = None warning_msg = None
await ctx.send( failed_to_dm_user = not silent and warning_msg is None
f'Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id}) for "{reason}" with severity {weight}', # pylint: disable=line-too-long
ephemeral=True,
)
if failed_to_dm_user:
guild_settings: Optional[GuildSettings] = GuildSettings.get_or_none(GuildSettings.guild_id == int(ctx.guild_id))
if guild_settings is not None:
if guild_settings.admin_channel is not None:
admin_channel = await self.client.fetch_channel(int(guild_settings.admin_channel))
if admin_channel is not None:
await admin_channel.send(embed=Embed(
title=f"Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id})",
description=f"{reason}",
color=infraction_colour(0x0000FF),
fields=[
EmbedField("**Warned by**",
f"{ctx.author.display_name} ({ctx.author.username}#{ctx.author.discriminator})")
],
))
if not silent and warning_msg is None:
await ctx.send( await ctx.send(
f"{user.mention} has been warned, but I couldn't DM them.", f"{user.mention} has received an infraction, but I couldn't DM them.",
ephemeral=True, ephemeral=True,
) )
else:
await ctx.send(
f'Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id}) for "{reason}" with severity {weight}', # pylint: disable=line-too-long
ephemeral=True,
)
await self.client.send_message_to_admins(
guild=ctx.guild,
embed=Embed(
title=f"Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id})",
description=f"{reason}",
color=infraction_colour(0x0000FF),
fields=[
EmbedField("**Warned by**",
f"{ctx.author.display_name} ({ctx.author.username}#{ctx.author.discriminator})"
)
],
)
)
@slash_command( @slash_command(
name="remove-infraction", name="remove-infraction",