from typing import Union from discord import Embed, Guild, Member, User from redbot.core import commands from redbot.core.utils.chat_formatting import bold, error, warning from aurora.configuration.utils import get_bool_emoji, get_pagesize_str from aurora.utilities.config import config async def _core(ctx: commands.Context) -> Embed: """Generates the core embed for configuration menus to use.""" e = Embed( title="Aurora Configuration Menu", color=await ctx.embed_color() ) e.set_thumbnail(url=ctx.bot.user.display_avatar.url) return e async def overrides(ctx: commands.Context) -> Embed: """Generates a configuration menu embed for a user's overrides.""" override_settings = { "ephemeral": await config.user(ctx.author).history_ephemeral(), "inline": await config.user(ctx.author).history_inline(), "inline_pagesize": await config.user(ctx.author).history_inline_pagesize(), "pagesize": await config.user(ctx.author).history_pagesize(), "auto_evidenceformat": await config.user(ctx.author).auto_evidenceformat() } override_str = [ 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']), bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']), bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']), ] override_str = '\n'.join(override_str) e = await _core(ctx) e.title += ": User Overrides" e.description = """ Use the buttons below to manage your user overrides. These settings will override the relevant guild settings.\n\n """ + override_str return e 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']), bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']), bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize']) ] guild_str = '\n'.join(guild_str) return guild_str async def _addrole(guild: Guild) -> str: """Generates a configuration menu field value for a guild's addrole whitelist.""" whitelist = await config.guild(guild).addrole_roles() if whitelist: whitelist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in whitelist] whitelist = '\n'.join(whitelist) else: whitelist = warning("No roles are on the addrole whitelist!") return whitelist 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 async def embed(ctx: commands.Context) -> Embed: """Generates the configuration embed for a guild.""" e = await _core(ctx) e.add_field(name="User Overrides", value=await _overrides(ctx.author), inline=False) if ctx.guild is not None and (ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_guild): e.add_field(name="Guild Settings", value=await _guild(ctx.guild), inline=False) return e 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) return e