This repository was archived by the owner on Mar 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_spam.cs
More file actions
83 lines (65 loc) · 2.89 KB
/
Commands_spam.cs
File metadata and controls
83 lines (65 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.SlashCommands;
using DSharpPlus.Entities;
using DiscordUrie_DSharpPlus.Attributes;
using Microsoft.Extensions.Logging;
namespace DiscordUrie_DSharpPlus
{
public partial class Commands : ApplicationCommandModule
{
[SlashCommandGroup("s", "Spam remove group"), RequireAuth]
public class SpamStuffGroup : ApplicationCommandModule
{
[SlashCommand("add", "More spam")]
public async Task SpamAddAsync(InteractionContext ctx, [Option("Phrase", "yes")] string Yes, [Option("count", "how many")] long Count)
{
await ctx.CreateResponseAsync(";)", ephemeral: true);
for (int i = 0; i < Count; i++)
{
await ctx.Channel.SendMessageAsync(Yes);
await Task.Delay(1000);
}
}
[SlashCommand("remove", "Mass remove the last x number of messages")]
public async Task SpamRemoveAsync(InteractionContext ctx, [Option("Amount", "Number of messages to remove")] long amount)
{
await ctx.CreateResponseAsync(";)", ephemeral: true);
var Messages = ctx.Channel.GetMessagesBeforeAsync(ctx.InteractionId, Convert.ToInt32(amount));
await ctx.Channel.DeleteMessagesAsync(Messages, $"Spam remove command by '{ctx.Member.DisplayName}'");
}
[SlashCommand("removeSearch", "Mass remove messages from a channel using the key as a search term")]
public async Task SpamRemoveAsync(InteractionContext ctx, [Option("key", "The key to search for.")] string key, [Option("User", "A specific user to search for, this param is optional")] DiscordUser ByUser = null)
{
try
{
List<DiscordMessage> Messages = ctx.Channel.GetMessagesAsync().ToBlockingEnumerable().ToList();
key = key.ToLower();
bool ByUserInput = false;
await ctx.DeferAsync();
ByUserInput |= ByUser != null;
IEnumerable<DiscordMessage> FilteredMessages;
if (ByUserInput)
FilteredMessages = Messages.Where(xr => xr.Content.ToLower().Contains(key) && xr.Author.Id == ByUser.Id);
else
FilteredMessages = Messages.Where(xr => xr.Content.ToLower().Contains(key));
await ctx.Channel.DeleteMessagesAsync(FilteredMessages.ToList(), "Spam Removal Command Deletion");
ctx.Client.Logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, $"Removed {FilteredMessages.Count()} matching messages.");
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Removed {FilteredMessages.Count()} matching messages."));
await Task.Delay(3000);
await ctx.DeleteResponseAsync();
}
catch (Exception ex)
{
DiscordMessage ErrorMessage = await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Something went wrong: {ex.Message}"));
ctx.Client.Logger.Log(LogLevel.Error, $"Error in /s remove; {ex.Message}");
await Task.Delay(5000);
await ctx.DeleteResponseAsync();
}
}
}
}
}