feat(aurora): implemented the per-type configuration options so they actually do something
All checks were successful
Actions / Build Documentation (MkDocs) (pull_request) Successful in 28s
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 40s

This commit is contained in:
Seaswimmer 2024-08-12 18:13:04 -04:00
parent 08278c2de4
commit 4d408ff616
Signed by: cswimr
GPG key ID: 3813315477F26F82
4 changed files with 50 additions and 14 deletions

View file

@ -526,6 +526,7 @@ class Aurora(commands.Cog):
on: str | None = None,
before: str | None = None,
after: str | None = None,
types: str | None = None,
ephemeral: bool | None = None,
inline: bool | None = None,
export: bool = False,
@ -548,6 +549,8 @@ class Aurora(commands.Cog):
List infractions before a certain date
after: str
List infractions after a certain date
types: bool
List infractions of specific types, comma separated
ephemeral: bool
Hide the command response
inline: bool
@ -644,15 +647,33 @@ class Aurora(commands.Cog):
)
return
type_list = []
registry_values = type_registry.values()
if types:
for t in types.split(","):
stripped = t.strip().lower()
if stripped == "all":
type_list.clear()
type_list = registry_values
break
try:
type_list.append(type_registry[stripped])
except RegistryKeyError:
continue
else:
for t in registry_values:
if await config.custom("types", interaction.guild.id, t.key).show_in_history():
type_list.append(t)
if target:
filename = f"moderation_target_{str(target.id)}_{str(interaction.guild.id)}.json"
moderations = await Moderation.find_by_target(bot=interaction.client, guild_id=interaction.guild.id, target=target.id, before=before, after=after)
moderations = await Moderation.find_by_target(bot=interaction.client, guild_id=interaction.guild.id, target=target.id, before=before, after=after, types=type_list)
elif moderator:
filename = f"moderation_moderator_{str(moderator.id)}_{str(interaction.guild.id)}.json"
moderations = await Moderation.find_by_moderator(bot=interaction.client, guild_id=interaction.guild.id, moderator=moderator.id, before=before, after=after)
moderations = await Moderation.find_by_moderator(bot=interaction.client, guild_id=interaction.guild.id, moderator=moderator.id, before=before, after=after, types=type_list)
else:
filename = f"moderation_{str(interaction.guild.id)}.json"
moderations = await Moderation.get_latest(bot=interaction.client, guild_id=interaction.guild.id, before=before, after=after)
moderations = await Moderation.get_latest(bot=interaction.client, guild_id=interaction.guild.id, before=before, after=after, types=type_list)
if export:
try:

View file

@ -64,7 +64,11 @@ async def message_factory(
timestamp=datetime.now(),
)
if await config.guild(guild).show_moderator() and moderator is not None:
show_moderator = await config.custom("types", guild.id, moderation_type.key).show_moderator()
if show_moderator is None:
show_moderator = await config.guild(guild).show_moderator()
if show_moderator and moderator is not None:
embed.add_field(
name="Moderator", value=f"`{moderator.name} ({moderator.id})`", inline=False
)
@ -572,10 +576,12 @@ async def type_embed(ctx: commands.Context, moderation_type = Type) -> Embed:
guild_str = "\n".join(guild_str)
e = await _config(ctx)
e.title += ": Server Configuration"
e.title += f": {moderation_type.string} Configuration"
e.description = (
"""
Use the buttons below to manage Aurora's server configuration.\n
f"""
Use the buttons below to manage Aurora's configuration for the {moderation_type.string} moderation type.
If an option has a question mark (\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}) next to it, Aurora will default to the guild level setting instead.
See `{ctx.prefix}aurora set guild` for more information.\n
"""
+ guild_str
)

View file

@ -28,13 +28,16 @@ async def moderate(ctx: Union[commands.Context, discord.Interaction], target: di
ctx = await commands.Context.from_interaction(interaction)
if isinstance(interaction.command, app_commands.ContextMenu):
ctx.author = interaction.user
if not await check_moddable(target, ctx, permissions):
if not await check_moddable(target=target, ctx=ctx, permissions=permissions, moderation_type=moderation_type):
return
if silent is None:
silent = not await config.guild(ctx.guild).dm_users()
dm_users = await config.custom("types", ctx.guild.id, moderation_type.key).dm_users()
if dm_users is None:
dm_users = await config.guild(ctx.guild).dm_users()
silent = not dm_users
return await moderation_type.handler(
ctx,
target,
silent,
ctx=ctx,
target=target,
silent=silent,
**kwargs
)

View file

@ -9,6 +9,7 @@ from discord.errors import Forbidden
from redbot.core import commands, data_manager
from redbot.core.utils.chat_formatting import error
from ..models.type import Type
from ..utilities.config import config
from ..utilities.json import dumps
from ..utilities.logger import logger
@ -43,10 +44,15 @@ def check_permissions(
async def check_moddable(
target: Union[User, Member, TextChannel], ctx: commands.Context, permissions: Tuple[str]
target: Union[User, Member, TextChannel], ctx: commands.Context, permissions: Tuple[str], moderation_type: Type,
) -> bool:
"""Checks if a moderator can moderate a target."""
is_channel = isinstance(target, TextChannel)
use_discord_permissions = await config.custom("types", ctx.guild.id, moderation_type.key).use_discord_permissions()
if use_discord_permissions is None:
use_discord_permissions = await config.guild(ctx.guild).use_discord_permissions()
if check_permissions(ctx.bot.user, permissions, guild=ctx.guild):
await ctx.send(
error(
@ -56,7 +62,7 @@ async def check_moddable(
)
return False
if await config.guild(ctx.guild).use_discord_permissions() is True:
if use_discord_permissions is True:
if check_permissions(ctx.author, permissions, guild=ctx.guild):
await ctx.send(
error(