Skip to content
Merged
Changes from all commits
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
28 changes: 24 additions & 4 deletions DiscordBot/Modules/ReminderModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Discord.Commands;
using Discord.WebSocket;
using DiscordBot.Services;
using DiscordBot.Settings;
using DiscordBot.Attributes;
using System.Text.RegularExpressions;

namespace DiscordBot.Modules;

Expand All @@ -21,13 +23,31 @@ public class ReminderModule : ModuleBase
[Summary("Reminds users of a message based on time. Syntax : !remindme 1hour30min Watch a tutorial")]
public async Task RemindMe(string time, [Remainder] string message)
{
if (Context.Message.MentionedEveryone || Context.Message.MentionedRoleIds.Count > 0 ||
Context.Message.MentionedUserIds.Count > 0)
if (Context.Message.MentionedEveryone || Context.Message.MentionedRoleIds.Count > 0)
{
await ReplyAsync("You can't mention anyone or roles in a reminder.").DeleteAfterSeconds(seconds: 5);
await ReplyAsync("You can't mention groups or roles in a reminder.").DeleteAfterSeconds(seconds: 5);
return;
}

if (Context.Message.MentionedUserIds.Count > 0)
{
// IUserMessage does not guarantee .MentionedUsers so go through the class instead if possible
if (Context.Message is SocketMessage)
{
var sm = (Context.Message as SocketMessage);
// convert <@123> to **Joe**
foreach (var user in sm.MentionedUsers)
message = Regex.Replace(message, $"[<][@]{user.Id}[>]", user.GetUserPreferredName().ToBold());
// delete any remaining user mentions that are somehow not in the list
message = Regex.Replace(message, $"[<][@][0-9]+[>]", "");
}
else
{
await ReplyAsync($"You can't mention users in a reminder.\n`{message}`").DeleteAfterSeconds(seconds: 5);
return;
}
}

var reminderDate = Utils.Utils.ParseTimeFromString(time);
if (reminderDate < DateTime.Now)
{
Expand Down Expand Up @@ -177,4 +197,4 @@ public async Task RebootReminderService()
}

#endregion
}
}
Loading