Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Accept timestamps as valid date format for the !remindme command #238

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions Commands/Reminders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,37 @@ public async Task RemindMe(
[RemainingText, Description("The text to send when the reminder triggers.")] string reminder
)
{
DateTime t = HumanDateParser.HumanDateParser.Parse(timetoParse);
if (t <= DateTime.Now)
string discordTimestampRegexExp = @"^<t:(\d+):[a-z]>$";
sthivaios marked this conversation as resolved.
Show resolved Hide resolved
Match matchesDiscordTimestamp = Regex.Match(timetoParse, discordTimestampRegexExp);


DateTime t;
if (matchesDiscordTimestamp.Success)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time can't be in the past!");
return;
// parse as timestamp
// Extract the Unix timestamp from the matched pattern
long unixTimestamp = long.Parse(matchesDiscordTimestamp.Groups[1].Value);
// Convert the Unix timestamp to a DateTime object
t = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).DateTime;
sthivaios marked this conversation as resolved.
Show resolved Hide resolved
}
#if !DEBUG
else if (t < (DateTime.Now + TimeSpan.FromSeconds(59)))
else
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time must be at least a minute in the future!");
return;
}
t = HumanDateParser.HumanDateParser.Parse(timetoParse);
if (t <= DateTime.Now)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time can't be in the past!");
return;
}
#if !DEBUG
else if (t < (DateTime.Now + TimeSpan.FromSeconds(59)))
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Time must be at least a minute in the future!");
return;
}
#endif
}


sthivaios marked this conversation as resolved.
Show resolved Hide resolved
string guildId;

if (ctx.Channel.IsPrivate)
Expand Down