"""The MIT License (MIT)Copyright (c) 2024-present Developer AnonymousPermission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationthe rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHERDEALINGS IN THE SOFTWARE."""from__future__importannotationsfromenumimportEnumfromtypingimportAnyfromdiscordimportInteraction__all__=("BucketType",)
[docs]classBucketType(Enum):"""Specifies a type of bucket for, e.g. a cooldown. This works in a similar way as :class:`discord.ext.commands.BucketType`, but designed for interactions. To pass a BucketType to a application commands cooldown you must do the following: .. code-block:: python3 @app_commands.command(...) @app_commands.checks.cooldown(rate, per, key=BucketType.default) # Change the bucket type as desired async def my_command(...): ... """default=0"""The default bucket operates on a global basis."""user=1"""The user bucket operates on a per-user basis."""guild=2"""The guild bucket operates on a per-guild basis."""channel=3"""The channel bucket operates on a per-channel basis."""member=4"""The member bucket operates on a per-member basis."""category=5"""The category bucket operates on a per-category basis."""role=6"""The role bucket operates on a per-role basis."""defget_key(self,interaction:Interaction[Any])->Any:ifselfisBucketType.user:returninteraction.user.idifselfisBucketType.guild:returninteraction.guild_idorinteraction.user.idifselfisBucketType.channel:returninteraction.channel_idifselfisBucketType.member:returninteraction.guild_id,interaction.user.idifselfisBucketType.category:return(interaction.channeland(interaction.channel.categoryorinteraction.channel)).id# type: ignoreifselfisBucketType.role:returninteraction.channel_idifinteraction.guild_idisNoneelseinteraction.user.top_role.id# type: ignoredef__call__(self,interaction:Interaction[Any])->Any:returnself.get_key(interaction)