Skip to content

Commit 0b1a03a

Browse files
committed
Add collision detection to !anonwarn
1 parent 5fe1ff0 commit 0b1a03a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Commands/WarningCmds.cs

+26
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,32 @@ public async Task AnonWarnCmd(
464464
[RemainingText, Description("The reason for giving this warning.")] string reason = null
465465
)
466466
{
467+
// collision detection
468+
if (mostRecentWarning is not null && targetUser.Id == mostRecentWarning.TargetUserId)
469+
{
470+
var timeSinceLastWarning = DateTime.UtcNow.Subtract(mostRecentWarning.WarnTimestamp);
471+
if (timeSinceLastWarning <= TimeSpan.FromSeconds(5))
472+
{
473+
var response = new DiscordInteractionResponseBuilder()
474+
.WithContent($"{Program.cfgjson.Emoji.Error} {targetUser.Mention} was already warned a few seconds ago, refusing yours to prevent collisions. If your warning is unrelated, try again in a few seconds.")
475+
.AsEphemeral(true);
476+
if (!mostRecentWarning.Stub)
477+
response.AddEmbed(await FancyWarnEmbedAsync(mostRecentWarning, detailed: true));
478+
479+
await ctx.RespondAsync(response);
480+
return;
481+
}
482+
}
483+
484+
// this gets updated with a full warning object later, shove a stub in for now
485+
mostRecentWarning = new()
486+
{
487+
TargetUserId = targetUser.Id,
488+
ModUserId = ctx.User.Id,
489+
WarnTimestamp = DateTime.Now,
490+
Stub = true // make it clear this isn't a real warning
491+
};
492+
467493
DiscordMember targetMember;
468494
try
469495
{

0 commit comments

Comments
 (0)