forked from blizzthewolf/SeaCogs
feat(aurora): added aurora settings guild command
This commit is contained in:
parent
f97f010dec
commit
45286ded55
3 changed files with 89 additions and 61 deletions
|
@ -40,6 +40,10 @@ class Mixin(ABC):
|
||||||
async def aurora_settings_overrides(self, ctx: commands.Context) -> None:
|
async def aurora_settings_overrides(self, ctx: commands.Context) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def aurora_settings_guild(self, ctx: commands.Context) -> None:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def aurora_settings_addrole(self, ctx: commands.Context) -> None:
|
async def aurora_settings_addrole(self, ctx: commands.Context) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from redbot.core import commands
|
||||||
from redbot.core.utils.chat_formatting import error, warning
|
from redbot.core.utils.chat_formatting import error, warning
|
||||||
|
|
||||||
from aurora.configuration.menus.overrides import Overrides
|
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.abc import Mixin
|
||||||
from aurora.importers.aurora import ImportAuroraView
|
from aurora.importers.aurora import ImportAuroraView
|
||||||
from aurora.importers.galacticbot import ImportGalacticBotView
|
from aurora.importers.galacticbot import ImportGalacticBotView
|
||||||
|
@ -22,8 +22,12 @@ class Configuration(Mixin):
|
||||||
@aurora_settings.command(name="overrides", aliases=["override", "user"])
|
@aurora_settings.command(name="overrides", aliases=["override", "user"])
|
||||||
async def aurora_settings_overrides(self, ctx: commands.Context):
|
async def aurora_settings_overrides(self, ctx: commands.Context):
|
||||||
"""Manage Aurora's user overriddable settings."""
|
"""Manage Aurora's user overriddable settings."""
|
||||||
view = Overrides(ctx)
|
await ctx.send(embed=await overrides(ctx), view=Overrides(ctx))
|
||||||
await ctx.send(embed=await overrides(ctx), view=view)
|
|
||||||
|
@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"])
|
@aurora_settings.command(name="addrole", aliases=["removerole"])
|
||||||
@commands.admin_or_permissions(manage_guild=True)
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
|
@ -31,13 +35,13 @@ class Configuration(Mixin):
|
||||||
"""Manage the addrole whitelist.
|
"""Manage the addrole whitelist.
|
||||||
|
|
||||||
Roles added to this list are also applied to `/removerole`."""
|
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")
|
@aurora_settings.command(name="immunity")
|
||||||
@commands.admin_or_permissions(manage_guild=True)
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
async def aurora_settings_immunity(self, ctx: commands.Context):
|
async def aurora_settings_immunity(self, ctx: commands.Context):
|
||||||
"""Manage the immunity whitelist."""
|
"""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")
|
@aurora.group(autohelp=True, name="import")
|
||||||
@commands.admin()
|
@commands.admin()
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
from typing import Union
|
from discord import Embed, Guild
|
||||||
|
|
||||||
from discord import Embed, Guild, Member, User
|
|
||||||
from redbot.core import commands
|
from redbot.core import commands
|
||||||
from redbot.core.utils.chat_formatting import bold, error, warning
|
from redbot.core.utils.chat_formatting import bold, error, warning
|
||||||
|
|
||||||
|
@ -44,85 +42,107 @@ async def overrides(ctx: commands.Context) -> Embed:
|
||||||
""" + override_str
|
""" + override_str
|
||||||
return e
|
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."""
|
"""Generates a configuration menu field value for a guild's settings."""
|
||||||
|
|
||||||
guild_settings = {
|
guild_settings = {
|
||||||
"show_moderator": await config.guild(guild).show_moderator(),
|
"show_moderator": await config.guild(ctx.guild).show_moderator(),
|
||||||
"use_discord_permissions": await config.guild(guild).use_discord_permissions(),
|
"use_discord_permissions": await config.guild(ctx.guild).use_discord_permissions(),
|
||||||
"ignore_modlog": await config.guild(guild).ignore_modlog(),
|
"ignore_modlog": await config.guild(ctx.guild).ignore_modlog(),
|
||||||
"ignore_other_bots": await config.guild(guild).ignore_other_bots(),
|
"ignore_other_bots": await config.guild(ctx.guild).ignore_other_bots(),
|
||||||
"dm_users": await config.guild(guild).dm_users(),
|
"dm_users": await config.guild(ctx.guild).dm_users(),
|
||||||
"log_channel": await config.guild(guild).log_channel(),
|
"log_channel": await config.guild(ctx.guild).log_channel(),
|
||||||
"history_ephemeral": await config.guild(guild).history_ephemeral(),
|
"history_ephemeral": await config.guild(ctx.guild).history_ephemeral(),
|
||||||
"history_inline": await config.guild(guild).history_inline(),
|
"history_inline": await config.guild(ctx.guild).history_inline(),
|
||||||
"history_pagesize": await config.guild(guild).history_pagesize(),
|
"history_pagesize": await config.guild(ctx.guild).history_pagesize(),
|
||||||
"history_inline_pagesize": await config.guild(guild).history_inline_pagesize(),
|
"history_inline_pagesize": await config.guild(ctx.guild).history_inline_pagesize(),
|
||||||
"auto_evidenceformat": await config.guild(guild).auto_evidenceformat(),
|
"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:
|
if channel is None:
|
||||||
channel = warning("Not Set")
|
channel = warning("Not Set")
|
||||||
else:
|
else:
|
||||||
channel = channel.mention
|
channel = channel.mention
|
||||||
|
|
||||||
guild_str = [
|
guild_str = [
|
||||||
bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']),
|
'- '+ bold("Show Moderator: ") + get_bool_emoji(guild_settings['show_moderator']),
|
||||||
bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']),
|
'- '+ bold("Use Discord Permissions: ") + get_bool_emoji(guild_settings['use_discord_permissions']),
|
||||||
bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']),
|
'- '+ bold("Ignore Modlog: ") + get_bool_emoji(guild_settings['ignore_modlog']),
|
||||||
bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']),
|
'- '+ bold("Ignore Other Bots: ") + get_bool_emoji(guild_settings['ignore_other_bots']),
|
||||||
bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']),
|
'- '+ bold("DM Users: ") + get_bool_emoji(guild_settings['dm_users']),
|
||||||
bold("Log Channel: ") + channel,
|
'- '+ bold("Log Channel: ") + channel,
|
||||||
bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']),
|
'- '+ bold("Auto Evidence Format: ") + get_bool_emoji(guild_settings['auto_evidenceformat']),
|
||||||
bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']),
|
'- '+ bold("Ephemeral: ") + get_bool_emoji(guild_settings['history_ephemeral']),
|
||||||
bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']),
|
'- '+ bold("History Inline: ") + get_bool_emoji(guild_settings['history_inline']),
|
||||||
bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']),
|
'- '+ bold("History Pagesize: ") + get_pagesize_str(guild_settings['history_pagesize']),
|
||||||
bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize'])
|
'- '+ bold("History Inline Pagesize: ") + get_pagesize_str(guild_settings['history_inline_pagesize'])
|
||||||
]
|
]
|
||||||
guild_str = '\n'.join(guild_str)
|
guild_str = '\n'.join(guild_str)
|
||||||
return 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."""
|
"""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:
|
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)
|
whitelist = '\n'.join(whitelist)
|
||||||
else:
|
else:
|
||||||
whitelist = warning("No roles are on the addrole whitelist!")
|
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 = await _core(ctx)
|
||||||
e.title += ": Addrole Whitelist"
|
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
|
return e
|
||||||
|
|
||||||
async def immune_embed(ctx: commands.Context) -> Embed:
|
async def immune(ctx: commands.Context) -> str:
|
||||||
"""Generates the immune roles embed for a guild."""
|
"""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 = await _core(ctx)
|
||||||
e.title += ": Immune Roles"
|
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
|
return e
|
||||||
|
|
Loading…
Reference in a new issue