aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-09-09 17:23:26 -0700
committerGravatar MarkKoz <[email protected]>2020-09-09 17:25:50 -0700
commit6556a5cc02c391657e26950ede84a2fb7e4f679e (patch)
treeeaf7ded91a2601e4e60ae5d0c3c89d6966274b94
parentDecorators: replace asyncio.Lock with a custom object (diff)
Decorators: remove locked() decorator
It was not being used anywhere.
-rw-r--r--bot/decorators.py37
1 files changed, 2 insertions, 35 deletions
diff --git a/bot/decorators.py b/bot/decorators.py
index 3418dfd11..333716cf5 100644
--- a/bot/decorators.py
+++ b/bot/decorators.py
@@ -1,17 +1,16 @@
import asyncio
import inspect
import logging
-import random
import typing as t
from collections import defaultdict
from contextlib import suppress
from functools import partial, wraps
from weakref import WeakValueDictionary
-from discord import Colour, Embed, Member, NotFound
+from discord import Member, NotFound
from discord.ext.commands import Cog, Context, check
-from bot.constants import Channels, ERROR_REPLIES, RedirectOutput
+from bot.constants import Channels, RedirectOutput
from bot.errors import LockedResourceError
from bot.utils import LockGuard, function
from bot.utils.checks import in_whitelist_check, with_role_check, without_role_check
@@ -67,38 +66,6 @@ def without_role(*role_ids: int) -> t.Callable:
return check(predicate)
-def locked() -> t.Callable:
- """
- Allows the user to only run one instance of the decorated command at a time.
-
- Subsequent calls to the command from the same author are ignored until the command has completed invocation.
-
- This decorator must go before (below) the `command` decorator.
- """
- def wrap(func: t.Callable) -> t.Callable:
- func.__locks = WeakValueDictionary()
-
- @wraps(func)
- async def inner(self: Cog, ctx: Context, *args, **kwargs) -> None:
- lock = func.__locks.setdefault(ctx.author.id, asyncio.Lock())
- if lock.locked():
- embed = Embed()
- embed.colour = Colour.red()
-
- log.debug("User tried to invoke a locked command.")
- embed.description = (
- "You're already using this command. Please wait until it is done before you use it again."
- )
- embed.title = random.choice(ERROR_REPLIES)
- await ctx.send(embed=embed)
- return
-
- async with func.__locks.setdefault(ctx.author.id, asyncio.Lock()):
- await func(self, ctx, *args, **kwargs)
- return inner
- return wrap
-
-
def mutually_exclusive(
namespace: t.Hashable,
resource_id: ResourceId,