Merge pull request 'Aurora Configuration Rewrite' (#15) from aurora-config-rewrite into main
Reviewed-on: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs/pulls/15
This commit is contained in:
commit
860eccb52a
10 changed files with 622 additions and 496 deletions
|
@ -1,204 +1,88 @@
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
## auroraset
|
/// admonition | Work in progress
|
||||||
- Usage: `[p]auroraset`
|
type: warning
|
||||||
- Aliases: `moderationset, modset, moderationsettings, aurorasettings, and auroraconfig`
|
This page is still a work in progress.
|
||||||
|
///
|
||||||
|
|
||||||
Manage moderation commands.
|
## aurora
|
||||||
|
|
||||||
### auroraset ignorebots
|
- Usage: `[p]aurora`
|
||||||
- Usage: `[p]auroraset ignorebots`
|
- Aliases: `moderation and mod`
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Toggle if the cog should ignore other bots' moderations.
|
Settings and miscellaneous commands for Aurora.
|
||||||
|
|
||||||
### auroraset user
|
### aurora import
|
||||||
- Usage: `[p]auroraset user`
|
|
||||||
|
|
||||||
Manage configurations for user configuration options.
|
- Usage: `[p]aurora import`
|
||||||
|
- Restricted to: `ADMIN`
|
||||||
|
- Checks: `server_only`
|
||||||
|
|
||||||
#### auroraset user history
|
Import moderation history from other bots.
|
||||||
- Usage: `[p]auroraset user history`
|
|
||||||
|
|
||||||
Manage configuration for the /history command.
|
#### aurora import aurora
|
||||||
|
|
||||||
##### auroraset user history inline
|
- Usage: `[p]aurora import aurora`
|
||||||
- Usage: `[p]auroraset user history inline`
|
- Restricted to: `ADMIN`
|
||||||
|
|
||||||
Manage configuration for the /history command's inline argument.
|
Import moderation history from another bot using Aurora.
|
||||||
|
|
||||||
###### auroraset user history inline toggle
|
#### aurora import galacticbot
|
||||||
- Usage: `[p]auroraset user history inline toggle <enabled>`
|
|
||||||
|
|
||||||
Enable the /history command's inline argument by default.
|
- Usage: `[p]aurora import galacticbot`
|
||||||
|
- Restricted to: `ADMIN`
|
||||||
|
|
||||||
##### auroraset user history inline pagesize
|
Import moderation history from GalacticBot.
|
||||||
- Usage: `[p]auroraset user history inline pagesize <pagesize>`
|
|
||||||
|
|
||||||
Set the amount of cases to display per page.
|
### aurora settings
|
||||||
|
|
||||||
#### auroraset user history pagesize
|
- Usage: `[p]aurora settings`
|
||||||
- Usage: `[p]auroraset user history pagesize <pagesize>`
|
- Aliases: `config, options, and set`
|
||||||
|
|
||||||
Set the amount of cases to display per page.
|
Configure Aurora's settings.
|
||||||
|
|
||||||
#### auroraset user history ephemeral
|
#### aurora settings server
|
||||||
- Usage: `[p]auroraset user history ephemeral <enabled>`
|
|
||||||
- Aliases: `hidden and hide`
|
|
||||||
|
|
||||||
Toggle if the /history command should be ephemeral.
|
- Usage: `[p]aurora settings server`
|
||||||
|
- Restricted to: `ADMIN`
|
||||||
|
- Aliases: `server`
|
||||||
|
- Checks: `server_only`
|
||||||
|
|
||||||
### auroraset user autoevidence
|
Manage Aurora's server settings.
|
||||||
- Usage: `[p]auroraset user autoevidence <enabled>`
|
|
||||||
|
|
||||||
Toggle if the evidenceformat codeblock should be sent automatically.
|
#### aurora settings overrides
|
||||||
|
|
||||||
## auroraset server
|
- Usage: `[p]aurora settings overrides`
|
||||||
- Usage: `[p]auroraset server`
|
- Aliases: `override and user`
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Manage default configurations for user configuration options, per server.
|
Manage Aurora's user overriddable settings.
|
||||||
|
|
||||||
### auroraset server history
|
#### aurora settings addrole
|
||||||
- Usage: `[p]auroraset server history`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Manage configuration for the /history command.
|
- Usage: `[p]aurora settings addrole`
|
||||||
|
- Restricted to: `ADMIN`
|
||||||
|
- Aliases: `removerole`
|
||||||
|
- Checks: `server_only`
|
||||||
|
|
||||||
#### auroraset server history inline
|
Manage the addrole whitelist.
|
||||||
- Usage: `[p]auroraset server history inline`
|
Roles added to this list are also applied to `/removerole`.
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Manage configuration for the /history command's inline argument.
|
#### aurora settings immunity
|
||||||
|
|
||||||
##### auroraset server history inline pagesize
|
- Usage: `[p]aurora settings immunity`
|
||||||
- Usage: `[p]auroraset server history inline pagesize <pagesize>`
|
- Restricted to: `ADMIN`
|
||||||
- Restricted to: `ADMIN`
|
- Checks: `server_only`
|
||||||
|
|
||||||
Set the amount of cases to display per page.
|
Manage the immunity whitelist.
|
||||||
|
|
||||||
##### auroraset server history inline toggle
|
### aurora timedelta
|
||||||
- Usage: `[p]auroraset server history inline toggle <enabled>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Enable the /history command's inline argument by default.
|
- Usage: `[p]aurora timedelta <duration>`
|
||||||
|
- Aliases: `tdc, td, and timedeltaconvert`
|
||||||
|
|
||||||
#### auroraset server history ephemeral
|
This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
||||||
- Usage: `[p]auroraset server history ephemeral <enabled>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
- Aliases: `hidden and hide`
|
|
||||||
|
|
||||||
Toggle if the /history command should be ephemeral.
|
**Example usage**
|
||||||
|
`[p]timedelta 1 day 15hr 82 minutes 52s`
|
||||||
#### auroraset server history pagesize
|
**Output**
|
||||||
- Usage: `[p]auroraset server history pagesize <pagesize>`
|
`1 day, 16:22:52`
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Set the amount of cases to display per page.
|
|
||||||
|
|
||||||
### auroraset server autoevidence
|
|
||||||
- Usage: `[p]auroraset server autoevidence <enabled>`
|
|
||||||
|
|
||||||
Toggle if the evidenceformat codeblock should be sent automatically.
|
|
||||||
|
|
||||||
## auroraset showmoderator
|
|
||||||
- Usage: `[p]auroraset showmoderator`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Toggle if the cog should show the moderator in the case embed when dming a user.
|
|
||||||
|
|
||||||
## auroraset immunity
|
|
||||||
- Usage: `[p]auroraset immunity`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Manage configuration for immune roles.
|
|
||||||
|
|
||||||
### auroraset immunity add
|
|
||||||
- Usage: `[p]auroraset immunity add <role>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Add a role to the immune roles list.
|
|
||||||
|
|
||||||
### auroraset immunity remove
|
|
||||||
- Usage: `[p]auroraset immunity remove <role>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Remove a role from the immune roles list.
|
|
||||||
|
|
||||||
### auroraset immunity list
|
|
||||||
- Usage: `[p]auroraset immunity list`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
List all immune roles.
|
|
||||||
|
|
||||||
## auroraset permissions
|
|
||||||
- Usage: `[p]auroraset permissions`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Toggle whether the bot will check for discord permissions.
|
|
||||||
|
|
||||||
## auroraset logchannel
|
|
||||||
- Usage: `[p]auroraset logchannel [channel=None]`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Set a channel to log infractions to.
|
|
||||||
|
|
||||||
## auroraset import
|
|
||||||
- Usage: `[p]auroraset import`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Import moderations from other bots.
|
|
||||||
|
|
||||||
### auroraset import galacticbot
|
|
||||||
- Usage: `[p]auroraset import galacticbot`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Import moderations from GalacticBot.
|
|
||||||
|
|
||||||
### auroraset import aurora
|
|
||||||
- Usage: `[p]auroraset import aurora`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Import moderations from another bot using Aurora.
|
|
||||||
|
|
||||||
## auroraset dm
|
|
||||||
- Usage: `[p]auroraset dm`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Toggle automatically messaging moderated users.<br/><br/>This option can be overridden by specifying the `silent` argument in any moderation command.
|
|
||||||
|
|
||||||
## auroraset list
|
|
||||||
- Usage: `[p]auroraset list`
|
|
||||||
- Aliases: `view and show`
|
|
||||||
|
|
||||||
List all moderation settings.
|
|
||||||
|
|
||||||
## auroraset blacklist
|
|
||||||
- Usage: `[p]auroraset blacklist`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Manage configuration for the /blacklist command.
|
|
||||||
|
|
||||||
### auroraset blacklist list
|
|
||||||
- Usage: `[p]auroraset blacklist list`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
List all blacklist types.
|
|
||||||
|
|
||||||
### auroraset blacklist remove
|
|
||||||
- Usage: `[p]auroraset blacklist remove <role>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Remove a role's blacklist type.
|
|
||||||
|
|
||||||
### auroraset blacklist add
|
|
||||||
- Usage: `[p]auroraset blacklist add <role> <duration>`
|
|
||||||
- Restricted to: `ADMIN`
|
|
||||||
|
|
||||||
Add a role to the blacklist.
|
|
||||||
|
|
||||||
# timedeltaconvert
|
|
||||||
- Usage: `[p]timedeltaconvert <duration>`
|
|
||||||
- Aliases: `tdc`
|
|
||||||
|
|
||||||
This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.<br/><br/>**Example usage**<br/>`[p]timedeltaconvert 1 day 15hr 82 minutes 52s`<br/>**Output**<br/>`1 day, 16:22:52`
|
|
||||||
|
|
407
aurora/aurora.py
407
aurora/aurora.py
|
@ -16,17 +16,22 @@ import discord
|
||||||
import humanize
|
import humanize
|
||||||
from discord.ext import tasks
|
from discord.ext import tasks
|
||||||
from pytimeparse2 import disable_dateutil, parse
|
from pytimeparse2 import disable_dateutil, parse
|
||||||
from redbot.core import app_commands, checks, commands, data_manager
|
from redbot.core import app_commands, commands, data_manager
|
||||||
from redbot.core.app_commands import Choice
|
from redbot.core.app_commands import Choice
|
||||||
|
from redbot.core.bot import Red
|
||||||
from redbot.core.utils.chat_formatting import box, error, warning
|
from redbot.core.utils.chat_formatting import box, error, warning
|
||||||
|
|
||||||
from .importers.galacticbot import ImportGalacticBotView
|
from aurora.importers.aurora import ImportAuroraView
|
||||||
from .importers.aurora import ImportAuroraView
|
from aurora.importers.galacticbot import ImportGalacticBotView
|
||||||
from .utilities.config import config, register_config
|
from aurora.menus.addrole import Addrole
|
||||||
from .utilities.database import connect, create_guild_table, fetch_case, mysql_log
|
from aurora.menus.guild import Guild
|
||||||
from .utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory
|
from aurora.menus.immune import Immune
|
||||||
from .utilities.logger import logger
|
from aurora.menus.overrides import Overrides
|
||||||
from .utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat
|
from aurora.utilities.config import config, register_config
|
||||||
|
from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log
|
||||||
|
from aurora.utilities.factory import case_factory, changes_factory, evidenceformat_factory, message_factory, overrides_embed, immune_embed, guild_embed, addrole_embed
|
||||||
|
from aurora.utilities.logger import logger
|
||||||
|
from aurora.utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat
|
||||||
|
|
||||||
|
|
||||||
class Aurora(commands.Cog):
|
class Aurora(commands.Cog):
|
||||||
|
@ -65,7 +70,8 @@ class Aurora(commands.Cog):
|
||||||
else:
|
else:
|
||||||
logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester)
|
logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester)
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot: Red):
|
||||||
|
super().__init__()
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
register_config(config)
|
register_config(config)
|
||||||
disable_dateutil()
|
disable_dateutil()
|
||||||
|
@ -745,6 +751,7 @@ class Aurora(commands.Cog):
|
||||||
|
|
||||||
if case_dict['moderation_type'] in ['UNMUTE', 'UNBAN']:
|
if case_dict['moderation_type'] in ['UNMUTE', 'UNBAN']:
|
||||||
await interaction.response.send_message(content=error("You cannot resolve this type of moderation!"), ephemeral=True)
|
await interaction.response.send_message(content=error("You cannot resolve this type of moderation!"), ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
if case_dict['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']:
|
if case_dict['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']:
|
||||||
if case_dict['moderation_type'] == 'MUTE':
|
if case_dict['moderation_type'] == 'MUTE':
|
||||||
|
@ -1016,336 +1023,96 @@ class Aurora(commands.Cog):
|
||||||
completion_time = (time.time() - current_time) * 1000
|
completion_time = (time.time() - current_time) * 1000
|
||||||
logger.debug("Completed expiry loop in %sms with %s users unbanned", f"{completion_time:.6f}", global_num)
|
logger.debug("Completed expiry loop in %sms with %s users unbanned", f"{completion_time:.6f}", global_num)
|
||||||
|
|
||||||
#######################################################################################################################
|
########################################################################################################################
|
||||||
### CONFIGURATION COMMANDS
|
### Configuration Commands #
|
||||||
#######################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@commands.group(autohelp=True, aliases=['moderationset', 'modset', 'moderationsettings', 'aurorasettings', 'auroraconfig'])
|
@commands.group(autohelp=True, aliases=["moderation", "mod"])
|
||||||
async def auroraset(self, ctx: commands.Context):
|
async def aurora(self, ctx: commands.Context):
|
||||||
"""Manage moderation commands."""
|
"""Settings and miscellaneous commands for Aurora."""
|
||||||
|
|
||||||
@auroraset.command(name='list', aliases=['view', 'show'])
|
@aurora.group(autohelp=True, name="settings", aliases=["config", "options", "set"])
|
||||||
async def auroraset_list(self, ctx: commands.Context):
|
async def aurora_settings(self, ctx: commands.Context):
|
||||||
"""List all moderation settings."""
|
"""Configure Aurora's settings."""
|
||||||
if ctx.guild:
|
|
||||||
guild_settings = await config.guild(ctx.guild).all()
|
|
||||||
|
|
||||||
guild_settings_string = ""
|
@aurora_settings.command(name="overrides", aliases=["override", "user"])
|
||||||
for setting in guild_settings:
|
async def aurora_settings_overrides(self, ctx: commands.Context):
|
||||||
if 'roles' in setting:
|
"""Manage Aurora's user overriddable settings."""
|
||||||
continue
|
await ctx.send(embed=await overrides_embed(ctx), view=Overrides(ctx))
|
||||||
if setting == 'log_channel':
|
|
||||||
channel = ctx.guild.get_channel(guild_settings[setting])
|
|
||||||
guild_settings_string += f"**{setting}**: {channel.mention}\n" if channel else f"**{setting}**: {guild_settings[setting]}\n"
|
|
||||||
else:
|
|
||||||
guild_settings_string += f"**{setting}**: {guild_settings[setting]}\n"
|
|
||||||
|
|
||||||
user_settings = await config.user(ctx.author).all()
|
@aurora_settings.command(name="guild", aliases=["server"])
|
||||||
user_settings_string = ""
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
for setting in user_settings:
|
@commands.guild_only()
|
||||||
user_settings_string += f"**{setting}**: {user_settings[setting]}\n"
|
async def aurora_settings_guild(self, ctx: commands.Context):
|
||||||
|
"""Manage Aurora's guild settings."""
|
||||||
|
await ctx.send(embed=await guild_embed(ctx), view=Guild(ctx))
|
||||||
|
|
||||||
embed = discord.Embed(color=await self.bot.get_embed_color(ctx.channel))
|
@aurora_settings.command(name="addrole", aliases=["removerole"])
|
||||||
embed.set_author(icon_url=ctx.guild.icon.url, name=f"{ctx.guild.name} Moderation Settings")
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
if ctx.guild:
|
@commands.guild_only()
|
||||||
embed.add_field(name="Guild Settings", value=guild_settings_string)
|
async def aurora_settings_addrole(self, ctx: commands.Context):
|
||||||
embed.add_field(name="User Settings", value=user_settings_string)
|
"""Manage the addrole whitelist.
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
Roles added to this list are also applied to `/removerole`."""
|
||||||
|
await ctx.send(embed=await addrole_embed(ctx), view=Addrole(ctx))
|
||||||
|
|
||||||
@auroraset.group(autohelp=True, name='user')
|
@aurora_settings.command(name="immunity")
|
||||||
async def auroraset_user(self, ctx: commands.Context):
|
@commands.admin_or_permissions(manage_guild=True)
|
||||||
"""Manage configurations for user configuration options."""
|
@commands.guild_only()
|
||||||
|
async def aurora_settings_immunity(self, ctx: commands.Context):
|
||||||
|
"""Manage the immunity whitelist."""
|
||||||
|
await ctx.send(embed=await immune_embed(ctx), view=Immune(ctx))
|
||||||
|
|
||||||
@auroraset_user.command(name='autoevidence')
|
@aurora.group(autohelp=True, name="import")
|
||||||
async def auroraset_user_autoevidence(self, ctx: commands.Context, enabled: bool):
|
@commands.admin()
|
||||||
"""Toggle if the evidenceformat codeblock should be sent automatically."""
|
@commands.guild_only()
|
||||||
await config.user(ctx.author).auto_evidenceformat.set(enabled)
|
async def aurora_import(self, ctx: commands.Context):
|
||||||
await ctx.send(f"Auto evidenceformat setting set to {enabled}")
|
"""Import moderation history from other bots."""
|
||||||
|
|
||||||
@auroraset_user.group(autohelp=True, name='history')
|
@aurora_import.command(name="aurora")
|
||||||
async def auroraset_user_history(self, ctx: commands.Context):
|
@commands.admin()
|
||||||
"""Manage configuration for the /history command."""
|
async def aurora_import_aurora(self, ctx: commands.Context):
|
||||||
|
"""Import moderation history from another bot using Aurora."""
|
||||||
@auroraset_user_history.command(name='ephemeral', aliases=['hidden', 'hide'])
|
if (
|
||||||
async def auroraset_user_history_ephemeral(self, ctx: commands.Context, enabled: bool):
|
ctx.message.attachments
|
||||||
"""Toggle if the /history command should be ephemeral."""
|
and ctx.message.attachments[0].content_type
|
||||||
await config.user(ctx.author).history_ephemeral.set(enabled)
|
== "application/json; charset=utf-8"
|
||||||
await ctx.send(f"Ephemeral setting set to {enabled}")
|
):
|
||||||
|
message = await ctx.send(
|
||||||
@auroraset_user_history.command(name='pagesize')
|
warning(
|
||||||
async def auroraset_user_history_pagesize(self, ctx: commands.Context, pagesize: int):
|
"Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"
|
||||||
"""Set the amount of cases to display per page."""
|
)
|
||||||
if pagesize > 20:
|
)
|
||||||
await ctx.send("Pagesize cannot be greater than 20!")
|
|
||||||
return
|
|
||||||
if pagesize < 1:
|
|
||||||
await ctx.send("Pagesize cannot be less than 1!")
|
|
||||||
return
|
|
||||||
await config.user(ctx.author).history_pagesize.set(pagesize)
|
|
||||||
await ctx.send(f"Pagesize set to {await config.user(ctx.author).history_pagesize()}")
|
|
||||||
|
|
||||||
@auroraset_user_history.group(name='inline')
|
|
||||||
async def auroraset_user_history_inline(self, ctx: commands.Context):
|
|
||||||
"""Manage configuration for the /history command's inline argument."""
|
|
||||||
|
|
||||||
@auroraset_user_history_inline.command(name='toggle')
|
|
||||||
async def auroraset_user_history_inline_toggle(self, ctx: commands.Context, enabled: bool):
|
|
||||||
"""Enable the /history command's inline argument by default."""
|
|
||||||
await config.user(ctx.author).history_inline.set(enabled)
|
|
||||||
await ctx.send(f"Inline setting set to {enabled}")
|
|
||||||
|
|
||||||
@auroraset_user_history_inline.command(name='pagesize')
|
|
||||||
async def auroraset_user_history_inline_pagesize(self, ctx: commands.Context, pagesize: int):
|
|
||||||
"""Set the amount of cases to display per page."""
|
|
||||||
if pagesize > 20:
|
|
||||||
await ctx.send(error("Pagesize cannot be greater than 20!"))
|
|
||||||
return
|
|
||||||
if pagesize < 1:
|
|
||||||
await ctx.send(error("Pagesize cannot be less than 1!"))
|
|
||||||
return
|
|
||||||
await config.user(ctx.author).history_inline_pagesize.set(pagesize)
|
|
||||||
await ctx.send(f"Inline pagesize set to {await config.user(ctx.author).history_inline_pagesize()}")
|
|
||||||
|
|
||||||
@auroraset.group(autohelp=True, name='guild')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild(self, ctx: commands.Context):
|
|
||||||
"""Manage default configurations for user configuration options, per guild."""
|
|
||||||
|
|
||||||
@auroraset_guild.command(name='autoevidence')
|
|
||||||
async def auroraset_guild_autoevidence(self, ctx: commands.Context, enabled: bool):
|
|
||||||
"""Toggle if the evidenceformat codeblock should be sent automatically."""
|
|
||||||
await config.guild(ctx.guild).auto_evidenceformat.set(enabled)
|
|
||||||
await ctx.send(f"Auto evidenceformat setting set to {enabled}")
|
|
||||||
|
|
||||||
@auroraset_guild.group(autohelp=True, name='history')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history(self, ctx: commands.Context):
|
|
||||||
"""Manage configuration for the /history command."""
|
|
||||||
|
|
||||||
@auroraset_guild_history.command(name='ephemeral', aliases=['hidden', 'hide'])
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history_ephemeral(self, ctx: commands.Context, enabled: bool):
|
|
||||||
"""Toggle if the /history command should be ephemeral."""
|
|
||||||
await config.guild(ctx.guild).history_ephemeral.set(enabled)
|
|
||||||
await ctx.send(f"Ephemeral setting set to {enabled}")
|
|
||||||
|
|
||||||
@auroraset_guild_history.command(name='pagesize')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history_pagesize(self, ctx: commands.Context, pagesize: int):
|
|
||||||
"""Set the amount of cases to display per page."""
|
|
||||||
if pagesize > 20:
|
|
||||||
await ctx.send("Pagesize cannot be greater than 20!")
|
|
||||||
return
|
|
||||||
if pagesize < 1:
|
|
||||||
await ctx.send("Pagesize cannot be less than 1!")
|
|
||||||
return
|
|
||||||
await config.guild(ctx.guild).history_pagesize.set(pagesize)
|
|
||||||
await ctx.send(f"Pagesize set to {await config.guild(ctx.guild).history_pagesize()}")
|
|
||||||
|
|
||||||
@auroraset_guild_history.group(name='inline')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history_inline(self, ctx: commands.Context):
|
|
||||||
"""Manage configuration for the /history command's inline argument."""
|
|
||||||
|
|
||||||
@auroraset_guild_history_inline.command(name='toggle')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history_inline_toggle(self, ctx: commands.Context, enabled: bool):
|
|
||||||
"""Enable the /history command's inline argument by default."""
|
|
||||||
await config.guild(ctx.guild).history_inline.set(enabled)
|
|
||||||
await ctx.send(f"Inline setting set to {enabled}")
|
|
||||||
|
|
||||||
@auroraset_guild_history_inline.command(name='pagesize')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_guild_history_inline_pagesize(self, ctx: commands.Context, pagesize: int):
|
|
||||||
"""Set the amount of cases to display per page."""
|
|
||||||
if pagesize > 20:
|
|
||||||
await ctx.send("Pagesize cannot be greater than 20!")
|
|
||||||
return
|
|
||||||
if pagesize < 1:
|
|
||||||
await ctx.send("Pagesize cannot be less than 1!")
|
|
||||||
return
|
|
||||||
await config.guild(ctx.guild).history_inline_pagesize.set(pagesize)
|
|
||||||
await ctx.send(f"Inline pagesize set to {await config.guild(ctx.guild).history_inline_pagesize()}")
|
|
||||||
|
|
||||||
@auroraset.group(autohelp=True, name='immunity')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_immunity(self, ctx: commands.Context):
|
|
||||||
"""Manage configuration for immune roles."""
|
|
||||||
|
|
||||||
@auroraset_immunity.command(name='add')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_immunity_add(self, ctx: commands.Context, role: discord.Role):
|
|
||||||
"""Add a role to the immune roles list."""
|
|
||||||
immune_roles: list = await config.guild(ctx.guild).immune_roles()
|
|
||||||
if role.id in immune_roles:
|
|
||||||
await ctx.send(error("Role is already immune!"))
|
|
||||||
return
|
|
||||||
immune_roles.append(role.id)
|
|
||||||
await config.guild(ctx.guild).immune_roles.set(immune_roles)
|
|
||||||
await ctx.send(f"Role {role.name} added to immune roles.")
|
|
||||||
|
|
||||||
@auroraset_immunity.command(name='remove')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_immunity_remove(self, ctx: commands.Context, role: discord.Role):
|
|
||||||
"""Remove a role from the immune roles list."""
|
|
||||||
immune_roles: list = await config.guild(ctx.guild).immune_roles()
|
|
||||||
if role.id not in immune_roles:
|
|
||||||
await ctx.send(error("Role is not immune!"))
|
|
||||||
return
|
|
||||||
immune_roles.remove(role.id)
|
|
||||||
await config.guild(ctx.guild).immune_roles.set(immune_roles)
|
|
||||||
await ctx.send(f"Role {role.name} removed from immune roles.")
|
|
||||||
|
|
||||||
@auroraset_immunity.command(name='list')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_immunity_list(self, ctx: commands.Context):
|
|
||||||
"""List all immune roles."""
|
|
||||||
immune_roles: list = await config.guild(ctx.guild).immune_roles()
|
|
||||||
if not immune_roles:
|
|
||||||
await ctx.send("No immune roles set!")
|
|
||||||
return
|
|
||||||
role_list = ""
|
|
||||||
for role_id in immune_roles:
|
|
||||||
role = ctx.guild.get_role(role_id)
|
|
||||||
if role:
|
|
||||||
role_list += f"{role.mention}\n"
|
|
||||||
if role_list:
|
|
||||||
embed = discord.Embed(title="Immune Roles", description=role_list, color=await self.bot.get_embed_color(ctx.channel))
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@auroraset.group(autohelp=True, name='blacklist')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_blacklist(self, ctx: commands.Context):
|
|
||||||
"""Manage configuration for the /blacklist command."""
|
|
||||||
|
|
||||||
@auroraset_blacklist.command(name='add')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_blacklist_add(self, ctx: commands.Context, role: discord.Role, duration: str):
|
|
||||||
"""Add a role to the blacklist."""
|
|
||||||
blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles()
|
|
||||||
for blacklist_role in blacklist_roles:
|
|
||||||
if role.id == blacklist_role['role']:
|
|
||||||
await ctx.send(error("Role already has an associated blacklist type!"))
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
|
|
||||||
except ValueError:
|
|
||||||
await ctx.send(error("Please provide a valid duration!"))
|
|
||||||
return
|
|
||||||
|
|
||||||
blacklist_roles.append(
|
|
||||||
{
|
|
||||||
'role': role.id,
|
|
||||||
'duration': str(parsed_time)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
await config.guild(ctx.guild).blacklist_roles.set(blacklist_roles)
|
|
||||||
await ctx.send(f"Role {role.mention} added as a blacklist type.", allowed_mentions=discord.AllowedMentions.none())
|
|
||||||
|
|
||||||
@auroraset_blacklist.command(name='remove')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_blacklist_remove(self, ctx: commands.Context, role: discord.Role):
|
|
||||||
"""Remove a role's blacklist type."""
|
|
||||||
blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles()
|
|
||||||
for blacklist_role in blacklist_roles:
|
|
||||||
if role.id == blacklist_role['role']:
|
|
||||||
blacklist_roles.remove(blacklist_role)
|
|
||||||
await config.guild(ctx.guild).blacklist_roles.set(blacklist_roles)
|
|
||||||
await ctx.send(f"Role {role.mention} removed from blacklist types.", allowed_mentions=discord.AllowedMentions.none())
|
|
||||||
return
|
|
||||||
await ctx.send(error("Role does not have an associated blacklist type!"))
|
|
||||||
|
|
||||||
@auroraset_blacklist.command(name='list')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_blacklist_list(self, ctx: commands.Context):
|
|
||||||
"""List all blacklist types."""
|
|
||||||
blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles()
|
|
||||||
if not blacklist_roles:
|
|
||||||
await ctx.send("No blacklist types set!")
|
|
||||||
return
|
|
||||||
blacklist_list = ""
|
|
||||||
for blacklist_role in blacklist_roles:
|
|
||||||
role = ctx.guild.get_role(blacklist_role['role'])
|
|
||||||
if role:
|
|
||||||
blacklist_list += f"{role.mention} - {blacklist_role['duration']}\n"
|
|
||||||
if blacklist_list:
|
|
||||||
embed = discord.Embed(title="Blacklist Types", description=blacklist_list, color=await self.bot.get_embed_color(ctx.channel))
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@auroraset.command(name="ignorebots")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_ignorebots(self, ctx: commands.Context):
|
|
||||||
"""Toggle if the cog should ignore other bots' moderations."""
|
|
||||||
await config.guild(ctx.guild).ignore_other_bots.set(not await config.guild(ctx.guild).ignore_other_bots())
|
|
||||||
await ctx.send(f"Ignore bots setting set to {await config.guild(ctx.guild).ignore_other_bots()}")
|
|
||||||
|
|
||||||
@auroraset.command(name="dm")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_dm(self, ctx: commands.Context):
|
|
||||||
"""Toggle automatically messaging moderated users.
|
|
||||||
|
|
||||||
This option can be overridden by specifying the `silent` argument in any moderation command."""
|
|
||||||
await config.guild(ctx.guild).dm_users.set(not await config.guild(ctx.guild).dm_users())
|
|
||||||
await ctx.send(f"DM users setting set to {await config.guild(ctx.guild).dm_users()}")
|
|
||||||
|
|
||||||
@auroraset.command(name="permissions")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_permissions(self, ctx: commands.Context):
|
|
||||||
"""Toggle whether the bot will check for discord permissions."""
|
|
||||||
await config.guild(ctx.guild).use_discord_permissions.set(not await config.guild(ctx.guild).use_discord_permissions())
|
|
||||||
await ctx.send(f"Use Discord Permissions setting set to {await config.guild(ctx.guild).use_discord_permissions()}")
|
|
||||||
|
|
||||||
@auroraset.command(name="logchannel")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_logchannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
|
||||||
"""Set a channel to log infractions to."""
|
|
||||||
if channel:
|
|
||||||
await config.guild(ctx.guild).log_channel.set(channel.id)
|
|
||||||
await ctx.send(f"Logging channel set to {channel.mention}.")
|
|
||||||
else:
|
|
||||||
await config.guild(ctx.guild).log_channel.set(" ")
|
|
||||||
await ctx.send(warning("Logging channel disabled."))
|
|
||||||
|
|
||||||
@auroraset.command(name="showmoderator")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_showmoderator(self, ctx: commands.Context):
|
|
||||||
"""Toggle if the cog should show the moderator in the case embed when dming a user."""
|
|
||||||
await config.guild(ctx.guild).show_moderator.set(not await config.guild(ctx.guild).show_moderator())
|
|
||||||
await ctx.send(f"Show moderator setting set to {await config.guild(ctx.guild).show_moderator()}")
|
|
||||||
|
|
||||||
@auroraset.group(autohelp=True, name='import')
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_import(self, ctx: commands.Context):
|
|
||||||
"""Import moderations from other bots."""
|
|
||||||
|
|
||||||
@auroraset_import.command(name="aurora")
|
|
||||||
@checks.admin()
|
|
||||||
async def auroraset_import_aurora(self, ctx: commands.Context):
|
|
||||||
"""Import moderations from another bot using Aurora."""
|
|
||||||
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8':
|
|
||||||
message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"))
|
|
||||||
await message.edit(view=ImportAuroraView(60, ctx, message))
|
await message.edit(view=ImportAuroraView(60, ctx, message))
|
||||||
else:
|
else:
|
||||||
await ctx.send(error("Please provide a valid Aurora export file."))
|
await ctx.send(error("Please provide a valid Aurora export file."))
|
||||||
|
|
||||||
@auroraset_import.command(name="galacticbot")
|
@aurora_import.command(name="galacticbot")
|
||||||
@checks.admin()
|
@commands.admin()
|
||||||
async def auroraset_import_galacticbot(self, ctx: commands.Context):
|
async def aurora_import_galacticbot(self, ctx: commands.Context):
|
||||||
"""Import moderations from GalacticBot."""
|
"""Import moderation history from GalacticBot."""
|
||||||
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8':
|
if (
|
||||||
message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"))
|
ctx.message.attachments
|
||||||
|
and ctx.message.attachments[0].content_type
|
||||||
|
== "application/json; charset=utf-8"
|
||||||
|
):
|
||||||
|
message = await ctx.send(
|
||||||
|
warning(
|
||||||
|
"Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"
|
||||||
|
)
|
||||||
|
)
|
||||||
await message.edit(view=ImportGalacticBotView(60, ctx, message))
|
await message.edit(view=ImportGalacticBotView(60, ctx, message))
|
||||||
else:
|
else:
|
||||||
await ctx.send(error("Please provide a valid GalacticBot moderation export file."))
|
await ctx.send(
|
||||||
|
error("Please provide a valid GalacticBot moderation export file.")
|
||||||
|
)
|
||||||
|
|
||||||
@commands.command(aliases=["tdc"])
|
@aurora.command(aliases=["tdc", 'td', 'timedeltaconvert'])
|
||||||
async def timedeltaconvert(self, ctx: commands.Context, *, duration: str):
|
async def timedelta(self, ctx: commands.Context, *, duration: str):
|
||||||
"""This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
"""This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
||||||
|
|
||||||
**Example usage**
|
**Example usage**
|
||||||
`[p]timedeltaconvert 1 day 15hr 82 minutes 52s`
|
`[p]aurora timedelta 1 day 15hr 82 minutes 52s`
|
||||||
**Output**
|
**Output**
|
||||||
`1 day, 16:22:52`"""
|
`1 day, 16:22:52`"""
|
||||||
try:
|
try:
|
||||||
|
|
0
aurora/menus/__init__.py
Normal file
0
aurora/menus/__init__.py
Normal file
41
aurora/menus/addrole.py
Normal file
41
aurora/menus/addrole.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
from discord import ButtonStyle, ui, Interaction
|
||||||
|
from redbot.core import commands
|
||||||
|
from redbot.core.utils.chat_formatting import error
|
||||||
|
|
||||||
|
from aurora.utilities.factory import addrole_embed
|
||||||
|
from aurora.utilities.config import config
|
||||||
|
|
||||||
|
class Addrole(ui.View):
|
||||||
|
def __init__(self, ctx: commands.Context):
|
||||||
|
super().__init__()
|
||||||
|
self.ctx = ctx
|
||||||
|
|
||||||
|
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
|
||||||
|
async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect):
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You must have the manage guild permission to add roles to the addrole whitelist."), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
addrole_whitelist: list = await config.guild(self.ctx.guild).addrole_whitelist()
|
||||||
|
if select.values[0].id in addrole_whitelist:
|
||||||
|
addrole_whitelist.remove(select.values[0].id)
|
||||||
|
else:
|
||||||
|
addrole_whitelist.append(select.values[0].id)
|
||||||
|
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist)
|
||||||
|
await interaction.message.edit(embed=await addrole_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
|
||||||
|
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's addrole whitelist."), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
await config.guild(self.ctx.guild).addrole_whitelist.clear()
|
||||||
|
await interaction.message.edit(embed=await addrole_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Close", style=ButtonStyle.gray)
|
||||||
|
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.message.delete()
|
124
aurora/menus/guild.py
Normal file
124
aurora/menus/guild.py
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
from discord import ui, ButtonStyle, Interaction
|
||||||
|
from redbot.core import commands
|
||||||
|
|
||||||
|
from aurora.utilities.factory import guild_embed
|
||||||
|
from aurora.utilities.utils import create_pagesize_options
|
||||||
|
from aurora.utilities.config import config
|
||||||
|
|
||||||
|
class Guild(ui.View):
|
||||||
|
def __init__(self, ctx: commands.Context):
|
||||||
|
super().__init__()
|
||||||
|
self.ctx = ctx
|
||||||
|
|
||||||
|
@ui.button(label="Show Moderator", style=ButtonStyle.green, row=0)
|
||||||
|
async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).show_moderator
|
||||||
|
await config.guild(interaction.guild).show_moderator.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0)
|
||||||
|
async def use_discord_permissions(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).use_discord_permissions()
|
||||||
|
await config.guild(interaction.guild).use_discord_permissions.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
|
||||||
|
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).ignore_modlog()
|
||||||
|
await config.guild(interaction.guild).ignore_modlog.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Ignore Other Bots", style=ButtonStyle.green, row=0)
|
||||||
|
async def ignore_other_bots(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).ignore_other_bots()
|
||||||
|
await config.guild(interaction.guild).ignore_other_bots.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="DM Users", style=ButtonStyle.green, row=1)
|
||||||
|
async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).dm_users()
|
||||||
|
await config.guild(interaction.guild).dm_users.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1)
|
||||||
|
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).auto_evidenceformat()
|
||||||
|
await config.guild(interaction.guild).auto_evidenceformat.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Ephemeral", style=ButtonStyle.green, row=1)
|
||||||
|
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).history_ephemeral()
|
||||||
|
await config.guild(interaction.guild).history_ephemeral.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="History Inline", style=ButtonStyle.green, row=1)
|
||||||
|
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.guild(interaction.guild).history_inline()
|
||||||
|
await config.guild(interaction.guild).history_inline.set(not current_setting)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2)
|
||||||
|
async def pagesize(self, interaction: Interaction, select: ui.Select,):
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
if select.values[0] == "default":
|
||||||
|
await config.guild(interaction.guild).history_pagesize.clear()
|
||||||
|
else:
|
||||||
|
await config.guild(interaction.guild).history_pagesize.set(int(select.values[0]))
|
||||||
|
await interaction.response.defer()
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3)
|
||||||
|
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,):
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
if select.values[0] == "default":
|
||||||
|
await config.guild(interaction.guild).history_inline_pagesize.clear()
|
||||||
|
else:
|
||||||
|
await config.guild(interaction.guild).history_inline_pagesize.set(int(select.values[0]))
|
||||||
|
await interaction.response.defer()
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=4)
|
||||||
|
async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect):
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
await config.guild(interaction.guild).log_channel.set(select.values[0].id)
|
||||||
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
42
aurora/menus/immune.py
Normal file
42
aurora/menus/immune.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from discord import ButtonStyle, ui, Interaction
|
||||||
|
from redbot.core import commands
|
||||||
|
from redbot.core.utils.chat_formatting import error
|
||||||
|
|
||||||
|
from aurora.utilities.factory import immune_embed
|
||||||
|
from aurora.utilities.config import config
|
||||||
|
|
||||||
|
class Immune(ui.View):
|
||||||
|
def __init__(self, ctx: commands.Context):
|
||||||
|
super().__init__()
|
||||||
|
self.ctx = ctx
|
||||||
|
|
||||||
|
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
|
||||||
|
async def immune_select(self, interaction: Interaction, select: ui.RoleSelect):
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You must have the manage guild permission to add immune roles."), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
immune_roles: list = await config.guild(self.ctx.guild).immune_roles()
|
||||||
|
for role in select.values:
|
||||||
|
if role.id in immune_roles:
|
||||||
|
immune_roles.remove(role.id)
|
||||||
|
else:
|
||||||
|
immune_roles.append(role.id)
|
||||||
|
await config.guild(self.ctx.guild).immune_roles.set(immune_roles)
|
||||||
|
await interaction.message.edit(embed=await immune_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
|
||||||
|
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's immune roles."), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
await config.guild(self.ctx.guild).immune_roles.clear()
|
||||||
|
await interaction.message.edit(embed=await immune_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Close", style=ButtonStyle.gray)
|
||||||
|
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||||
|
await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.message.delete()
|
80
aurora/menus/overrides.py
Normal file
80
aurora/menus/overrides.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
from discord import ui, ButtonStyle, Interaction
|
||||||
|
from redbot.core import commands
|
||||||
|
|
||||||
|
from aurora.utilities.factory import overrides_embed
|
||||||
|
from aurora.utilities.utils import create_pagesize_options
|
||||||
|
from aurora.utilities.config import config
|
||||||
|
|
||||||
|
class Overrides(ui.View):
|
||||||
|
def __init__(self, ctx: commands.Context):
|
||||||
|
super().__init__()
|
||||||
|
self.ctx = ctx
|
||||||
|
|
||||||
|
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0)
|
||||||
|
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if self.ctx.author != interaction.user:
|
||||||
|
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.user(self.ctx.author).auto_evidenceformat()
|
||||||
|
if current_setting is False:
|
||||||
|
await config.user(self.ctx.author).auto_evidenceformat.clear()
|
||||||
|
elif current_setting is None:
|
||||||
|
await config.user(self.ctx.author).auto_evidenceformat.set(True)
|
||||||
|
else:
|
||||||
|
await config.user(self.ctx.author).auto_evidenceformat.set(False)
|
||||||
|
await interaction.message.edit(embed=await overrides_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Ephemeral", style=ButtonStyle.green, row=0)
|
||||||
|
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if self.ctx.author != interaction.user:
|
||||||
|
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.user(self.ctx.author).history_ephemeral()
|
||||||
|
if current_setting is False:
|
||||||
|
await config.user(self.ctx.author).history_ephemeral.clear()
|
||||||
|
elif current_setting is None:
|
||||||
|
await config.user(self.ctx.author).history_ephemeral.set(True)
|
||||||
|
else:
|
||||||
|
await config.user(self.ctx.author).history_ephemeral.set(False)
|
||||||
|
await interaction.message.edit(embed=await overrides_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.button(label="Inline", style=ButtonStyle.green, row=0)
|
||||||
|
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||||
|
if self.ctx.author != interaction.user:
|
||||||
|
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
current_setting = await config.user(self.ctx.author).history_inline()
|
||||||
|
if current_setting is False:
|
||||||
|
await config.user(self.ctx.author).history_inline.clear()
|
||||||
|
elif current_setting is None:
|
||||||
|
await config.user(self.ctx.author).history_inline.set(True)
|
||||||
|
else:
|
||||||
|
await config.user(self.ctx.author).history_inline.set(False)
|
||||||
|
await interaction.message.edit(embed=await overrides_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1)
|
||||||
|
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,):
|
||||||
|
if self.ctx.author != interaction.user:
|
||||||
|
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
if select.values[0] == "default":
|
||||||
|
await config.user(self.ctx.author).history_inline_pagesize.clear()
|
||||||
|
else:
|
||||||
|
await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0]))
|
||||||
|
await interaction.message.edit(embed=await overrides_embed(self.ctx))
|
||||||
|
|
||||||
|
@ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2)
|
||||||
|
async def pagesize(self, interaction: Interaction, select: ui.Select,):
|
||||||
|
if self.ctx.author != interaction.user:
|
||||||
|
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
if select.values[0] == "default":
|
||||||
|
await config.user(self.ctx.author).history_pagesize.clear()
|
||||||
|
else:
|
||||||
|
await config.user(self.ctx.author).history_pagesize.set(int(select.values[0]))
|
||||||
|
await interaction.message.edit(embed=await overrides_embed(self.ctx))
|
|
@ -16,7 +16,7 @@ def register_config(config_obj: Config):
|
||||||
history_pagesize = 5,
|
history_pagesize = 5,
|
||||||
history_inline_pagesize = 6,
|
history_inline_pagesize = 6,
|
||||||
auto_evidenceformat = False,
|
auto_evidenceformat = False,
|
||||||
blacklist_roles = []
|
addrole_whitelist = []
|
||||||
)
|
)
|
||||||
config_obj.register_user(
|
config_obj.register_user(
|
||||||
history_ephemeral = None,
|
history_ephemeral = None,
|
||||||
|
|
|
@ -5,10 +5,11 @@ from datetime import datetime, timedelta
|
||||||
|
|
||||||
import humanize
|
import humanize
|
||||||
from discord import Color, Embed, Guild, Interaction, InteractionMessage, User, Member
|
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 aurora.utilities.config import config
|
||||||
from .utils import fetch_channel_dict, fetch_user_dict, get_next_case_number
|
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:
|
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']}"
|
content += f"\nReason: {case_dict['reason']}"
|
||||||
|
|
||||||
return box(content, 'prolog')
|
return box(content, 'prolog')
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
### Configuration Embeds #
|
||||||
|
########################################################################################################################
|
||||||
|
|
||||||
|
async def _config(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_embed(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 _config(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_embed(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 _config(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_embed(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 _config(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_embed(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 _config(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 datetime import timedelta as td
|
||||||
from typing import Union
|
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 discord.errors import Forbidden, NotFound
|
||||||
from redbot.core import commands
|
from redbot.core import commands
|
||||||
from redbot.core.utils.chat_formatting import error
|
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
|
minutes = (total_seconds % 3600) // 60
|
||||||
seconds = total_seconds % 60
|
seconds = total_seconds % 60
|
||||||
return f"{hours}:{minutes}:{seconds}"
|
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…
Reference in a new issue