|  | 
| 2 | 2 | 
 | 
| 3 | 3 | from __future__ import annotations | 
| 4 | 4 | 
 | 
|  | 5 | +import random | 
| 5 | 6 | import re | 
| 6 | 7 | import shlex | 
| 7 |  | -from datetime import datetime, timezone | 
|  | 8 | +from datetime import datetime, timedelta, timezone | 
| 8 | 9 | 
 | 
| 9 | 10 | import disnake | 
| 10 | 11 | from dateutil import parser | 
| @@ -149,31 +150,40 @@ async def convert(cls, _: disnake.ApplicationCommandInteraction, time_string: st | 
| 149 | 150 |             discord_datetime.utc = datetime(9999, 12, 30, 0, 0, 0, tzinfo=timezone.utc) | 
| 150 | 151 |             return discord_datetime | 
| 151 | 152 | 
 | 
|  | 153 | +        options = ["random"] | 
|  | 154 | +        if time_string.lower() in options: | 
|  | 155 | +            # Generate random time between 10 minutes and 24 hours | 
|  | 156 | +            seconds = random.randint(600, 24 * 3600) | 
|  | 157 | +            time = datetime.now(timezone.utc) + timedelta(seconds=seconds) | 
|  | 158 | +            discord_datetime.local = time.astimezone(get_local_zone()) | 
|  | 159 | +            discord_datetime.utc = time.astimezone(timezone.utc) | 
|  | 160 | +            return discord_datetime | 
|  | 161 | + | 
| 152 | 162 |         pattern = re.compile(r"(\d+)([yYMwdhms])") | 
| 153 | 163 |         matches = pattern.findall(time_string) | 
| 154 | 164 | 
 | 
| 155 | 165 |         if matches: | 
| 156 | 166 |             time = datetime.now(timezone.utc) | 
| 157 |  | -            timedelta = None | 
|  | 167 | +            duration = None | 
| 158 | 168 |             while matches: | 
| 159 | 169 |                 match = matches.pop() | 
| 160 | 170 |                 value, unit = match | 
| 161 | 171 |                 if unit.lower() in ["y", "r"]: | 
| 162 |  | -                    timedelta = relativedelta(years=int(value)) | 
|  | 172 | +                    duration = relativedelta(years=int(value)) | 
| 163 | 173 |                 elif unit == "M": | 
| 164 |  | -                    timedelta = relativedelta(months=int(value)) | 
|  | 174 | +                    duration = relativedelta(months=int(value)) | 
| 165 | 175 |                 elif unit == "w": | 
| 166 |  | -                    timedelta = relativedelta(weeks=int(value)) | 
|  | 176 | +                    duration = relativedelta(weeks=int(value)) | 
| 167 | 177 |                 elif unit == "d": | 
| 168 |  | -                    timedelta = relativedelta(days=int(value)) | 
|  | 178 | +                    duration = relativedelta(days=int(value)) | 
| 169 | 179 |                 elif unit == "h": | 
| 170 |  | -                    timedelta = relativedelta(hours=int(value)) | 
|  | 180 | +                    duration = relativedelta(hours=int(value)) | 
| 171 | 181 |                 elif unit == "m": | 
| 172 |  | -                    timedelta = relativedelta(minutes=int(value)) | 
|  | 182 | +                    duration = relativedelta(minutes=int(value)) | 
| 173 | 183 |                 elif unit == "s": | 
| 174 |  | -                    timedelta = relativedelta(seconds=int(value)) | 
|  | 184 | +                    duration = relativedelta(seconds=int(value)) | 
| 175 | 185 |                 try: | 
| 176 |  | -                    time = time + timedelta | 
|  | 186 | +                    time = time + duration | 
| 177 | 187 |                 except ValueError: | 
| 178 | 188 |                     raise InvalidTime(Messages.time_format) | 
| 179 | 189 |         else: | 
|  | 
0 commit comments