From 8dadf547033d71480fd7756809992c0f32549f59 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Thu, 11 Jan 2024 07:31:09 +0100 Subject: Cleanup, more message formatters, messagebuilder start --- LibMatrix/Helpers/MessageBuilder.cs | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 LibMatrix/Helpers/MessageBuilder.cs (limited to 'LibMatrix/Helpers/MessageBuilder.cs') diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs new file mode 100644 index 0000000..7715462 --- /dev/null +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -0,0 +1,40 @@ +using ArcaneLibs; +using LibMatrix.EventTypes.Spec; + +namespace LibMatrix.Helpers; + +public class MessageBuilder(string msgType = "m.text", string format = "org.matrix.custom.html") { + private RoomMessageEventContent Content { get; set; } = new() { + MessageType = msgType, + Format = format + }; + + public RoomMessageEventContent Build() => Content; + + 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); + Content.FormattedBody += ""; + return this; + } + + public MessageBuilder WithRainbowString(string text, byte skip = 1, int offset = 0, double lengthFactor = 255.0, bool useLength = true) { + if (useLength) { + lengthFactor = text.Length; + } + RainbowEnumerator enumerator = new(skip, offset, lengthFactor); + for (int i = 0; i < text.Length; i++) { + var (r, g, b) = enumerator.Next(); + Content.FormattedBody += $"{text[i]}"; + } + + return this; + } + +} \ No newline at end of file -- cgit 1.5.1