feat(aurora): added configuration options for all of the user overrides

This commit is contained in:
Seaswimmer 2024-01-16 10:57:21 +00:00
parent c0ab9e89f3
commit c55cb53a41
Signed by untrusted user: cswimr
GPG key ID: D74DDDDF420E13DF
2 changed files with 103 additions and 35 deletions

View file

@ -1,7 +1,8 @@
from discord import ui, ButtonStyle, Interaction, SelectOption from discord import ui, ButtonStyle, Interaction
from redbot.core import commands from redbot.core import commands
from aurora.configuration.embed import embed from aurora.configuration.embed import embed
from aurora.configuration.utils import create_pagesize_options
from aurora.utilities.config import config from aurora.utilities.config import config
class Overrides(ui.View): class Overrides(ui.View):
@ -9,50 +10,104 @@ class Overrides(ui.View):
super().__init__() super().__init__()
self.ctx = ctx self.ctx = ctx
@ui.select(cls=ui.Select, placeholder="Auto Evidence Format", row=0, options=[ @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0)
SelectOption(label="Enabled", value=1, emoji=""), async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
SelectOption(label="Disabled", value=0, emoji=""),
SelectOption(label="Default", value='None', emoji="🔁")
])
async def auto_evidenceformat(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument
await interaction.response.defer()
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
if select.values[0] == 'None': await interaction.response.defer()
current_setting = await config.user(self.ctx.author).auto_evidenceformat()
if current_setting is not None:
await config.user(self.ctx.author).auto_evidenceformat.set(not current_setting)
else:
await config.user(self.ctx.author).auto_evidenceformat.set(True)
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="X", style=ButtonStyle.red, row=0)
async def auto_evidenceformat_reset(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()
await config.user(self.ctx.author).auto_evidenceformat.clear() await config.user(self.ctx.author).auto_evidenceformat.clear()
else:
await config.user(self.ctx.author).auto_evidenceformat.set(bool(int(select.values[0])))
await interaction.message.edit(embed=await embed(self.ctx)) await interaction.message.edit(embed=await embed(self.ctx))
@ui.select(cls=ui.Select, placeholder="Epheremal", row=1, options=[ @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0)
SelectOption(label="Enabled", value=1, emoji=""), async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
SelectOption(label="Disabled", value=0, emoji=""),
SelectOption(label="Default", value='None', emoji="🔁")
])
async def ephemeral(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument
await interaction.response.defer()
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
if select.values[0] == 'None': await interaction.response.defer()
current_setting = await config.user(self.ctx.author).history_ephemeral()
if current_setting:
await config.user(self.ctx.author).history_ephemeral.set(not current_setting)
else:
await config.user(self.ctx.author).history_ephemeral.set(True)
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="X", style=ButtonStyle.red, row=0)
async def ephemeral_reset(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()
await config.user(self.ctx.author).history_ephemeral.clear() await config.user(self.ctx.author).history_ephemeral.clear()
else:
await config.user(self.ctx.author).history_ephemeral.set(bool(int(select.values[0])))
await interaction.message.edit(embed=await embed(self.ctx)) await interaction.message.edit(embed=await embed(self.ctx))
@ui.select(cls=ui.Select, placeholder="Inline", row=2, options=[ @ui.button(label="Inline", style=ButtonStyle.green, row=0)
SelectOption(label="Enabled", value=1, emoji=""), async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
SelectOption(label="Disabled", value=0, emoji=""),
SelectOption(label="Default", value='None', emoji="🔁")
])
async def inline(self, interaction: Interaction, select: ui.Select): # pylint: disable=unused-argument
await interaction.response.defer()
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.followup.send("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
if select.values[0] == 'None': await interaction.response.defer()
await config.user(self.ctx.author).history_inline.clear() current_setting = await config.user(self.ctx.author).history_inline()
if current_setting:
await config.user(self.ctx.author).history_inline.set(not current_setting)
else: else:
await config.user(self.ctx.author).history_inline.set(bool(int(select.values[0]))) await config.user(self.ctx.author).history_inline.set(True)
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="X", style=ButtonStyle.red, row=0)
async def inline_reset(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()
await config.user(self.ctx.author).history_inline.clear()
await interaction.message.edit(embed=await embed(self.ctx))
@ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1)
async def inline_pagesize(self, select: ui.Select, interaction: Interaction): # 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()
await config.user(self.ctx.author).history_inline_pagesize.set(int(select.values[0]))
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="X", style=ButtonStyle.red, row=1)
async def inline_pagesize_reset(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()
await config.user(self.ctx.author).history_inline_pagesize.clear()
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="Pagesize", options=create_pagesize_options(), row=2)
async def pagesize(self, select: ui.Select, interaction: Interaction): # 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()
await config.user(self.ctx.author).history_pagesize.set(int(select.values[0]))
await interaction.message.edit(embed=await embed(self.ctx))
@ui.button(label="X", style=ButtonStyle.red, row=2)
async def pagesize_reset(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()
await config.user(self.ctx.author).history_pagesize.clear()
await interaction.message.edit(embed=await embed(self.ctx)) await interaction.message.edit(embed=await embed(self.ctx))

View file

@ -1,5 +1,7 @@
from typing import Union from typing import Union
from discord import SelectOption
def get_bool_emoji(value: bool) -> str: def get_bool_emoji(value: bool) -> str:
"""Returns a unicode emoji based on a boolean value.""" """Returns a unicode emoji based on a boolean value."""
if value is True: if value is True:
@ -13,3 +15,14 @@ def get_pagesize_str(value: Union[int, None]) -> str:
if value is None: if value is None:
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}" return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
return str(value) + " cases per page" return str(value) + " cases per page"
def create_pagesize_options() -> list[SelectOption]:
"""Returns a list of SelectOptions for pagesize configuration."""
return [
SelectOption(
label=str(i),
value=str(i),
description=f"Set the pagesize to {i}.",
)
for i in range(1, 21)
]