Skip to content

Commit

Permalink
feat: add clear commands for dice
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS committed Oct 7, 2024
1 parent af86bf5 commit d65b616
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
45 changes: 45 additions & 0 deletions exts/dice/dice_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,51 @@ async def dice_remove_from(
embed=utils.make_embed(f"Removed dice {name} from {user.mention}.")
)

@manage.subcommand(
"clear-for",
sub_cmd_description="Clears all dice registered for a user.",
)
async def dice_clear_for(
self,
ctx: utils.THIASlashContext,
user: ipy.Member = tansy.Option("The user to clear dice for."),
) -> None:
if (
await models.DiceEntry.prisma().delete_many(
where={"guild_id": ctx.guild_id, "user_id": user.id}
)
< 1
):
raise ipy.errors.BadArgument("No registered dice found for that user.")
await ctx.send(embed=utils.make_embed(f"Cleared all dice for {user.mention}."))

@manage.subcommand(
"clear-everyone",
sub_cmd_description="Clears all dice registered for everyone.",
)
async def dice_clear_everyone(
self,
ctx: utils.THIASlashContext,
confirm: bool = tansy.Option(
"Actually clear? Set this to true if you're sure.", default=False
),
) -> None:
if not confirm:
raise ipy.errors.BadArgument(
"Confirm option not set to true. Please set the option `confirm` to"
" true to continue."
)

if (
await models.DiceEntry.prisma().delete_many(
where={"guild_id": ctx.guild_id}
)
< 1
):
raise ipy.errors.BadArgument("No registered dice found for this server.")

await ctx.send(embed=utils.make_embed("Cleared all dice for this server."))

@dice_remove_from.autocomplete("name")
@dice_roll_registered_for.autocomplete("name")
async def dice_name_autocomplete(
Expand Down
26 changes: 26 additions & 0 deletions exts/dice/dice_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,32 @@ async def dice_remove(
raise ipy.errors.BadArgument("No registered dice found with that name.")
await ctx.send(embed=utils.make_embed(f"Removed dice {name}."), ephemeral=True)

@dice.subcommand(
"clear",
sub_cmd_description="Clears all of your registered dice.",
)
async def dice_clear(
self,
ctx: utils.THIASlashContext,
confirm: bool = tansy.Option(
"Actually clear? Set this to true if you're sure.", default=False
),
) -> None:
if not confirm:
raise ipy.errors.BadArgument(
"Confirm option not set to true. Please set the option `confirm` to"
" true to continue."
)

if (
await models.DiceEntry.prisma().delete_many(
where={"guild_id": ctx.guild_id, "user_id": ctx.user.id}
)
< 1
):
raise ipy.errors.BadArgument("You have no registered dice to clear.")
await ctx.send(embed=utils.make_embed("Cleared all registered dice."))

@dice.subcommand(
"help",
sub_cmd_description="Shows how to use the dice system.",
Expand Down

0 comments on commit d65b616

Please sign in to comment.