user-infractions shows total severity.
Command user-infractions now shows the total severity/weight and number of infractions.
This commit is contained in:
parent
a9920e44d1
commit
c02ff3f8f8
|
@ -15,6 +15,7 @@ from naff import (
|
|||
Button,
|
||||
ButtonStyles,
|
||||
)
|
||||
from peewee import fn
|
||||
from database import (
|
||||
GuildSettings,
|
||||
Infractions as InfractionsModel,
|
||||
|
@ -49,8 +50,11 @@ class Infractions(Extension):
|
|||
EmbedField(
|
||||
name="**Received**",
|
||||
value=f"<t:{int(infraction.at_time.timestamp())}:F>",
|
||||
inline=True,
|
||||
),
|
||||
EmbedField(
|
||||
name="**Severity**", value=f"{infraction.weight}", inline=True
|
||||
),
|
||||
EmbedField(name="**Severity**", value=f"{infraction.weight}"),
|
||||
],
|
||||
)
|
||||
embeds.append(embed)
|
||||
|
@ -73,35 +77,59 @@ class Infractions(Extension):
|
|||
await ctx.defer(ephemeral=False)
|
||||
infractions: List[InfractionsModel] = InfractionsModel.select().where(
|
||||
InfractionsModel.guild_id == int(ctx.guild_id),
|
||||
InfractionsModel.user_id == int(ctx.author.id),
|
||||
InfractionsModel.user_id == int(user.id),
|
||||
)
|
||||
|
||||
if len(infractions) == 0:
|
||||
await ctx.send(f"{user.mention} has no infractions.")
|
||||
return
|
||||
|
||||
infractions_weight: List[InfractionsModel] = InfractionsModel.select(
|
||||
InfractionsModel.user_id,
|
||||
fn.SUM(InfractionsModel.weight).alias("total_weight"),
|
||||
fn.COUNT(InfractionsModel.id).alias("total_infractions"),
|
||||
).where(
|
||||
InfractionsModel.guild_id == int(ctx.guild_id),
|
||||
InfractionsModel.user_id == int(user.id),
|
||||
)
|
||||
|
||||
embeds: List[Embed] = []
|
||||
for infraction in infractions: # pylint: disable=not-an-iterable
|
||||
issuer = await self.client.fetch_member(
|
||||
guild_id=ctx.guild, user_id=infraction.given_by
|
||||
)
|
||||
embed = Embed(
|
||||
title=f"Infraction for user {user.display_name} ({user.username}#{user.discriminator}, {user.id})", # pylint: disable=line-too-long
|
||||
title=f"Infraction for user {user.display_name} ({user.username}#{user.discriminator}, {user.id})", # pylint: disable=line-too-long
|
||||
description=f"{infraction.reason}",
|
||||
color=infraction_colour(infraction.weight),
|
||||
fields=[
|
||||
EmbedField(name="**ID**", value=f"{infraction.id}"),
|
||||
EmbedField(name="**ID**", value=f"{infraction.id}", inline=True),
|
||||
EmbedField(
|
||||
name="**Received**",
|
||||
value=f"<t:{int(infraction.at_time.timestamp())}:F>",
|
||||
inline=True,
|
||||
),
|
||||
EmbedField(
|
||||
name="**Severity**", value=f"{infraction.weight}", inline=True
|
||||
),
|
||||
EmbedField(
|
||||
name="**Issued by**",
|
||||
value=f"{issuer.display_name}",
|
||||
inline=True,
|
||||
),
|
||||
EmbedField(name="**Severity**", value=f"{infraction.weight}"),
|
||||
EmbedField(name="**Issued by**", value=f"{issuer.display_name}"),
|
||||
],
|
||||
)
|
||||
embeds.append(embed)
|
||||
|
||||
await ctx.send(embed=embeds, ephemeral=False)
|
||||
print(infractions.count())
|
||||
print(infractions_weight.count())
|
||||
await ctx.send(
|
||||
content=f"{user.mention} has {infractions_weight[0].total_infractions} infractions, for a total weight of {infractions_weight[0].total_weight:.2f}"
|
||||
if infractions_weight.count() > 0
|
||||
else None,
|
||||
embed=embeds,
|
||||
ephemeral=False,
|
||||
)
|
||||
|
||||
@slash_command(
|
||||
name="warn",
|
||||
|
@ -183,20 +211,20 @@ class Infractions(Extension):
|
|||
ephemeral=True,
|
||||
)
|
||||
|
||||
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 = 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(name="**Severity**", value=f"{weight}"),
|
||||
EmbedField("**Issued by**", f"{ctx.author.display_name}"),
|
||||
],
|
||||
))
|
||||
# TODO: Add this in again when GuildSettings is implemented
|
||||
|
||||
# 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 = 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=[
|
||||
# ],
|
||||
# ))
|
||||
|
||||
if not silent and warning_msg is None:
|
||||
await ctx.send(
|
||||
|
|
Loading…
Reference in New Issue