2024-01-13 10:44:08 -05:00
|
|
|
from typing import Union
|
|
|
|
|
2024-01-15 09:58:53 -05:00
|
|
|
from discord import Embed, Guild, Member, User, ui
|
2024-01-13 10:44:08 -05:00
|
|
|
from redbot.core import commands
|
|
|
|
from redbot.core.utils.chat_formatting import bold, error, warning
|
|
|
|
|
2024-01-15 09:58:53 -05:00
|
|
|
from aurora.configuration.menus.core import Overrides
|
|
|
|
from aurora.configuration.utils import get_bool_emoji, get_pagesize_str
|
|
|
|
from aurora.utilities.config import config
|
2024-01-13 10:44:08 -05:00
|
|
|
|
|
|
|
async def _core(ctx: commands.Context) -> Embed:
|
|
|
|
"""Generates the core embed for configuration menus to use."""
|
2024-01-15 06:49:20 -05:00
|
|
|
e = Embed(
|
2024-01-13 10:44:08 -05:00
|
|
|
title="Aurora Configuration Menu",
|
|
|
|
description="Use the buttons below to configure Aurora.",
|
|
|
|
color=await ctx.embed_color()
|
|
|
|
)
|
2024-01-15 06:49:20 -05:00
|
|
|
e.set_thumbnail(url=ctx.bot.user.display_avatar.url)
|
|
|
|
return e
|
2024-01-13 10:44:08 -05:00
|
|
|
|
|
|
|
async def _overrides(user: Union[Member, User]) -> str:
|
|
|
|
"""Generates a configuration menu field value for a user's overrides."""
|
|
|
|
|
|
|
|
override_settings = {
|
|
|
|
"ephemeral": await config.user(user).history_ephemeral(),
|
|
|
|
"inline": await config.user(user).history_inline(),
|
|
|
|
"inline_pagesize": await config.user(user).history_inline_pagesize(),
|
|
|
|
"pagesize": await config.user(user).history_pagesize(),
|
|
|
|
"auto_evidenceformat": await config.user(user).auto_evidenceformat()
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides = [
|
|
|
|
"These settings will override the relevant guild settings.\n", # Add an extra line between the subtitle and the settings
|
|
|
|
bold("Auto Evidence Format: ") + get_bool_emoji(override_settings['auto_evidenceformat']),
|
|
|
|
bold("Ephemeral: ") + get_bool_emoji(override_settings['ephemeral']),
|
|
|
|
bold("Inline: ") + get_bool_emoji(override_settings['inline']),
|
2024-01-15 02:07:06 -05:00
|
|
|
bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']),
|
|
|
|
bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']),
|
2024-01-13 10:44:08 -05:00
|
|
|
]
|
|
|
|
overrides = '\n'.join(overrides)
|
|
|
|
return overrides
|
|
|
|
|
|
|
|
async def _guild(guild: Guild) -> str:
|
|
|
|
"""Generates a configuration menu field value for a guild's settings."""
|
|
|
|
|
|
|
|
guild_settings = {
|
|
|
|
"show_moderator": await config.guild(guild).show_moderator(),
|
|
|
|
"use_discord_permissions": await config.guild(guild).use_discord_permissions(),
|
|
|
|
"ignore_modlog": await config.guild(guild).ignore_modlog(),
|
|
|
|
"ignore_other_bots": await config.guild(guild).ignore_other_bots(),
|
|
|
|
"dm_users": await config.guild(guild).dm_users(),
|
|
|
|
"log_channel": await config.guild(guild).log_channel(),
|
|
|
|
"history_ephemeral": await config.guild(guild).history_ephemeral(),
|
|
|
|
"history_inline": await config.guild(guild).history_inline(),
|
|
|
|
"history_pagesize": await config.guild(guild).history_pagesize(),
|
|
|
|
"history_inline_pagesize": await config.guild(guild).history_inline_pagesize(),
|
|
|
|
"auto_evidenceformat": await config.guild(guild).auto_evidenceformat(),
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = guild.get_channel(guild_settings['log_channel'])
|
|
|
|
if channel is None:
|
|
|
|
channel = warning("Not Set")
|
|
|
|
else:
|
|
|
|
channel = channel.mention
|
|
|
|
|
|
|
|
guild_str = [
|
|
|
|
bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']),
|
|
|
|
bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']),
|
|
|
|
bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']),
|
|
|
|
bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']),
|
|
|
|
bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']),
|
|
|
|
bold("Log Channel: ") + channel,
|
|
|
|
bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']),
|
|
|
|
bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']),
|
|
|
|
bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']),
|
2024-01-15 02:07:06 -05:00
|
|
|
bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']),
|
|
|
|
bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize'])
|
2024-01-13 10:44:08 -05:00
|
|
|
]
|
|
|
|
guild_str = '\n'.join(guild_str)
|
|
|
|
return guild_str
|
|
|
|
|
2024-01-15 09:03:02 -05:00
|
|
|
async def _addrole(guild: Guild) -> str:
|
|
|
|
"""Generates a configuration menu field value for a guild's addrole whitelist."""
|
2024-01-13 10:44:08 -05:00
|
|
|
|
2024-01-15 09:03:02 -05:00
|
|
|
whitelist = await config.guild(guild).addrole_roles()
|
2024-01-15 09:13:33 -05:00
|
|
|
if whitelist:
|
|
|
|
whitelist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist]
|
|
|
|
whitelist = '\n'.join(whitelist)
|
2024-01-13 10:44:08 -05:00
|
|
|
else:
|
2024-01-15 09:13:33 -05:00
|
|
|
whitelist = warning("No roles are on the addrole whitelist!")
|
|
|
|
return whitelist
|
2024-01-13 10:44:08 -05:00
|
|
|
|
|
|
|
async def _immune(guild: Guild) -> str:
|
|
|
|
"""Generates a configuration menu field value for a guild's immune roles."""
|
|
|
|
|
|
|
|
immune = await config.guild(guild).immune_roles()
|
|
|
|
if immune:
|
|
|
|
immune = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune]
|
|
|
|
immune = '\n'.join(immune)
|
|
|
|
else:
|
|
|
|
immune = warning("No roles are set as immune roles!")
|
|
|
|
return immune
|
|
|
|
|
2024-01-15 09:58:53 -05:00
|
|
|
async def embed(ctx: commands.Context) -> (Embed, ui.View):
|
2024-01-13 10:44:08 -05:00
|
|
|
"""Generates the configuration embed for a guild."""
|
2024-01-15 06:49:20 -05:00
|
|
|
e = await _core(ctx)
|
|
|
|
e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False)
|
2024-01-15 09:58:53 -05:00
|
|
|
view = Overrides(ctx)
|
2024-01-13 10:44:08 -05:00
|
|
|
if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild):
|
2024-01-15 06:49:20 -05:00
|
|
|
e.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False)
|
2024-01-15 09:58:53 -05:00
|
|
|
view = None
|
|
|
|
return (e, view)
|
2024-01-15 09:03:02 -05:00
|
|
|
|
|
|
|
async def addrole_embed(ctx: commands.Context) -> Embed:
|
|
|
|
"""Generates the addrole embed for a guild."""
|
|
|
|
e = await _core(ctx)
|
|
|
|
e.title += ": Addrole Whitelist"
|
|
|
|
e.description = "Use the buttons below to manage the addrole whitelist.\n\n" + await _addrole(ctx.guild)
|
|
|
|
return e
|
|
|
|
|
|
|
|
async def immune_embed(ctx: commands.Context) -> Embed:
|
|
|
|
"""Generates the immune roles embed for a guild."""
|
|
|
|
e = await _core(ctx)
|
|
|
|
e.title += ": Immune Roles"
|
|
|
|
e.description = "Use the buttons below to manage the immune roles.\n\n" + await _immune(ctx.guild)
|
2024-01-15 06:49:20 -05:00
|
|
|
return e
|