Prevent modlog action prompt from opening multiple cases, closes #140
This commit is contained in:
parent
9188b13695
commit
f906886512
1 changed files with 30 additions and 21 deletions
|
@ -799,30 +799,39 @@ class Jarvis(Client):
|
||||||
note = Note(
|
note = Note(
|
||||||
admin=context.author.id, content="Moderation case opened via message"
|
admin=context.author.id, content="Moderation case opened via message"
|
||||||
)
|
)
|
||||||
modlog = Modlog(
|
modlog = await Modlog.find_one(
|
||||||
user=user.id,
|
q(user=user.id, guild=context.guild.id, open=True)
|
||||||
admin=context.author.id,
|
|
||||||
guild=context.guild.id,
|
|
||||||
actions=[action],
|
|
||||||
notes=[note],
|
|
||||||
)
|
)
|
||||||
await modlog.commit()
|
if modlog:
|
||||||
|
self.logger.debug("User already has active case in guild")
|
||||||
|
await context.send(
|
||||||
|
f"User already has open case: {modlog.nanoid}", ephemeral=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
modlog = Modlog(
|
||||||
|
user=user.id,
|
||||||
|
admin=context.author.id,
|
||||||
|
guild=context.guild.id,
|
||||||
|
actions=[action],
|
||||||
|
notes=[note],
|
||||||
|
)
|
||||||
|
await modlog.commit()
|
||||||
|
|
||||||
fields = (
|
fields = (
|
||||||
EmbedField(name="Admin", value=context.author.mention),
|
EmbedField(name="Admin", value=context.author.mention),
|
||||||
EmbedField(name="Opening Action", value=f"{name} {parent}"),
|
EmbedField(name="Opening Action", value=f"{name} {parent}"),
|
||||||
)
|
)
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="Moderation Case Opened",
|
title="Moderation Case Opened",
|
||||||
description=f"Moderation case opened against {user.mention}",
|
description=f"Moderation case opened against {user.mention}",
|
||||||
fields=fields,
|
fields=fields,
|
||||||
)
|
)
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name=user.username + "#" + user.discriminator,
|
name=user.username + "#" + user.discriminator,
|
||||||
icon_url=user.display_avatar.url,
|
icon_url=user.display_avatar.url,
|
||||||
)
|
)
|
||||||
|
|
||||||
await context.message.edit(embed=embed)
|
await context.message.edit(embed=embed)
|
||||||
elif not user:
|
elif not user:
|
||||||
self.logger.debug("User no longer in guild")
|
self.logger.debug("User no longer in guild")
|
||||||
await context.send("User no longer in guild", ephemeral=True)
|
await context.send("User no longer in guild", ephemeral=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue