Add confirmation to settings clear, closes #82
This commit is contained in:
parent
6c1753d5d2
commit
c4e822d732
1 changed files with 29 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
|||
"""J.A.R.V.I.S. Settings Management Cog."""
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from dis_snek import InteractionContext, Scale, Snake
|
||||
from dis_snek.models.discord.channel import GuildText
|
||||
from dis_snek.models.discord.components import ActionRow, Button, ButtonStyles
|
||||
from dis_snek.models.discord.embed import EmbedField
|
||||
from dis_snek.models.discord.enums import Permissions
|
||||
from dis_snek.models.discord.role import Role
|
||||
|
@ -236,9 +238,33 @@ class SettingsCog(Scale):
|
|||
@settings.subcommand(sub_cmd_name="clear", sub_cmd_description="Clear all settings")
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _clear(self, ctx: InteractionContext) -> None:
|
||||
async for setting in Setting.find(q(guild=ctx.guild.id)):
|
||||
await setting.delete()
|
||||
await ctx.send("Guild settings cleared")
|
||||
components = [
|
||||
ActionRow(
|
||||
Button(style=ButtonStyles.RED, emoji="✖️", custom_id="no"),
|
||||
Button(style=ButtonStyles.GREEN, emoji="✔️", custom_id="yes"),
|
||||
)
|
||||
]
|
||||
message = await ctx.send("***Are you sure?***", components=components)
|
||||
try:
|
||||
context = await self.bot.wait_for_component(
|
||||
check=lambda x: ctx.author.id == x.context.author.id,
|
||||
messages=message,
|
||||
timeout=60 * 5,
|
||||
)
|
||||
if context.context.custom_id == "yes":
|
||||
async for setting in Setting.find(q(guild=ctx.guild.id)):
|
||||
await setting.delete()
|
||||
await ctx.send("Guild settings cleared")
|
||||
else:
|
||||
for row in components:
|
||||
for component in row.components:
|
||||
component.disabled = True
|
||||
await message.edit(components=components)
|
||||
except asyncio.TimeoutError:
|
||||
for row in components:
|
||||
for component in row.components:
|
||||
component.disabled = True
|
||||
await message.edit(components=components)
|
||||
|
||||
|
||||
def setup(bot: Snake) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue