using System.Net.Http.Json; using LibMatrix; using LibMatrix.EventTypes.Spec.State.Policy; using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.Extensions; 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 => true; 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()); // for (int i = 0; i < 8; i++) { // _ = ctx.Homeserver.ClientHttpClient.PostAsJsonAsync($"/_matrix/client/unstable/gay.rory.bulk_send_events/rooms/{ctx.Room.RoomId}/bulk_send_events", // CreateMessagesAsync()); // await new MatrixHttpClient(){BaseAddress = new("http://127.0.0.1:8888")}.GetAsync($"/_matrix/client/unstable/gay.rory.bulk_send_events/rooms/{ctx.Room.RoomId}/bulk_send_events"); _ = ctx.Homeserver.ClientHttpClient // _ = new MatrixHttpClient(){BaseAddress = new("http://127.0.0.1:8888")} .PostAsyncEnumerableAsJsonAsync($"/_matrix/client/unstable/gay.rory.bulk_send_events/rooms/{ctx.Room.RoomId}/bulk_send_events?_r={Guid.NewGuid()}", CreateMessagesAsync(ctx.Room)); } } private async IAsyncEnumerable CreateMessagesAsync(GenericRoom room) { int i = 0; // var pls = await room.GetStateEventAsync(RoomPowerLevelEventContent.EventId); // var pls2 = await room.GetStateEventAsync(RoomPowerLevelEventContent.EventId); // if (pls2.TypedContent is RoomPowerLevelEventContent pl2) { // pl2.Ban = 5; // pl2.Users!["@emma:synapse.localhost"] = 102; // pls2.TypedContent = pl2; // } // // yield return new() { // RawContent = pls2.RawContent, // Type = RoomPowerLevelEventContent.EventId, // StateKey = "" // // StateKey = Guid.NewGuid().ToString() // }; while (i++ < 200) { // await Task.Delay(500); Console.WriteLine(i); // yield return new() { // Type = "m.room.message", // TypedContent = new MessageBuilder().WithBody(i.ToString()).Build() // }; // yield return new() { // RawContent = pls.RawContent, // Type = RoomPowerLevelEventContent.EventId, // StateKey = "" // // StateKey = Guid.NewGuid().ToString() // }; yield return new() { TypedContent = new UserPolicyRuleEventContent() { Entity = $"@{Guid.NewGuid()}:{room.Homeserver.ServerName}", }, Type = UserPolicyRuleEventContent.EventId, StateKey = Guid.NewGuid().ToString() }; } } 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); } }