2020units ["seconds" ].append ("secs" )
2121
2222if TYPE_CHECKING :
23+ from discord .ext .commands import Context
2324 from typing_extensions import Self
24- from cogs .utils .context import Context
2525
2626
2727class plural :
@@ -82,7 +82,7 @@ def __init__(self, argument: str, *, now: Optional[datetime.datetime] = None):
8282 self .dt = now + relativedelta (** data )
8383
8484 @classmethod
85- async def convert (cls , ctx : Context , argument : str ) -> Self :
85+ async def convert (cls , ctx : Context , argument : str ) -> Self :
8686 return cls (argument , now = ctx .message .created_at )
8787
8888
@@ -146,14 +146,23 @@ async def transform(self, interaction, value: str) -> datetime.datetime:
146146 return short .dt
147147
148148
149+ ## CHANGE: Added now
149150class FriendlyTimeResult :
150151 dt : datetime .datetime
152+ now : datetime .datetime
151153 arg : str
152154
153- __slots__ = ("dt" , "arg" )
155+ __slots__ = ("dt" , "arg" , "now" )
154156
155- def __init__ (self , dt : datetime .datetime ):
157+ def __init__ (self , dt : datetime .datetime , now : datetime . datetime = None ):
156158 self .dt = dt
159+ self .now = now
160+
161+ if now is None :
162+ self .now = dt
163+ else :
164+ self .now = now
165+
157166 self .arg = ""
158167
159168 async def ensure_constraints (
@@ -162,6 +171,7 @@ async def ensure_constraints(
162171 if self .dt < now :
163172 raise commands .BadArgument ("This time is in the past." )
164173
174+ # CHANGE
165175 # if not remaining:
166176 # if uft.default is None:
167177 # raise commands.BadArgument("Missing argument after the time.")
@@ -200,15 +210,15 @@ async def convert(self, ctx: Context, argument: str) -> FriendlyTimeResult:
200210 if match is not None and match .group (0 ):
201211 data = {k : int (v ) for k , v in match .groupdict (default = 0 ).items ()}
202212 remaining = argument [match .end () :].strip ()
203- result = FriendlyTimeResult (now + relativedelta (** data ))
213+ result = FriendlyTimeResult (now + relativedelta (** data ), now )
204214 await result .ensure_constraints (ctx , self , now , remaining )
205215 return result
206216
207217 if match is None or not match .group (0 ):
208218 match = ShortTime .discord_fmt .match (argument )
209219 if match is not None :
210220 result = FriendlyTimeResult (
211- datetime .datetime .fromtimestamp (int (match .group ("ts" )), tz = datetime .timezone .utc )
221+ datetime .datetime .fromtimestamp (int (match .group ("ts" )), now , tz = datetime .timezone .utc )
212222 )
213223 remaining = argument [match .end () :].strip ()
214224 await result .ensure_constraints (ctx , self , now , remaining )
@@ -226,7 +236,10 @@ async def convert(self, ctx: Context, argument: str) -> FriendlyTimeResult:
226236
227237 elements = calendar .nlp (argument , sourceTime = now )
228238 if elements is None or len (elements ) == 0 :
229- raise commands .BadArgument ('Invalid time provided, try e.g. "tomorrow" or "3 days".' )
239+ # CHANGE
240+ result = FriendlyTimeResult (now )
241+ await result .ensure_constraints (ctx , self , now , argument )
242+ return result
230243
231244 # handle the following cases:
232245 # "date time" foo
@@ -254,7 +267,7 @@ async def convert(self, ctx: Context, argument: str) -> FriendlyTimeResult:
254267 if status .accuracy == pdt .pdtContext .ACU_HALFDAY :
255268 dt = dt .replace (day = now .day + 1 )
256269
257- result = FriendlyTimeResult (dt .replace (tzinfo = datetime .timezone .utc ))
270+ result = FriendlyTimeResult (dt .replace (tzinfo = datetime .timezone .utc ), now )
258271 remaining = ""
259272
260273 if begin in (0 , 1 ):
0 commit comments