Skip to content

Commit

Permalink
Add snipe deleter
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Jan 10, 2023
1 parent 5456750 commit c2419f4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ModCore/Commands/Moderation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Microsoft.Extensions.Caching.Memory;
using ModCore.Database;
using ModCore.Database.DatabaseEntities;
using ModCore.Database.JsonEntities;
Expand All @@ -22,6 +23,8 @@ public class Moderation : ApplicationCommandModule
public DatabaseContextBuilder Database { private get; set; }
public SharedData Shared { private get; set; }

public IMemoryCache Cache { private get; set; }

[SlashCommand("offtopic", "Moves off-topic chat to another channel.")]
[SlashCommandPermissions(Permissions.ManageMessages)]
public async Task OfftopicAsync(InteractionContext ctx,
Expand Down Expand Up @@ -213,7 +216,7 @@ await ctx.Client.GetInteractionExtension()
users.Add(user5);
users.RemoveAll(x => x == null);

foreach(var cuser in users)
foreach (var cuser in users)
{
if (!(cuser as DiscordMember).PermissionsIn(ctx.Channel).HasPermission(Permissions.AccessChannels))
{
Expand All @@ -231,13 +234,26 @@ await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder()
await thread.SendMessageAsync($"{mentions}, a moderator has created an isolated chat with you" +
$"{(reason != null ? $" for the following reasoning:\n```\n{reason}\n```" : ".")}" +
$"_Said moderator can bring in more members through_ ***@pinging*** _when needed._");

// Add the responsible moderator through a ping
await (await thread.SendMessageAsync(ctx.Member.Mention)).DeleteAsync();

await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder()
.WithContent($"✅ Created a new private thread: {thread.Mention}")
.AsEphemeral());
}

[SlashCommand("unsnipe", "Clears message deletion/update data for this channel.")]
[SlashCommandPermissions(Permissions.ManageMessages)]
public async Task UnsnipeAsync(InteractionContext ctx)
{
var snipeId = $"snipe_{ctx.Channel.Id}";
var eSnipeId = "e" + snipeId;

Cache.Remove(snipeId);
Cache.Remove(eSnipeId);

await ctx.CreateResponseAsync($"Deletion and Edit snipe data for this channel was deleted!");
}
}
}

0 comments on commit c2419f4

Please sign in to comment.