SeaCogs/aurora/configuration/embed.py

154 lines
6.4 KiB
Python

from discord import Embed, Guild
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("History Inline: ") + get_bool_emoji(override_settings['inline']),
'- ' + bold("History Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']),
'- ' + bold("History 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
""" + override_str
return e
async def guild(ctx: commands.Context) -> Embed:
"""Generates a configuration menu field value for a guild's settings."""
guild_settings = {
"show_moderator": await config.guild(ctx.guild).show_moderator(),
"use_discord_permissions": await config.guild(ctx.guild).use_discord_permissions(),
"ignore_modlog": await config.guild(ctx.guild).ignore_modlog(),
"ignore_other_bots": await config.guild(ctx.guild).ignore_other_bots(),
"dm_users": await config.guild(ctx.guild).dm_users(),
"log_channel": await config.guild(ctx.guild).log_channel(),
"history_ephemeral": await config.guild(ctx.guild).history_ephemeral(),
"history_inline": await config.guild(ctx.guild).history_inline(),
"history_pagesize": await config.guild(ctx.guild).history_pagesize(),
"history_inline_pagesize": await config.guild(ctx.guild).history_inline_pagesize(),
"auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(),
}
channel = ctx.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("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']),
'- '+ bold("Log Channel: ") + channel
]
guild_str = '\n'.join(guild_str)
e = await _core(ctx)
e.title += ": Server Configuration"
e.description = """
Use the buttons below to manage Aurora's server configuration.\n
""" + guild_str
return e
async def addrole(ctx: commands.Context) -> Embed:
"""Generates a configuration menu field value for a guild's addrole whitelist."""
whitelist = await config.guild(ctx.guild).addrole_whitelist()
if whitelist:
whitelist = [ctx.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!")
e = await _core(ctx)
e.title += ": Addrole Whitelist"
e.description = "Use the select menu below to manage this guild's addrole whitelist."
if len(whitelist) > 4000 and len(whitelist) < 5000:
lines = whitelist.split('\n')
chunks = []
chunk = ""
for line in lines:
if len(chunk) + len(line) > 1024:
chunks.append(chunk)
chunk = line
else:
chunk += '\n' + line if chunk else line
chunks.append(chunk)
for chunk in chunks:
e.add_field(name="", value=chunk)
else:
e.description += '\n\n' + whitelist
return e
async def immune(ctx: commands.Context) -> Embed:
"""Generates a configuration menu field value for a guild's immune roles."""
immune_roles = await config.guild(ctx.guild).immune_roles()
if immune_roles:
immune_str = [ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in immune_roles]
immune_str = '\n'.join(immune_str)
else:
immune_str = warning("No roles are set as immune roles!")
e = await _core(ctx)
e.title += ": Immune Roles"
e.description = "Use the select menu below to manage this guild's immune roles."
if len(immune_str) > 4000 and len(immune_str) < 5000:
lines = immune_str.split('\n')
chunks = []
chunk = ""
for line in lines:
if len(chunk) + len(line) > 1024:
chunks.append(chunk)
chunk = line
else:
chunk += '\n' + line if chunk else line
chunks.append(chunk)
for chunk in chunks:
e.add_field(name="", value=chunk)
else:
e.description += '\n\n' + immune_str
return e