diff options
Diffstat (limited to 'bot/converters.py')
| -rw-r--r-- | bot/converters.py | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/bot/converters.py b/bot/converters.py index 3bf05cfb3..595809517 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -236,35 +236,6 @@ class Snowflake(IDConverter): return snowflake -class Subreddit(Converter): - """Forces a string to begin with "r/" and checks if it's a valid subreddit.""" - - @staticmethod - async def convert(ctx: Context, sub: str) -> str: - """ - Force sub to begin with "r/" and check if it's a valid subreddit. - - If sub is a valid subreddit, return it prepended with "r/" - """ - sub = sub.lower() - - if not sub.startswith("r/"): - sub = f"r/{sub}" - - resp = await ctx.bot.http_session.get( - "https://www.reddit.com/subreddits/search.json", - params={"q": sub} - ) - - json = await resp.json() - if not json["data"]["children"]: - raise BadArgument( - f"The subreddit `{sub}` either doesn't exist, or it has no posts." - ) - - return sub - - class TagNameConverter(Converter): """ Ensure that a proposed tag name is valid. @@ -445,11 +416,11 @@ class HushDurationConverter(Converter): MINUTES_RE = re.compile(r"(\d+)(?:M|m|$)") - async def convert(self, ctx: Context, argument: str) -> t.Optional[int]: + async def convert(self, ctx: Context, argument: str) -> int: """ Convert `argument` to a duration that's max 15 minutes or None. - If `"forever"` is passed, None is returned; otherwise an int of the extracted time. + If `"forever"` is passed, -1 is returned; otherwise an int of the extracted time. Accepted formats are: * <duration>, * <duration>m, @@ -457,7 +428,7 @@ class HushDurationConverter(Converter): * forever. """ if argument == "forever": - return None + return -1 match = self.MINUTES_RE.match(argument) if not match: raise BadArgument(f"{argument} is not a valid minutes duration.") |