forked from cswimr/SeaCogs
111 lines
5.3 KiB
Python
111 lines
5.3 KiB
Python
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 .utils import get_bool_emoji, get_pagesize_str
|
|
from ..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",
|
|
description="Use the buttons below to configure Aurora.",
|
|
color=await ctx.embed_color()
|
|
)
|
|
e.set_thumbnail(url=ctx.bot.user.display_avatar.url)
|
|
return e
|
|
|
|
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']),
|
|
bold("Inline Pagesize: ") + get_pagesize_str(override_settings['inline_pagesize']),
|
|
bold("Pagesize: ") + get_pagesize_str(override_settings['pagesize']),
|
|
]
|
|
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']),
|
|
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 _blacklist(guild: Guild) -> str:
|
|
"""Generates a configuration menu field value for a guild's blacklist."""
|
|
|
|
blacklist = await config.guild(guild).blacklist_roles()
|
|
if blacklist:
|
|
blacklist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in blacklist]
|
|
blacklist = '\n'.join(blacklist)
|
|
else:
|
|
blacklist = warning("No roles are set as blacklist roles!")
|
|
return blacklist
|
|
|
|
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)
|
|
e.add_field(name="Blacklist Roles", value=await _blacklist(ctx.guild), inline=False)
|
|
e.add_field(name="Immune Roles", value=await _immune(ctx.guild), inline=False)
|
|
return e
|