From 4ef9ae4b396b0eb37036d4008e8cb40e468dbe73 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 9 Feb 2024 16:32:46 +0100 Subject: Apply syntax style to LibMatrix --- LibMatrix/Helpers/MessageBuilder.cs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'LibMatrix/Helpers/MessageBuilder.cs') diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index 250187a..68f6300 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -8,46 +8,42 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr MessageType = msgType, Format = format }; - + public RoomMessageEventContent Build() => Content; - + public MessageBuilder WithBody(string body) { Content.Body += body; Content.FormattedBody += body; return this; } - + public MessageBuilder WithHtmlTag(string tag, string body, Dictionary? attributes = null) { Content.Body += body; Content.FormattedBody += $"<{tag}"; - if (attributes != null) { - foreach (var (key, value) in attributes) { + if (attributes != null) + foreach (var (key, value) in attributes) Content.FormattedBody += $" {key}=\"{value}\""; - } - } Content.FormattedBody += $">{body}"; return this; } - + public MessageBuilder WithHtmlTag(string tag, Action bodyBuilder, Dictionary? attributes = null) { Content.FormattedBody += $"<{tag}"; - if (attributes != null) { - foreach (var (key, value) in attributes) { + if (attributes != null) + foreach (var (key, value) in attributes) Content.FormattedBody += $" {key}=\"{value}\""; - } - } Content.FormattedBody += ">"; bodyBuilder(this); Content.FormattedBody += $""; return this; } - + public MessageBuilder WithColoredBody(string color, string body) { Content.Body += body; Content.FormattedBody += $"{body}"; return this; } - + public MessageBuilder WithColoredBody(string color, Action bodyBuilder) { Content.FormattedBody += $""; bodyBuilder(this); @@ -55,7 +51,7 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr return this; } - public MessageBuilder WithRainbowString(string text, byte skip = 1, int offset = 0, double lengthFactor = 255.0, bool useLength = true) { + public MessageBuilder WithRainbowString(string text, byte skip = 1, int offset = 0, double lengthFactor = 255.0, bool useLength = true) => // if (useLength) { // lengthFactor = text.Length; // } @@ -67,8 +63,5 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr // // Console.WriteLine($"RBA: {r} {g} {b} {a}"); // // Content.FormattedBody += $"{text[i]}"; // } - - return this; - } - + this; } \ No newline at end of file -- cgit 1.4.1