-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bd2e93
commit 572aedb
Showing
2 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Dict, Optional, Callable, Any, final, Tuple, Union | ||
|
||
import discord | ||
from redbot.core import commands | ||
|
||
|
||
@final | ||
class ThreadCooldown(commands.CooldownMapping[commands.Context]): | ||
def __init__( | ||
self, | ||
original: Optional[commands.Cooldown], | ||
type: Callable[[commands.Context], Any], | ||
) -> None: | ||
super().__init__(original, type) | ||
self._cache: Dict[Any, commands.Cooldown] = {} | ||
self._cooldown: Optional[commands.Cooldown] = original | ||
self._type: Callable[[commands.Context], Any] = type | ||
|
||
def __call__(self) -> "ThreadCooldown": | ||
return self | ||
|
||
def get_bucket( | ||
self, message: discord.Message, current: Optional[float] = None | ||
) -> Optional[commands.Cooldown]: | ||
return super().get_bucket(message, current) # type: ignore | ||
|
||
def _bucket_key(self, tup: Tuple[int, Union[int, str]]) -> Tuple[int, Union[int, str]]: | ||
return tup | ||
|
||
def is_rate_limited(self, message: discord.Message) -> bool: | ||
bucket = self.get_bucket(message) | ||
return bucket.update_rate_limit() is not None # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters