feat(aurora): merged all of the changes made in the configuration rewrite into the codebase of the cog itself
This commit is contained in:
parent
3b8506cba8
commit
46a290aad3
13 changed files with 297 additions and 372 deletions
|
@ -5,10 +5,11 @@ from datetime import datetime, timedelta
|
|||
|
||||
import humanize
|
||||
from discord import Color, Embed, Guild, Interaction, InteractionMessage, User, Member
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import box, bold, error, warning
|
||||
|
||||
from .config import config
|
||||
from .utils import fetch_channel_dict, fetch_user_dict, get_next_case_number
|
||||
from aurora.utilities.config import config
|
||||
from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_next_case_number, get_bool_emoji, get_pagesize_str
|
||||
|
||||
|
||||
async def message_factory(color: Color, guild: Guild, reason: str, moderation_type: str, moderator: Union[Member, User] = None, duration: timedelta = None, response: InteractionMessage = None) -> Embed:
|
||||
|
@ -223,3 +224,156 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
|
|||
content += f"\nReason: {case_dict['reason']}"
|
||||
|
||||
return box(content, 'prolog')
|
||||
|
||||
|
||||
########################################################################################################################
|
||||
### Configuration Embeds #
|
||||
########################################################################################################################
|
||||
|
||||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ import json
|
|||
from datetime import timedelta as td
|
||||
from typing import Union
|
||||
|
||||
from discord import Guild, Interaction, Member, User
|
||||
from discord import Guild, Interaction, Member, User, SelectOption
|
||||
from discord.errors import Forbidden, NotFound
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import error
|
||||
|
@ -228,3 +228,37 @@ def convert_timedelta_to_str(timedelta: td) -> str:
|
|||
minutes = (total_seconds % 3600) // 60
|
||||
seconds = total_seconds % 60
|
||||
return f"{hours}:{minutes}:{seconds}"
|
||||
|
||||
def get_bool_emoji(value: bool) -> str:
|
||||
"""Returns a unicode emoji based on a boolean value."""
|
||||
if value is True:
|
||||
return "\N{WHITE HEAVY CHECK MARK}"
|
||||
if value is False:
|
||||
return "\N{NO ENTRY SIGN}"
|
||||
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
|
||||
|
||||
def get_pagesize_str(value: Union[int, None]) -> str:
|
||||
"""Returns a string based on a pagesize value."""
|
||||
if value is None:
|
||||
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
|
||||
return str(value) + " cases per page"
|
||||
|
||||
def create_pagesize_options() -> list[SelectOption]:
|
||||
"""Returns a list of SelectOptions for pagesize configuration."""
|
||||
options = []
|
||||
options.append(
|
||||
SelectOption(
|
||||
label="Default",
|
||||
value="default",
|
||||
description="Reset the pagesize to the default value.",
|
||||
)
|
||||
)
|
||||
for i in range(1, 21):
|
||||
options.append(
|
||||
SelectOption(
|
||||
label=str(i),
|
||||
value=str(i),
|
||||
description=f"Set the pagesize to {i}.",
|
||||
)
|
||||
)
|
||||
return options
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue