From cf455ed8de20bbee011289223e7d8d5775dfd69e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 5 Sep 2023 06:28:52 +0200 Subject: Media moderator PoC works, abstract command handling to library --- LibMatrix/Helpers/MessageFormatter.cs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 LibMatrix/Helpers/MessageFormatter.cs (limited to 'LibMatrix/Helpers/MessageFormatter.cs') diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs new file mode 100644 index 0000000..ff0a00f --- /dev/null +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -0,0 +1,39 @@ +using ArcaneLibs.Extensions; +using LibMatrix.StateEventTypes.Spec; + +namespace LibMatrix.Helpers; + +public static class MessageFormatter { + public static RoomMessageEventData FormatError(string error) { + return new RoomMessageEventData(body: error, messageType: "m.text") { + FormattedBody = $"{error}: {error}", + Format = "org.matrix.custom.html" + }; + } + + public static RoomMessageEventData FormatException(string error, Exception e) { + return new RoomMessageEventData(body: $"{error}: {e.Message}", messageType: "m.text") { + FormattedBody = $"{error}:
{e.Message}
" + + $"
", + Format = "org.matrix.custom.html" + }; + } + + public static RoomMessageEventData FormatSuccess(string text) { + return new RoomMessageEventData(body: text, messageType: "m.text") { + FormattedBody = $"{text}", + Format = "org.matrix.custom.html" + }; + } + + public static RoomMessageEventData FormatSuccessJson(string text, object data) { + return new RoomMessageEventData(body: text, messageType: "m.text") { + FormattedBody = $"{text}:
{data.ToJson(ignoreNull: true)}
", + Format = "org.matrix.custom.html" + }; + } + + public static string HtmlFormatMention(string id, string? displayName = null) { + return $"{displayName ?? id}"; + } +} -- cgit 1.4.1