From a1e5d9f5331ec095a8a0a842e35aadc1cb5fb1fe Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 20 Mar 2024 04:26:54 -0500 Subject: [PATCH] Added roomstate message type --- TwitchIrcClient/IRC/Messages/Roomstate.cs | 96 +++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 TwitchIrcClient/IRC/Messages/Roomstate.cs diff --git a/TwitchIrcClient/IRC/Messages/Roomstate.cs b/TwitchIrcClient/IRC/Messages/Roomstate.cs new file mode 100644 index 0000000..e462932 --- /dev/null +++ b/TwitchIrcClient/IRC/Messages/Roomstate.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using TwitchLogger.IRC; +using TwitchLogger.IRC.Messages; + +namespace TwitchIrcClient.IRC.Messages +{ + public class Roomstate : ReceivedMessage + { + /// + /// A Boolean value that determines whether the chat room allows only messages with emotes. + /// + public bool EmoteOnly + { get + { + var value = TryGetTag("emote-only"); + if (value == "1") + return true; + if (value == "0") + return false; + throw new InvalidDataException($"tag \"emote-only\" does not have a proper value: {value}"); + } + } + /// + /// An integer value that determines whether only followers can post messages in the chat room. + /// The value indicates how long, in minutes, the user must have followed the broadcaster before + /// posting chat messages. If the value is -1, the chat room is not restricted to followers only. + /// + public int FollowersOnly + { get + { + var value = TryGetTag("followers-only"); + if (!int.TryParse(value, out int result)) + throw new InvalidDataException(); + return result; + } + } + /// + /// A Boolean value that determines whether a user’s messages must be unique. + /// Applies only to messages with more than 9 characters. + /// + public bool UniqueMode + { get + { + var value = TryGetTag("r9k"); + if (value == "1") + return true; + if (value == "0") + return false; + throw new InvalidDataException($"tag \"r9k\" does not have a proper value: {value}"); + } + } + /// + /// An ID that identifies the chat room (channel). + /// + public string RoomId => TryGetTag("room-id"); + /// + /// An integer value that determines how long, in seconds, users must wait between sending messages. + /// + public int Slow + { get + { + string value = TryGetTag("slow"); + if (!int.TryParse(value, out int result)) + throw new InvalidDataException($"tag \"slow\" does not have a proper value: {value}"); + return result; + } + } + /// + /// A Boolean value that determines whether only subscribers and moderators can chat in the chat room. + /// + public bool SubsOnly + { get + { + var value = TryGetTag("subs-only"); + if (value == "1") + return true; + if (value == "0") + return false; + throw new InvalidDataException($"tag \"subs-only\" does not have a proper value: {value}"); + } + } + public Roomstate(ReceivedMessage other) : base(other) + { + Debug.Assert(MessageType == IrcMessageType.ROOMSTATE, + $"{nameof(Roomstate)} must have type {IrcMessageType.ROOMSTATE}" + + $" but has {MessageType}"); + } + } +}