From 9dcce18cda5317ea1150eed06d6589b6285577e6 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 4 Sep 2023 06:29:00 +0200 Subject: Add start of Media Moderator PoC bot --- LibMatrix/RoomTypes/GenericRoom.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'LibMatrix/RoomTypes/GenericRoom.cs') diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 3ba965b..8ba9a4b 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using System.Web; using LibMatrix.Extensions; @@ -83,6 +84,7 @@ public class GenericRoom { return res ?? new MessagesResponse(); } + // TODO: should we even error handle here? public async Task GetNameAsync() { try { var res = await GetStateAsync("m.room.name"); @@ -103,6 +105,8 @@ public class GenericRoom { }); } + + // TODO: rewrite (members endpoint?) public async IAsyncEnumerable GetMembersAsync(bool joinedOnly = true) { var res = GetFullStateAsync(); await foreach (var member in res) { @@ -112,6 +116,9 @@ public class GenericRoom { } } + +#region Utility shortcuts + public async Task> GetAliasesAsync() { var res = await GetStateAsync("m.room.aliases"); return res.Aliases; @@ -143,6 +150,13 @@ public class GenericRoom { return res.Type; } + public async Task GetPowerLevelAsync() => + await GetStateAsync("m.room.power_levels"); + +#endregion + + + public async Task ForgetAsync() => await _httpClient.PostAsync($"/_matrix/client/v3/rooms/{RoomId}/forget", null); @@ -169,7 +183,9 @@ public class GenericRoom { public async Task SendMessageEventAsync(string eventType, RoomMessageEventData content) { var res = await _httpClient.PutAsJsonAsync( - $"/_matrix/client/v3/rooms/{RoomId}/send/{eventType}/" + Guid.NewGuid(), content); + $"/_matrix/client/v3/rooms/{RoomId}/send/{eventType}/" + Guid.NewGuid(), content, new JsonSerializerOptions() { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }); var resu = await res.Content.ReadFromJsonAsync(); return resu; } @@ -207,4 +223,8 @@ public class GenericRoom { } public readonly SpaceRoom AsSpace; + + public async Task GetEvent(string eventId) { + return await _httpClient.GetFromJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}"); + } } -- cgit 1.4.1