mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 18:02:31 -05:00
Add public positive_int and finite_float converters (#5969)
Co-authored-by: Kreusada <67752638+Kreusada@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
from typing import NewType, TYPE_CHECKING
|
||||
|
||||
from redbot.core.commands import BadArgument, Context, Converter
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils.chat_formatting import inline
|
||||
|
||||
_ = Translator("Cleanup", __file__)
|
||||
|
||||
@@ -15,18 +12,3 @@ class RawMessageIds(Converter):
|
||||
return int(argument)
|
||||
|
||||
raise BadArgument(_("{} doesn't look like a valid message ID.").format(argument))
|
||||
|
||||
|
||||
PositiveInt = NewType("PositiveInt", int)
|
||||
if TYPE_CHECKING:
|
||||
positive_int = PositiveInt
|
||||
else:
|
||||
|
||||
def positive_int(arg: str) -> int:
|
||||
try:
|
||||
ret = int(arg)
|
||||
except ValueError:
|
||||
raise BadArgument(_("{arg} is not an integer.").format(arg=inline(arg)))
|
||||
if ret <= 0:
|
||||
raise BadArgument(_("{arg} is not a positive integer.").format(arg=inline(arg)))
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user