about summary refs log tree commit diff
path: root/MiniUtils/Commands/SpamCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MiniUtils/Commands/SpamCommand.cs')
-rw-r--r--MiniUtils/Commands/SpamCommand.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/MiniUtils/Commands/SpamCommand.cs b/MiniUtils/Commands/SpamCommand.cs
new file mode 100644

index 0000000..9f475eb --- /dev/null +++ b/MiniUtils/Commands/SpamCommand.cs
@@ -0,0 +1,44 @@ +using System.Collections.Frozen; +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec; +using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Filters; +using LibMatrix.Helpers; +using LibMatrix.RoomTypes; +using LibMatrix.Utilities.Bot.Interfaces; +using MiniUtils.Classes; +using MiniUtils.Services; + +namespace MiniUtils.Commands; + +public class SpamCommand(IgnoreListManager ignoreListManager) : ICommand { + public string Name => "spam"; + + public string[]? Aliases => []; + + public string Description => "Redact all user's events"; + + public bool Unlisted => false; + + public async Task Invoke(CommandContext ctx) { + var tasks = Enumerable.Range(0, 10000) + .Select(i => SendMessage(ctx.Room, i.ToString())) + .ToList(); + await Task.WhenAll(tasks); + await ctx.Room.SendMessageEventAsync(new MessageBuilder().WithBody($"{Emojis.Recycle}").Build()); + } + + private async Task SendMessage(GenericRoom room, string content) { + bool success; + do { + try { + await room.SendMessageEventAsync(new MessageBuilder().WithBody(content).Build()); + success = true; + } + catch (Exception e) { + success = false; + Console.WriteLine($"Failed to send event {content}: {e}"); + } + } while (!success); + } +} \ No newline at end of file