diff --git a/exts/dice/dice_admin.py b/exts/dice/dice_admin.py index 6c1fe0f..9678ece 100644 --- a/exts/dice/dice_admin.py +++ b/exts/dice/dice_admin.py @@ -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( diff --git a/exts/dice/dice_cmds.py b/exts/dice/dice_cmds.py index b97432b..09f977d 100644 --- a/exts/dice/dice_cmds.py +++ b/exts/dice/dice_cmds.py @@ -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.",