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

This commit is contained in:
Seaswimmer 2024-04-05 10:43:58 -04:00
parent a4f2d21fa1
commit 9f7244cd65
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063
5 changed files with 21 additions and 15 deletions

View file

@ -18,8 +18,7 @@ from redbot.core import app_commands, commands, data_manager
from redbot.core.app_commands import Choice from redbot.core.app_commands import Choice
from redbot.core.bot import Red from redbot.core.bot import Red
from redbot.core.commands.converter import parse_relativedelta, parse_timedelta from redbot.core.commands.converter import parse_relativedelta, parse_timedelta
from redbot.core.utils.chat_formatting import (box, error, humanize_list, from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning
humanize_timedelta, warning)
from aurora.importers.aurora import ImportAuroraView from aurora.importers.aurora import ImportAuroraView
from aurora.importers.galacticbot import ImportGalacticBotView 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.immune import Immune
from aurora.menus.overrides import Overrides from aurora.menus.overrides import Overrides
from aurora.utilities.config import config, register_config from aurora.utilities.config import config, register_config
from aurora.utilities.database import (connect, create_guild_table, fetch_case, from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log
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.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.logger import logger
from aurora.utilities.utils import (check_moddable, check_permissions, 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
convert_timedelta_to_str,
fetch_channel_dict, fetch_user_dict,
generate_dict, log, send_evidenceformat,
timedelta_from_relativedelta)
class Aurora(commands.Cog): class Aurora(commands.Cog):
@ -48,7 +39,7 @@ class Aurora(commands.Cog):
This cog stores all of its data in an SQLite database.""" This cog stores all of its data in an SQLite database."""
__author__ = ["SeaswimmerTheFsh"] __author__ = ["SeaswimmerTheFsh"]
__version__ = "2.1.1" __version__ = "2.1.2"
__documentation__ = "https://seacogs.coastalcommits.com/aurora/" __documentation__ = "https://seacogs.coastalcommits.com/aurora/"
async def red_delete_data_for_user(self, *, requester, user_id: int): async def red_delete_data_for_user(self, *, requester, user_id: int):

View file

@ -31,6 +31,16 @@ class Guild(ui.View):
await config.guild(interaction.guild).use_discord_permissions.set(not current_setting) await config.guild(interaction.guild).use_discord_permissions.set(not current_setting)
await interaction.message.edit(embed=await guild_embed(self.ctx)) 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) @ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument 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: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:

View file

@ -7,6 +7,7 @@ def register_config(config_obj: Config):
config_obj.register_guild( config_obj.register_guild(
show_moderator=True, show_moderator=True,
use_discord_permissions=True, use_discord_permissions=True,
respect_hierarchy=True,
ignore_modlog=True, ignore_modlog=True,
ignore_other_bots=True, ignore_other_bots=True,
dm_users=True, dm_users=True,

View file

@ -451,6 +451,7 @@ async def guild_embed(ctx: commands.Context) -> Embed:
ctx.guild ctx.guild
).history_inline_pagesize(), ).history_inline_pagesize(),
"auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(), "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"]) 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: ") + bold("Use Discord Permissions: ")
+ get_bool_emoji(guild_settings["use_discord_permissions"]), + get_bool_emoji(guild_settings["use_discord_permissions"]),
"- " "- "
+ bold("Respect Hierarchy: ")
+ get_bool_emoji(guild_settings["respect_hierarchy"]),
"- "
+ bold("Ignore Modlog: ") + bold("Ignore Modlog: ")
+ get_bool_emoji(guild_settings["ignore_modlog"]), + get_bool_emoji(guild_settings["ignore_modlog"]),
"- " "- "

View file

@ -77,7 +77,7 @@ async def check_moddable(
return False return False
if isinstance(target, Member): 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( await interaction.response.send_message(
content=error( content=error(
"You cannot moderate members with a higher role than you!" "You cannot moderate members with a higher role than you!"