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
84
85
86
87
88
89
90
91
92
93
94
95
|
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<StateEvent> 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);
}
}
|