Catch overflow errors for mutes time conversion (#5605)

This commit is contained in:
TrustyJAID 2022-03-18 15:48:32 -06:00 committed by GitHub
parent 193cb3b035
commit c8ff3c4cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ from datetime import timedelta
from discord.ext.commands.converter import Converter from discord.ext.commands.converter import Converter
from redbot.core import commands from redbot.core import commands
from redbot.core import i18n
log = logging.getLogger("red.cogs.mutes") log = logging.getLogger("red.cogs.mutes")
@ -26,6 +27,8 @@ TIME_RE_STRING = r"|".join(
TIME_RE = re.compile(TIME_RE_STRING, re.I) TIME_RE = re.compile(TIME_RE_STRING, re.I)
TIME_SPLIT = re.compile(r"t(?:ime)?=") TIME_SPLIT = re.compile(r"t(?:ime)?=")
_ = i18n.Translator("Mutes", __file__)
class MuteTime(Converter): class MuteTime(Converter):
""" """
@ -50,6 +53,11 @@ class MuteTime(Converter):
if v: if v:
time_data[k] = int(v) time_data[k] = int(v)
if time_data: if time_data:
try:
result["duration"] = timedelta(**time_data) result["duration"] = timedelta(**time_data)
except OverflowError:
raise commands.BadArgument(
_("The time provided is too long; use a more reasonable time.")
)
result["reason"] = argument.strip() result["reason"] = argument.strip()
return result return result