From d6f33857a3298b824ddab4c264b6e3ffbdbca42f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 3 May 2024 22:20:53 -0400 Subject: [PATCH] feat(aurora): added timeouts to configuration views --- aurora/aurora.py | 12 ++++++++---- aurora/menus/addrole.py | 9 +++++++-- aurora/menus/guild.py | 9 +++++++-- aurora/menus/immune.py | 9 +++++++-- aurora/menus/overrides.py | 9 +++++++-- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index bff9976..0b338c6 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -1788,14 +1788,16 @@ class Aurora(commands.Cog): @aurora_settings.command(name="overrides", aliases=["override", "user"]) async def aurora_settings_overrides(self, ctx: commands.Context): """Manage Aurora's user overriddable settings.""" - await ctx.send(embed=await overrides_embed(ctx), view=Overrides(ctx)) + msg = await ctx.send(embed=await overrides_embed(ctx)) + await msg.edit(view=Overrides(ctx, msg, 180)) @aurora_settings.command(name="guild", aliases=["server"]) @commands.admin_or_permissions(manage_guild=True) @commands.guild_only() 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)) + msg = await ctx.send(embed=await guild_embed(ctx)) + await msg.edit(view=Guild(ctx, msg, 180)) @aurora_settings.command(name="addrole", aliases=["removerole"]) @commands.admin_or_permissions(manage_guild=True) @@ -1804,14 +1806,16 @@ class Aurora(commands.Cog): """Manage the addrole whitelist. Roles added to this list are also applied to `/removerole`.""" - await ctx.send(embed=await addrole_embed(ctx), view=Addrole(ctx)) + msg = await ctx.send(embed=await addrole_embed(ctx)) + await msg.edit(view=Addrole(ctx, msg, 180)) @aurora_settings.command(name="immunity") @commands.admin_or_permissions(manage_guild=True) @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)) + msg = await ctx.send(embed=await immune_embed(ctx)) + await msg.edit(view=Immune(ctx, msg, 180)) @aurora.group(autohelp=True, name="import") @commands.admin() diff --git a/aurora/menus/addrole.py b/aurora/menus/addrole.py index 69f9574..bb02546 100644 --- a/aurora/menus/addrole.py +++ b/aurora/menus/addrole.py @@ -1,4 +1,4 @@ -from discord import ButtonStyle, Interaction, ui +from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands from redbot.core.utils.chat_formatting import error @@ -7,9 +7,14 @@ from aurora.utilities.factory import addrole_embed class Addrole(ui.View): - def __init__(self, ctx: commands.Context): + def __init__(self, ctx: commands.Context, message: Message, timeout: int = 0): super().__init__() self.ctx = ctx + self.message = message + self.timeout = timeout + + async def on_timeout(self): + await self.message.edit(view=None) @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): diff --git a/aurora/menus/guild.py b/aurora/menus/guild.py index 4ef311d..c6e91d3 100644 --- a/aurora/menus/guild.py +++ b/aurora/menus/guild.py @@ -1,4 +1,4 @@ -from discord import ButtonStyle, Interaction, ui +from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands from aurora.utilities.config import config @@ -7,9 +7,14 @@ from aurora.utilities.utils import create_pagesize_options class Guild(ui.View): - def __init__(self, ctx: commands.Context): + def __init__(self, ctx: commands.Context, message: Message, timeout: int = 0): super().__init__() self.ctx = ctx + self.message = message + self.timeout = timeout + + async def on_timeout(self): + await self.message.edit(view=None) @ui.button(label="Show Moderator", style=ButtonStyle.green, row=0) async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument diff --git a/aurora/menus/immune.py b/aurora/menus/immune.py index 15bf0c7..cfe0948 100644 --- a/aurora/menus/immune.py +++ b/aurora/menus/immune.py @@ -1,4 +1,4 @@ -from discord import ButtonStyle, Interaction, ui +from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands from redbot.core.utils.chat_formatting import error @@ -7,9 +7,14 @@ from aurora.utilities.factory import immune_embed class Immune(ui.View): - def __init__(self, ctx: commands.Context): + def __init__(self, ctx: commands.Context, message: Message, timeout: int = 0): super().__init__() self.ctx = ctx + self.message = message + self.timeout = timeout + + async def on_timeout(self): + await self.message.edit(view=None) @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): diff --git a/aurora/menus/overrides.py b/aurora/menus/overrides.py index d98a208..62c663a 100644 --- a/aurora/menus/overrides.py +++ b/aurora/menus/overrides.py @@ -1,4 +1,4 @@ -from discord import ButtonStyle, Interaction, ui +from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands from aurora.utilities.config import config @@ -7,9 +7,14 @@ from aurora.utilities.utils import create_pagesize_options class Overrides(ui.View): - def __init__(self, ctx: commands.Context): + def __init__(self, ctx: commands.Context, message: Message, timeout: int = 0): super().__init__() self.ctx = ctx + self.message = message + self.timeout = timeout + + async def on_timeout(self): + await self.message.edit(view=None) @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