Prevent OverflowError from very large timedeltas in Mutes (#6353)

This commit is contained in:
TrustyJAID
2024-04-20 19:01:28 -06:00
committed by GitHub
parent 47d4675f52
commit 0c9c210dbb
3 changed files with 58 additions and 36 deletions

View File

@@ -3,7 +3,7 @@ from __future__ import annotations
import logging
import re
from typing import Optional, TypedDict
from datetime import timedelta
from datetime import timedelta, datetime, timezone
from typing_extensions import Annotated
from discord.ext.commands.converter import Converter
@@ -29,6 +29,7 @@ def _edgematch(pattern: re.Pattern[str], argument: str) -> Optional[re.Match[str
class _MuteTime(TypedDict, total=False):
duration: timedelta
reason: str
until: datetime
class _MuteTimeConverter(Converter):
@@ -57,6 +58,8 @@ class _MuteTimeConverter(Converter):
)
try:
result["duration"] = duration = timedelta(**time_data)
result["until"] = ctx.message.created_at + duration
# Catch if using the timedelta with the current date will also result in an Overflow error
except OverflowError:
raise commands.BadArgument(
_("The time provided is too long; use a more reasonable time.")