about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Tools/MassCMEBan.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-03-22 17:47:29 +0100
committerRory& <root@rory.gay>2024-03-22 17:47:29 +0100
commitc69e5c790b2b277d9b11265b8f0883e9f90fe3b9 (patch)
treea2ad72230772d7459605ebc4ba13337e70d3bda4 /MatrixUtils.Web/Pages/Tools/MassCMEBan.razor
parentChanges (diff)
downloadMatrixUtils-c69e5c790b2b277d9b11265b8f0883e9f90fe3b9.tar.xz
Changes
Diffstat (limited to 'MatrixUtils.Web/Pages/Tools/MassCMEBan.razor')
-rw-r--r--MatrixUtils.Web/Pages/Tools/MassCMEBan.razor75
1 files changed, 75 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Tools/MassCMEBan.razor b/MatrixUtils.Web/Pages/Tools/MassCMEBan.razor
new file mode 100644
index 0000000..cbbca9e
--- /dev/null
+++ b/MatrixUtils.Web/Pages/Tools/MassCMEBan.razor
@@ -0,0 +1,75 @@
+@page "/Tools/MassCMEBan"
+@using ArcaneLibs.Extensions
+@using LibMatrix.RoomTypes
+@using System.Collections.ObjectModel
+@using LibMatrix
+@using System.Collections.Frozen
+@using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.EventTypes.Spec.State.Policy
+@using MatrixUtils.Abstractions
+<h3>User Trace</h3>
+<hr/>
+
+<br/>
+<span>Users:</span>
+<InputTextArea @bind-Value="@roomId"></InputTextArea>
+<LinkButton OnClick="@Execute">Execute</LinkButton>
+
+<br/>
+
+<br/>
+@foreach (var line in log.Reverse()) {
+    <pre>@line</pre>
+}
+
+@code {
+    // TODO: Properly implement page to be more useful
+    private ObservableCollection<string> log { get; set; } = new();
+    private AuthenticatedHomeserverGeneric hs { get; set; }
+    
+    [Parameter, SupplyParameterFromQuery(Name = "room")]
+    public string roomId { get; set; }
+    
+
+    protected override async Task OnInitializedAsync() {
+        log.CollectionChanged += (sender, args) => StateHasChanged();
+        hs = await RMUStorage.GetCurrentSessionOrNavigate();
+        if (hs is null) return;
+       
+        StateHasChanged();
+        Console.WriteLine("Rerendered!");
+        await base.OnInitializedAsync();
+    }
+
+    private async Task<string> Execute() {
+        var room = hs.GetRoom("!fTjMjIzNKEsFlUIiru:neko.dev");
+        // var room = hs.GetRoom("!yf7OpOiRDXx6zUGpT6:conduit.rory.gay");
+        var users = roomId.Split("\n").Select(x => x.Trim()).Where(x=>x.StartsWith('@')).ToList();
+        foreach (var user in users) {
+            var exists = false;
+            try {
+                exists = !string.IsNullOrWhiteSpace((await room.GetStateAsync<UserPolicyRuleEventContent>(UserPolicyRuleEventContent.EventId, user.Replace('@', '_'))).Entity);
+            } catch (Exception e) {
+                log.Add($"Failed to get {user}");
+            }
+
+            if (!exists) {
+                var evt = await room.SendStateEventAsync(UserPolicyRuleEventContent.EventId, user.Replace('@', '_'), new UserPolicyRuleEventContent() {
+                    Entity = user,
+                    Reason = "spam (invite)",
+                    Recommendation = "m.ban"
+                });
+                log.Add($"Sent {evt.EventId} to ban {user}");
+            }
+            else {
+                log.Add($"User {user} already exists");
+            }
+        }
+        
+        
+        StateHasChanged();
+
+        return "";
+    }
+
+}
\ No newline at end of file