From b26384dbcf63b2fb4de7b8ec800143d53f163bea Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Thu, 15 Nov 2018 19:59:28 -0500 Subject: [PATCH] Add command cooldowns for booru cog --- src/cogs/booru.py | 8 +++++++- src/run.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index a2d6a0a..35079e3 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -11,7 +11,6 @@ import copy import discord as d from discord import errors as err -from discord import reaction from discord.ext import commands as cmds from discord.ext.commands import errors as errext @@ -382,6 +381,7 @@ class MsG: await e.message.edit(content='\N{NO ENTRY SIGN}') # Reverse image searches a linked image using the public iqdb + @cmds.cooldown(1, 5, cmds.BucketType.member) @cmds.command(name='reverse', aliases=['rev', 'ris'], brief='Reverse image search from e621', description='NSFW\nReverse-search an image with given URL') async def reverse(self, ctx, *args): try: @@ -433,6 +433,7 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @cmds.command(name='reversify', aliases=['revify', 'risify', 'rify']) + @cmds.cooldown(1, 5, cmds.BucketType.member) async def reversify(self, ctx, *args): try: dest = ctx @@ -731,6 +732,7 @@ class MsG: # Creates reaction-based paginator for linked pools @cmds.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format') + @cmds.cooldown(1, 5, cmds.BucketType.member) async def pool_paginator(self, ctx, *args): def on_reaction(reaction, user): if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and (user is ctx.author or user.permissions_in(reaction.message.channel).manage_messages): @@ -868,6 +870,7 @@ class MsG: @cmds.command(name='e621page', aliases=['e621p', 'e6p', '6p']) @checks.is_nsfw() + @cmds.cooldown(1, 5, cmds.BucketType.member) async def e621_paginator(self, ctx, *args): def on_reaction(reaction, user): if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and (user is ctx.author or user.permissions_in(reaction.message.channel).manage_messages): @@ -1032,6 +1035,7 @@ class MsG: # await ctx.message.add_reaction('\N{NO ENTRY}') @cmds.command(name='e926page', aliases=['e926p', 'e9p', '9p']) + @cmds.cooldown(1, 5, cmds.BucketType.member) async def e926_paginator(self, ctx, *args): def on_reaction(reaction, user): if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and (user is ctx.author or user.permissions_in(reaction.message.channel).manage_messages): @@ -1190,6 +1194,7 @@ class MsG: # Searches for and returns images from e621.net given tags when not blacklisted @cmds.command(aliases=['e6', '6'], brief='e621 | NSFW', description='e621 | NSFW\nTag-based search for e621.net\n\nYou can only search 5 tags and 6 images at once for now.\ne6 [tags...] ([# of images])') @checks.is_nsfw() + @cmds.cooldown(1, 5, cmds.BucketType.member) async def e621(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args, limit=3) @@ -1241,6 +1246,7 @@ class MsG: # Searches for and returns images from e926.net given tags when not blacklisted @cmds.command(aliases=['e9', '9'], brief='e926 | SFW', description='e926 | SFW\nTag-based search for e926.net\n\nYou can only search 5 tags and 6 images at once for now.\ne9 [tags...] ([# of images])') + @cmds.cooldown(1, 5, cmds.BucketType.member) async def e926(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args, limit=3) diff --git a/src/run.py b/src/run.py index 22bd2d5..92c9139 100644 --- a/src/run.py +++ b/src/run.py @@ -159,7 +159,11 @@ async def on_error(error, *args, **kwargs): @bot.event async def on_command_error(ctx, error): - if isinstance(error, err.NotFound): + if isinstance(error, errext.CommandOnCooldown): + await ctx.message.add_reaction('\N{HOURGLASS}') + await asyncio.sleep(error.retry_after) + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + elif isinstance(error, err.NotFound): print('NOT FOUND') elif isinstance(error, err.Forbidden): pass