aboutsummaryrefslogtreecommitdiff
path: root/discord/ext/commands/cooldowns.py
diff options
context:
space:
mode:
authorBluePhoenixGame <[email protected]>2019-08-12 00:44:16 +0200
committerDanny <[email protected]>2019-08-11 18:44:16 -0400
commitc7d3ebb400cadd685cff4943397f8101c9cc51ec (patch)
tree41c9548a1338da45834664e382302b3d2cf1b429 /discord/ext/commands/cooldowns.py
parentAdd versionadded tags to new ffmpeg related classes. (diff)
downloaddiscord.py-c7d3ebb400cadd685cff4943397f8101c9cc51ec.tar.xz
discord.py-c7d3ebb400cadd685cff4943397f8101c9cc51ec.zip
[commands] Add role cooldown bucket
Diffstat (limited to 'discord/ext/commands/cooldowns.py')
-rw-r--r--discord/ext/commands/cooldowns.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/discord/ext/commands/cooldowns.py b/discord/ext/commands/cooldowns.py
index 5cd305f6..57577a07 100644
--- a/discord/ext/commands/cooldowns.py
+++ b/discord/ext/commands/cooldowns.py
@@ -27,6 +27,8 @@ DEALINGS IN THE SOFTWARE.
from discord.enums import Enum
import time
+from ...abc import PrivateChannel
+
__all__ = (
'BucketType',
'Cooldown',
@@ -40,6 +42,7 @@ class BucketType(Enum):
channel = 3
member = 4
category = 5
+ role = 6
class Cooldown:
__slots__ = ('rate', 'per', 'type', '_window', '_tokens', '_last')
@@ -127,6 +130,12 @@ class CooldownMapping:
return ((msg.guild and msg.guild.id), msg.author.id)
elif bucket_type is BucketType.category:
return (msg.channel.category or msg.channel).id
+ elif bucket_type is BucketType.role:
+ # we return the channel id of a private-channel as there are only roles in guilds
+ # and that yields the same result as for a guild with only the @everyone role
+ # NOTE: PrivateChannel doesn't actually have an id attribute but we assume we are
+ # recieving a DMChannel or GroupChannel which inherit from PrivateChannel and do
+ return (msg.channel if isinstance(msg.channel, PrivateChannel) else msg.author.top_role).id
def _verify_cache_integrity(self, current=None):
# we want to delete all cache objects that haven't been used