Skip to content

Commit

Permalink
added warning removal
Browse files Browse the repository at this point in the history
  • Loading branch information
99oblivius committed Sep 22, 2024
1 parent 3e6ac94 commit 040a775
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/cogs/moderation/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from config import *
from utils.logger import Logger as log
from utils.models import Warn
from utils.models import Warn, MMBotWarnedUsers
from utils.utils import format_duration, log_moderation


Expand Down Expand Up @@ -91,7 +91,7 @@ async def moderation_infractions(self, interaction: nextcord.Interaction,
for warn_type, warnings in grouped_users.items():
user_list = []
for warn in warnings:
user_info = f"{f'Match #{warn.match_id}' if warn.match_id else ''}<t:{int(warn.timestamp.timestamp())}:f>"
user_info = f"id: {warn.id} |{f' Match #{warn.match_id} |' if warn.match_id else ''} <t:{int(warn.timestamp.timestamp())}:f>"
if warn.moderator_id:
user_info += f" - by <@{warn.moderator_id}>"
user_info += f"\n```\n{warn.message}```"
Expand All @@ -112,6 +112,20 @@ async def moderation_infractions(self, interaction: nextcord.Interaction,
@moderation_infractions.on_autocomplete("warn_filter")
async def autocomplete_infractions(self, interaction: nextcord.Interaction, warn_filter):
await interaction.response.send_autocomplete(choices=[w.value.capitalize() for w in Warn])

@moderation.subcommand(name="unwarn", description="Remove a warning")
async def moderation_remove_warn(self, interaction: nextcord.Interaction,
warning_id: int = nextcord.SlashOption(min_value=0, description="Unique idendentifier for the warning to remove")
):
warning = await self.bot.store.get_warning(warning_id)
if not warning:
return await interaction.response.send_message(f"Warning `{warning_id}` does not exist.", ephemeral=True)

await self.bot.store.update(MMBotWarnedUsers, id=warning_id, ignored=True)
settings = await self.bot.store.get_settings(interaction.guild.id)
moderation_category = interaction.guild.get_channel(settings.staff_channel).category
await interaction.response.send_message(f"Warning `{warning_id}` was removed successfully.", ephemeral=interaction.channel.category.id != moderation_category.id)
await log_moderation(interaction, settings.log_channel, f"Removed warning", f"id: {warning_id}\ntype: {warning.type.value.capitalize()}\nmatch: {warning.match_id}\n```\n{warning.message}")


def setup(bot):
Expand Down
11 changes: 9 additions & 2 deletions src/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,8 +1587,15 @@ async def get_user_warnings(self, guild_id: int, user_id: int, warn_filters: Lis
query = (select(MMBotWarnedUsers)
.where(
MMBotWarnedUsers.guild_id == guild_id,
MMBotWarnedUsers.user_id == user_id))
MMBotWarnedUsers.user_id == user_id,
MMBotWarnedUsers.ignored == False))
if warn_filters:
query = query.where(MMBotWarnedUsers.type.in_(warn_filters))
result = await session.execute(query)
return result.scalars().all()
return result.scalars().all()

@log_db_operation
async def get_warning(self, warning_id: int) -> MMBotWarnedUsers:
async with self._session_maker() as session:
result = await session.execute(select(MMBotWarnedUsers).where(MMBotWarnedUsers.id == warning_id))
return result.scalar_one_or_none()

0 comments on commit 040a775

Please sign in to comment.