Skip to content

Commit 1e181de

Browse files
authored
Feat: Accept timestamps as valid date format for the !remindme command (#238)
1 parent d4ba0c4 commit 1e181de

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Commands/Reminders.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,24 @@ public async Task RemindMe(
3636
[RemainingText, Description("The text to send when the reminder triggers.")] string reminder
3737
)
3838
{
39-
DateTime t = HumanDateParser.HumanDateParser.Parse(timetoParse);
39+
string discordTimestampRegexExp = @"^<t:(\d+):?\w*>$";
40+
Match matchesDiscordTimestamp = Regex.Match(timetoParse, discordTimestampRegexExp);
41+
42+
43+
DateTime t;
44+
if (matchesDiscordTimestamp.Success)
45+
{
46+
// parse as timestamp
47+
// Extract the Unix timestamp from the matched pattern
48+
long unixTimestamp = long.Parse(matchesDiscordTimestamp.Groups[1].Value);
49+
// Convert the Unix timestamp to a DateTime object
50+
t = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).DateTime;
51+
}
52+
else
53+
{
54+
t = HumanDateParser.HumanDateParser.Parse(timetoParse);
55+
}
56+
4057
if (t <= DateTime.Now)
4158
{
4259
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time can't be in the past!");
@@ -49,6 +66,7 @@ public async Task RemindMe(
4966
return;
5067
}
5168
#endif
69+
5270
string guildId;
5371

5472
if (ctx.Channel.IsPrivate)

0 commit comments

Comments
 (0)