From 8570bd2c9d644c82e69e4c3bbae3af24f95180e2 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Sun, 7 Jun 2020 03:15:51 -0500 Subject: Create cooldown.md --- bot/resources/tags/cooldown.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bot/resources/tags/cooldown.md diff --git a/bot/resources/tags/cooldown.md b/bot/resources/tags/cooldown.md new file mode 100644 index 000000000..a4e237872 --- /dev/null +++ b/bot/resources/tags/cooldown.md @@ -0,0 +1,22 @@ +**Cooldowns** + +Cooldowns are used in discord.py to rate-limit. + +```python +from discord.ext import commands + +class SomeCog(commands.Cog): + def __init__(self): + self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) + + async def cog_check(self, ctx): + bucket = self._cd.get_bucket(ctx.message) + retry_after = bucket.update_rate_limit() + if retry_after: + # you're rate limited + # helpful message here + pass + # you're not rate limited +``` + +`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From 97710d5bb8145d10983187bebe554b845a9c0ef1 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Sun, 7 Jun 2020 03:40:59 -0500 Subject: Update cooldown.md --- bot/resources/tags/cooldown.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/cooldown.md b/bot/resources/tags/cooldown.md index a4e237872..3d34c078b 100644 --- a/bot/resources/tags/cooldown.md +++ b/bot/resources/tags/cooldown.md @@ -1,7 +1,7 @@ **Cooldowns** Cooldowns are used in discord.py to rate-limit. - + ```python from discord.ext import commands -- cgit v1.2.3 From 06d8ab2f7203d4ee92a040444bbb1999a36accb3 Mon Sep 17 00:00:00 2001 From: Daniel Nash Date: Wed, 10 Jun 2020 15:49:14 -0500 Subject: Rename to customcooldown.md --- bot/resources/tags/cooldown.md | 22 ---------------------- bot/resources/tags/customcooldown.md | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 bot/resources/tags/cooldown.md create mode 100644 bot/resources/tags/customcooldown.md diff --git a/bot/resources/tags/cooldown.md b/bot/resources/tags/cooldown.md deleted file mode 100644 index 3d34c078b..000000000 --- a/bot/resources/tags/cooldown.md +++ /dev/null @@ -1,22 +0,0 @@ -**Cooldowns** - -Cooldowns are used in discord.py to rate-limit. - -```python -from discord.ext import commands - -class SomeCog(commands.Cog): - def __init__(self): - self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) - - async def cog_check(self, ctx): - bucket = self._cd.get_bucket(ctx.message) - retry_after = bucket.update_rate_limit() - if retry_after: - # you're rate limited - # helpful message here - pass - # you're not rate limited -``` - -`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md new file mode 100644 index 000000000..3d34c078b --- /dev/null +++ b/bot/resources/tags/customcooldown.md @@ -0,0 +1,22 @@ +**Cooldowns** + +Cooldowns are used in discord.py to rate-limit. + +```python +from discord.ext import commands + +class SomeCog(commands.Cog): + def __init__(self): + self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) + + async def cog_check(self, ctx): + bucket = self._cd.get_bucket(ctx.message) + retry_after = bucket.update_rate_limit() + if retry_after: + # you're rate limited + # helpful message here + pass + # you're not rate limited +``` + +`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From b71ff0f2bbd7be64d1a0009b9e6530ba3c179926 Mon Sep 17 00:00:00 2001 From: Daniel Nash Date: Wed, 10 Jun 2020 15:53:33 -0500 Subject: Update example to not be in a cog --- bot/resources/tags/customcooldown.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index 3d34c078b..35f28a1e5 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -1,22 +1,20 @@ **Cooldowns** -Cooldowns are used in discord.py to rate-limit. +Cooldowns can be used in discord.py to rate-limit. In this example, we're using it in an on_message. ```python from discord.ext import commands -class SomeCog(commands.Cog): - def __init__(self): - self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) +_cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) - async def cog_check(self, ctx): - bucket = self._cd.get_bucket(ctx.message) - retry_after = bucket.update_rate_limit() - if retry_after: - # you're rate limited - # helpful message here - pass - # you're not rate limited +@bot.event +async def on_message(message): + bucket = _cd.get_bucket(message) + retry_after = bucket.update_rate_limit() + if retry_after: + await message.channel.send("Slow down! You're sending messages too fast") + pass + # you're not rate limited ``` `from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From b2195f1990c6720dad6819cc118920b89e24beba Mon Sep 17 00:00:00 2001 From: Daniel Nash Date: Wed, 10 Jun 2020 15:56:00 -0500 Subject: Move the not rate-limited message into else --- bot/resources/tags/customcooldown.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index 35f28a1e5..b44d6b12f 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -13,8 +13,10 @@ async def on_message(message): retry_after = bucket.update_rate_limit() if retry_after: await message.channel.send("Slow down! You're sending messages too fast") + else: + # you're not rate limited pass - # you're not rate limited + # more code here ``` `from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From 76da8f09c7c8d62f8451bc561f020f489b3a0970 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Wed, 10 Jun 2020 17:09:17 -0500 Subject: change _cd to message_cooldown Apply suggestions from code review Co-authored-by: Joseph Banks --- bot/resources/tags/customcooldown.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index b44d6b12f..f304de246 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -5,11 +5,11 @@ Cooldowns can be used in discord.py to rate-limit. In this example, we're using ```python from discord.ext import commands -_cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) +message_cooldown = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) @bot.event async def on_message(message): - bucket = _cd.get_bucket(message) + bucket = message_cooldown.get_bucket(message) retry_after = bucket.update_rate_limit() if retry_after: await message.channel.send("Slow down! You're sending messages too fast") -- cgit v1.2.3 From b1b1765596469b76d6321e81732a54e46d3b5865 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Wed, 10 Jun 2020 17:35:44 -0500 Subject: Update bot/resources/tags/customcooldown.md Co-authored-by: Joseph Banks --- bot/resources/tags/customcooldown.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index f304de246..f7987556d 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -14,9 +14,7 @@ async def on_message(message): if retry_after: await message.channel.send("Slow down! You're sending messages too fast") else: - # you're not rate limited - pass - # more code here + await message.channel.send("Not ratelimited!") ``` `from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From ccd3a17d6a8723cabb21a4b2c7e0d8a835dc9e99 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Fri, 12 Jun 2020 08:42:30 -0500 Subject: Make title more specific Co-authored-by: Mark --- bot/resources/tags/customcooldown.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index f7987556d..4060a9827 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -1,4 +1,4 @@ -**Cooldowns** +**Cooldowns in discord.py** Cooldowns can be used in discord.py to rate-limit. In this example, we're using it in an on_message. -- cgit v1.2.3 From 844726f7bedc8c1d772c5f866a29a52cda6f3a9f Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Fri, 12 Jun 2020 08:48:16 -0500 Subject: Update customcooldown.md --- bot/resources/tags/customcooldown.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index 4060a9827..3f6db0ec6 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -10,6 +10,8 @@ message_cooldown = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.Bu @bot.event async def on_message(message): bucket = message_cooldown.get_bucket(message) + # update_rate_limit returns a time you need to wait before + # trying again retry_after = bucket.update_rate_limit() if retry_after: await message.channel.send("Slow down! You're sending messages too fast") -- cgit v1.2.3 From 08db3df18711ff57a56fef99d0ad725669448f3b Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Fri, 12 Jun 2020 08:50:30 -0500 Subject: Add scheme to URL --- bot/resources/tags/customcooldown.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index 3f6db0ec6..e877e4dae 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -19,4 +19,4 @@ async def on_message(message): await message.channel.send("Not ratelimited!") ``` -`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). +`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType). -- cgit v1.2.3 From efd27cf29f726627b9ba630e257a2e3e89d3a286 Mon Sep 17 00:00:00 2001 From: Daniel Nash <22755628+crazygmr101@users.noreply.github.com> Date: Mon, 15 Jun 2020 13:18:36 -0400 Subject: Update bot/resources/tags/customcooldown.md Co-authored-by: Mark --- bot/resources/tags/customcooldown.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index e877e4dae..ac7e70aee 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -10,11 +10,9 @@ message_cooldown = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.Bu @bot.event async def on_message(message): bucket = message_cooldown.get_bucket(message) - # update_rate_limit returns a time you need to wait before - # trying again retry_after = bucket.update_rate_limit() if retry_after: - await message.channel.send("Slow down! You're sending messages too fast") + await message.channel.send(f"Slow down! Try again in {retry_after} seconds.") else: await message.channel.send("Not ratelimited!") ``` -- cgit v1.2.3