[3.4] Catch overflow errors for mutes time conversion (#5605) (#5739)

(cherry picked from commit c8ff3c4cce)

Co-authored-by: TrustyJAID <TrustyJAID@gmail.com>

Co-authored-by: TrustyJAID <TrustyJAID@gmail.com>
This commit is contained in:
Red-GitHubBot
2022-06-04 03:04:13 +02:00
committed by GitHub
parent d88bdba092
commit d8bbf1c4c7

View File

@@ -5,6 +5,7 @@ from datetime import timedelta
from discord.ext.commands.converter import Converter
from redbot.core import commands
from redbot.core import i18n
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_SPLIT = re.compile(r"t(?:ime)?=")
_ = i18n.Translator("Mutes", __file__)
class MuteTime(Converter):
"""
@@ -50,6 +53,11 @@ class MuteTime(Converter):
if v:
time_data[k] = int(v)
if time_data:
result["duration"] = timedelta(**time_data)
try:
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()
return result