feat(aurora): added aurora settings guild command

This commit is contained in:
Seaswimmer 2024-01-16 11:50:09 +00:00
parent f97f010dec
commit 45286ded55
Signed by untrusted user: cswimr
GPG key ID: D74DDDDF420E13DF
3 changed files with 89 additions and 61 deletions

View file

@ -40,6 +40,10 @@ class Mixin(ABC):
async def aurora_settings_overrides(self, ctx: commands.Context) -> None:
raise NotImplementedError()
@abstractmethod
async def aurora_settings_guild(self, ctx: commands.Context) -> None:
raise NotImplementedError()
@abstractmethod
async def aurora_settings_addrole(self, ctx: commands.Context) -> None:
raise NotImplementedError()

View file

@ -2,7 +2,7 @@ from redbot.core import commands
from redbot.core.utils.chat_formatting import error, warning
from aurora.configuration.menus.overrides import Overrides
from aurora.configuration.embed import addrole_embed, overrides, immune_embed
from aurora.configuration.embed import addrole, overrides, immune, guild
from aurora.abc import Mixin
from aurora.importers.aurora import ImportAuroraView
from aurora.importers.galacticbot import ImportGalacticBotView
@ -22,8 +22,12 @@ class Configuration(Mixin):
@aurora_settings.command(name="overrides", aliases=["override", "user"])
async def aurora_settings_overrides(self, ctx: commands.Context):
"""Manage Aurora's user overriddable settings."""
view = Overrides(ctx)
await ctx.send(embed=await overrides(ctx), view=view)
await ctx.send(embed=await overrides(ctx), view=Overrides(ctx))
@aurora_settings.command(name="guild", aliases=["server"])
async def aurora_settings_guild(self, ctx: commands.Context):
"""Manage Aurora's guild settings."""
await ctx.send(embed=await guild(ctx))
@aurora_settings.command(name="addrole", aliases=["removerole"])
@commands.admin_or_permissions(manage_guild=True)
@ -31,13 +35,13 @@ class Configuration(Mixin):
"""Manage the addrole whitelist.
Roles added to this list are also applied to `/removerole`."""
await ctx.send(embed=await addrole_embed(ctx))
await ctx.send(embed=await addrole(ctx))
@aurora_settings.command(name="immunity")
@commands.admin_or_permissions(manage_guild=True)
async def aurora_settings_immunity(self, ctx: commands.Context):
"""Manage the immunity whitelist."""
await ctx.send(embed=await immune_embed(ctx))
await ctx.send(embed=await immune(ctx))
@aurora.group(autohelp=True, name="import")
@commands.admin()

View file

@ -1,6 +1,4 @@
from typing import Union
from discord import Embed, Guild, Member, User
from discord import Embed, Guild
from redbot.core import commands
from redbot.core.utils.chat_formatting import bold, error, warning
@ -44,85 +42,107 @@ async def overrides(ctx: commands.Context) -> Embed:
""" + override_str
return e
async def _guild(guild: Guild) -> str:
async def guild(ctx: commands.Context) -> 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(),
"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 = guild.get_channel(guild_settings['log_channel'])
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("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'])
'- '+ 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:
async def addrole(ctx: commands.Context) -> str:
"""Generates a configuration menu field value for a guild's addrole whitelist."""
whitelist = await config.guild(guild).addrole_roles()
whitelist = await config.guild(ctx.guild).addrole_roles()
if whitelist:
whitelist = [guild.get_role(role).mention or error(f"`{role}` (Not Found)") for role in 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!")
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)
e.description = "Use the buttons 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' + whitelist
return e
async def immune_embed(ctx: commands.Context) -> Embed:
"""Generates the immune roles embed for a guild."""
async def immune(ctx: commands.Context) -> str:
"""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]
immune_str = '\n'.join(immune)
else:
immune_str = warning("No roles are set as immune roles!")
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)
e.description = "Use the buttons 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' + immune_str
return e