From 9f7244cd650b7d17f781d4b67a83cdacaa54c174 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 5 Apr 2024 10:43:58 -0400 Subject: [PATCH] feat(Aurora): added a respect_hierarchy configuration option and relevant configuration button to `[p]aurora set guild`, along with functionality that uses this configuration value --- aurora/aurora.py | 19 +++++-------------- aurora/menus/guild.py | 10 ++++++++++ aurora/utilities/config.py | 1 + aurora/utilities/factory.py | 4 ++++ aurora/utilities/utils.py | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index bc931de..8a437cb 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -18,8 +18,7 @@ from redbot.core import app_commands, commands, data_manager from redbot.core.app_commands import Choice from redbot.core.bot import Red from redbot.core.commands.converter import parse_relativedelta, parse_timedelta -from redbot.core.utils.chat_formatting import (box, error, humanize_list, - humanize_timedelta, warning) +from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning from aurora.importers.aurora import ImportAuroraView from aurora.importers.galacticbot import ImportGalacticBotView @@ -28,18 +27,10 @@ from aurora.menus.guild import Guild from aurora.menus.immune import Immune from aurora.menus.overrides import Overrides from aurora.utilities.config import config, register_config -from aurora.utilities.database import (connect, create_guild_table, fetch_case, - mysql_log) -from aurora.utilities.factory import (addrole_embed, case_factory, - changes_factory, evidenceformat_factory, - guild_embed, immune_embed, - message_factory, overrides_embed) +from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log +from aurora.utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, message_factory, overrides_embed from aurora.utilities.logger import logger -from aurora.utilities.utils import (check_moddable, check_permissions, - convert_timedelta_to_str, - fetch_channel_dict, fetch_user_dict, - generate_dict, log, send_evidenceformat, - timedelta_from_relativedelta) +from aurora.utilities.utils import check_moddable, check_permissions, convert_timedelta_to_str, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat, timedelta_from_relativedelta class Aurora(commands.Cog): @@ -48,7 +39,7 @@ class Aurora(commands.Cog): This cog stores all of its data in an SQLite database.""" __author__ = ["SeaswimmerTheFsh"] - __version__ = "2.1.1" + __version__ = "2.1.2" __documentation__ = "https://seacogs.coastalcommits.com/aurora/" async def red_delete_data_for_user(self, *, requester, user_id: int): diff --git a/aurora/menus/guild.py b/aurora/menus/guild.py index a7c78c7..4f5544d 100644 --- a/aurora/menus/guild.py +++ b/aurora/menus/guild.py @@ -31,6 +31,16 @@ class Guild(ui.View): await config.guild(interaction.guild).use_discord_permissions.set(not current_setting) await interaction.message.edit(embed=await guild_embed(self.ctx)) + @ui.button(label="Respect Hierarchy", style=ButtonStyle.green, row=0) + async def respect_heirarchy(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument + if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: + await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) + return + await interaction.response.defer() + current_setting = await config.guild(interaction.guild).respect_hierarchy() + await config.guild(interaction.guild).respect_hierarchy.set(not current_setting) + await interaction.message.edit(embed=await guild_embed(self.ctx)) + @ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0) async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: diff --git a/aurora/utilities/config.py b/aurora/utilities/config.py index 77c1dfe..0b5e503 100644 --- a/aurora/utilities/config.py +++ b/aurora/utilities/config.py @@ -7,6 +7,7 @@ def register_config(config_obj: Config): config_obj.register_guild( show_moderator=True, use_discord_permissions=True, + respect_hierarchy=True, ignore_modlog=True, ignore_other_bots=True, dm_users=True, diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index c7b41c7..9a9e572 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -451,6 +451,7 @@ async def guild_embed(ctx: commands.Context) -> Embed: ctx.guild ).history_inline_pagesize(), "auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(), + "respect_hierarchy": await config.guild(ctx.guild).respect_hierarchy(), } channel = ctx.guild.get_channel(guild_settings["log_channel"]) @@ -467,6 +468,9 @@ async def guild_embed(ctx: commands.Context) -> Embed: + bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings["use_discord_permissions"]), "- " + + bold("Respect Hierarchy: ") + + get_bool_emoji(guild_settings["respect_hierarchy"]), + "- " + bold("Ignore Modlog: ") + get_bool_emoji(guild_settings["ignore_modlog"]), "- " diff --git a/aurora/utilities/utils.py b/aurora/utilities/utils.py index eef5a62..616fa78 100644 --- a/aurora/utilities/utils.py +++ b/aurora/utilities/utils.py @@ -77,7 +77,7 @@ async def check_moddable( return False if isinstance(target, Member): - if interaction.user.top_role <= target.top_role: + if interaction.user.top_role <= target.top_role and await config.guild(interaction.guild).respect_hierarchy() is True: await interaction.response.send_message( content=error( "You cannot moderate members with a higher role than you!"