From b8a0d04ab7100b12191ceef7db67ee01f879c26f Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Thu, 9 Feb 2023 12:57:27 +0100 Subject: [PATCH] Update UI and stream-related stuff YouTube is still experimental but at least selecting it is easier now --- GTAChaos/Form1.Designer.cs | 81 +++++---- GTAChaos/Form1.cs | 162 +++++++++++++++--- GTAChaos/GTAChaos.csproj | 11 +- GTAChaos/src/utils/Config.cs | 4 +- .../src/utils/{ => stream}/DebugConnection.cs | 0 .../utils/{ => stream}/IStreamConnection.cs | 0 GTAChaos/src/utils/stream/StreamHandler.cs | 30 ++++ .../{ => stream}/TwitchChatConnection.cs | 0 .../{ => stream}/TwitchPollConnection.cs | 0 .../{ => stream}/YouTubeChatConnection.cs | 4 +- 10 files changed, 222 insertions(+), 70 deletions(-) rename GTAChaos/src/utils/{ => stream}/DebugConnection.cs (100%) rename GTAChaos/src/utils/{ => stream}/IStreamConnection.cs (100%) create mode 100644 GTAChaos/src/utils/stream/StreamHandler.cs rename GTAChaos/src/utils/{ => stream}/TwitchChatConnection.cs (100%) rename GTAChaos/src/utils/{ => stream}/TwitchPollConnection.cs (100%) rename GTAChaos/src/utils/{ => stream}/YouTubeChatConnection.cs (99%) diff --git a/GTAChaos/Form1.Designer.cs b/GTAChaos/Form1.Designer.cs index aa5c844..44435da 100644 --- a/GTAChaos/Form1.Designer.cs +++ b/GTAChaos/Form1.Designer.cs @@ -40,9 +40,9 @@ private void InitializeComponent() this.comboBoxMainCooldown = new System.Windows.Forms.ComboBox(); this.listLastEffectsMain = new System.Windows.Forms.ListBox(); this.tabStream = new System.Windows.Forms.TabPage(); - this.label3 = new System.Windows.Forms.Label(); + this.labelStreamClientID = new System.Windows.Forms.Label(); this.textBoxStreamClientID = new System.Windows.Forms.TextBox(); - this.labelTwitchAccessToken = new System.Windows.Forms.Label(); + this.labelStreamAccessToken = new System.Windows.Forms.Label(); this.linkLabelTwitchGetAccessToken = new System.Windows.Forms.LinkLabel(); this.checkBoxStreamCombineVotingMessages = new System.Windows.Forms.CheckBox(); this.checkBoxTwitchUsePolls = new System.Windows.Forms.CheckBox(); @@ -87,6 +87,8 @@ private void InitializeComponent() this.textBoxSyncServer = new System.Windows.Forms.TextBox(); this.buttonSyncConnect = new System.Windows.Forms.Button(); this.tabSettings = new System.Windows.Forms.TabPage(); + this.label5 = new System.Windows.Forms.Label(); + this.comboBoxSettingsStreamMode = new System.Windows.Forms.ComboBox(); this.checkBoxSettingsCheckForUpdatesAtLaunch = new System.Windows.Forms.CheckBox(); this.buttonRestartWebsocket = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); @@ -95,7 +97,6 @@ private void InitializeComponent() this.label8 = new System.Windows.Forms.Label(); this.textBoxSeed = new System.Windows.Forms.TextBox(); this.tabExperimental = new System.Windows.Forms.TabPage(); - this.checkBoxExperimentalYouTubeConnection = new System.Windows.Forms.CheckBox(); this.buttonExperimentalRunEffect = new System.Windows.Forms.Button(); this.textBoxExperimentalEffectName = new System.Windows.Forms.TextBox(); this.checkBoxExperimental_RunEffectOnAutoStart = new System.Windows.Forms.CheckBox(); @@ -232,9 +233,9 @@ private void InitializeComponent() // tabStream // this.tabStream.BackColor = System.Drawing.Color.Transparent; - this.tabStream.Controls.Add(this.label3); + this.tabStream.Controls.Add(this.labelStreamClientID); this.tabStream.Controls.Add(this.textBoxStreamClientID); - this.tabStream.Controls.Add(this.labelTwitchAccessToken); + this.tabStream.Controls.Add(this.labelStreamAccessToken); this.tabStream.Controls.Add(this.linkLabelTwitchGetAccessToken); this.tabStream.Controls.Add(this.checkBoxStreamCombineVotingMessages); this.tabStream.Controls.Add(this.checkBoxTwitchUsePolls); @@ -261,14 +262,14 @@ private void InitializeComponent() this.tabStream.TabIndex = 2; this.tabStream.Text = "Stream"; // - // label3 + // labelStreamClientID // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(37, 11); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(50, 13); - this.label3.TabIndex = 33; - this.label3.Text = "Client ID:"; + this.labelStreamClientID.AutoSize = true; + this.labelStreamClientID.Location = new System.Drawing.Point(8, 10); + this.labelStreamClientID.Name = "labelStreamClientID"; + this.labelStreamClientID.Size = new System.Drawing.Size(50, 13); + this.labelStreamClientID.TabIndex = 33; + this.labelStreamClientID.Text = "Client ID:"; // // textBoxStreamClientID // @@ -279,14 +280,14 @@ private void InitializeComponent() this.textBoxStreamClientID.TabIndex = 32; this.textBoxStreamClientID.TextChanged += new System.EventHandler(this.TextBoxStreamClientID_TextChanged); // - // labelTwitchAccessToken + // labelStreamAccessToken // - this.labelTwitchAccessToken.AutoSize = true; - this.labelTwitchAccessToken.Location = new System.Drawing.Point(8, 35); - this.labelTwitchAccessToken.Name = "labelTwitchAccessToken"; - this.labelTwitchAccessToken.Size = new System.Drawing.Size(79, 13); - this.labelTwitchAccessToken.TabIndex = 31; - this.labelTwitchAccessToken.Text = "Access Token:"; + this.labelStreamAccessToken.AutoSize = true; + this.labelStreamAccessToken.Location = new System.Drawing.Point(8, 35); + this.labelStreamAccessToken.Name = "labelStreamAccessToken"; + this.labelStreamAccessToken.Size = new System.Drawing.Size(79, 13); + this.labelStreamAccessToken.TabIndex = 31; + this.labelStreamAccessToken.Text = "Access Token:"; // // linkLabelTwitchGetAccessToken // @@ -770,6 +771,8 @@ private void InitializeComponent() // tabSettings // this.tabSettings.BackColor = System.Drawing.Color.Transparent; + this.tabSettings.Controls.Add(this.label5); + this.tabSettings.Controls.Add(this.comboBoxSettingsStreamMode); this.tabSettings.Controls.Add(this.checkBoxSettingsCheckForUpdatesAtLaunch); this.tabSettings.Controls.Add(this.buttonRestartWebsocket); this.tabSettings.Controls.Add(this.label4); @@ -784,6 +787,25 @@ private void InitializeComponent() this.tabSettings.TabIndex = 3; this.tabSettings.Text = "Settings"; // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(8, 99); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(73, 13); + this.label5.TabIndex = 26; + this.label5.Text = "Stream Mode:"; + this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // comboBoxSettingsStreamMode + // + this.comboBoxSettingsStreamMode.FormattingEnabled = true; + this.comboBoxSettingsStreamMode.Location = new System.Drawing.Point(87, 96); + this.comboBoxSettingsStreamMode.Name = "comboBoxSettingsStreamMode"; + this.comboBoxSettingsStreamMode.Size = new System.Drawing.Size(121, 21); + this.comboBoxSettingsStreamMode.TabIndex = 25; + this.comboBoxSettingsStreamMode.SelectedIndexChanged += new System.EventHandler(this.comboBoxSettingsStreamMode_SelectedIndexChanged); + // // checkBoxSettingsCheckForUpdatesAtLaunch // this.checkBoxSettingsCheckForUpdatesAtLaunch.AutoSize = true; @@ -878,7 +900,6 @@ private void InitializeComponent() // tabExperimental // this.tabExperimental.BackColor = System.Drawing.Color.Transparent; - this.tabExperimental.Controls.Add(this.checkBoxExperimentalYouTubeConnection); this.tabExperimental.Controls.Add(this.buttonExperimentalRunEffect); this.tabExperimental.Controls.Add(this.textBoxExperimentalEffectName); this.tabExperimental.Controls.Add(this.checkBoxExperimental_RunEffectOnAutoStart); @@ -889,19 +910,6 @@ private void InitializeComponent() this.tabExperimental.TabIndex = 7; this.tabExperimental.Text = "Experimental"; // - // checkBoxExperimentalYouTubeConnection - // - this.checkBoxExperimentalYouTubeConnection.AutoSize = true; - this.checkBoxExperimentalYouTubeConnection.Location = new System.Drawing.Point(6, 29); - this.checkBoxExperimentalYouTubeConnection.Name = "checkBoxExperimentalYouTubeConnection"; - this.checkBoxExperimentalYouTubeConnection.Size = new System.Drawing.Size(127, 17); - this.checkBoxExperimentalYouTubeConnection.TabIndex = 16; - this.checkBoxExperimentalYouTubeConnection.Text = "YouTube Connection"; - this.toolTipHandler.SetToolTip(this.checkBoxExperimentalYouTubeConnection, "When auto-start kicks in\r\nit will enable an effect immediately\r\ninstead of only s" + - "tarting the\r\ntimer.\r\nDoesn\'t work for Twitch mode."); - this.checkBoxExperimentalYouTubeConnection.UseVisualStyleBackColor = true; - this.checkBoxExperimentalYouTubeConnection.CheckedChanged += new System.EventHandler(this.CheckBoxExperimentalYouTubeConnection_CheckedChanged); - // // buttonExperimentalRunEffect // this.buttonExperimentalRunEffect.Location = new System.Drawing.Point(469, 263); @@ -1166,9 +1174,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.NumericUpDown numericUpDownTwitchPollsChannelPointsCost; private System.Windows.Forms.LinkLabel linkLabelTwitchGetAccessToken; - private System.Windows.Forms.Label labelTwitchAccessToken; - private System.Windows.Forms.CheckBox checkBoxExperimentalYouTubeConnection; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label labelStreamAccessToken; + private System.Windows.Forms.Label labelStreamClientID; private System.Windows.Forms.TextBox textBoxStreamClientID; private System.Windows.Forms.Label labelEffectCooldown; private System.Windows.Forms.NumericUpDown numericUpDownEffectCooldown; @@ -1179,6 +1186,8 @@ private void InitializeComponent() private System.Windows.Forms.Button buttonRestartWebsocket; private System.Windows.Forms.ToolStripMenuItem checkForUpdateToolStripMenuItem; private System.Windows.Forms.CheckBox checkBoxSettingsCheckForUpdatesAtLaunch; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.ComboBox comboBoxSettingsStreamMode; } } diff --git a/GTAChaos/Form1.cs b/GTAChaos/Form1.cs index b0f59e3..b0c83ce 100644 --- a/GTAChaos/Form1.cs +++ b/GTAChaos/Form1.cs @@ -1,6 +1,7 @@ // Copyright (c) 2019 Lordmau5 using GTAChaos.Effects; using GTAChaos.Utils; +using GTAChaos.Utils.Stream; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -44,7 +45,7 @@ public Form1() this.experimentalModeEnabled = false; } - this.tabs.TabPages.Remove(this.tabPolls); + this.SetPollsTabVisible(false); this.stopwatch = new Stopwatch(); @@ -59,6 +60,8 @@ public Form1() this.PopulateVotingTimes(); this.PopulateVotingCooldowns(); + this.PopulateStreamModes(); + this.TryLoadConfig(); this.UpdateProgramText(); @@ -227,13 +230,30 @@ private void UpdateInterface() this.checkBoxExperimental_RunEffectOnAutoStart.Checked = Config.Instance().Experimental_RunEffectOnAutoStart; this.textBoxExperimentalEffectName.Text = Config.Instance().Experimental_EffectName; - this.checkBoxExperimentalYouTubeConnection.Checked = Config.Instance().Experimental_YouTubeConnection; this.numericUpDownEffectCooldown.Value = Math.Min(Config.Instance().EffectsCooldownNotActivating, this.numericUpDownEffectCooldown.Maximum); this.numericWebsocketPort.Value = Config.Instance().WebsocketPort; this.textBoxSeed.Text = Config.Instance().Seed; + foreach (StreamModeComboBoxItem item in this.comboBoxSettingsStreamMode.Items) + { + if (item.StreamMode == Config.Instance().StreamMode) + { + this.comboBoxSettingsStreamMode.SelectedItem = item; + found = true; + break; + } + } + + if (!found) + { + this.comboBoxSettingsStreamMode.SelectedIndex = 1; + Config.Instance().StreamMode = StreamHandler.STREAM_MODE.TWITCH; + } + + this.UpdateStreamTab(); + /* * Update selections */ @@ -383,7 +403,7 @@ private void TickStream() bool didFinish; - if (Config.Instance().TwitchUsePolls && this.stream != null && !Config.Instance().Experimental_YouTubeConnection) + if (Config.Instance().TwitchUsePolls && this.stream != null && StreamHandler.IsTwitchMode()) { didFinish = this.stream.GetRemaining() == 0; @@ -741,6 +761,28 @@ private void ComboBoxVotingCooldown_SelectedIndexChanged(object sender, EventArg Config.Instance().StreamVotingCooldown = item.VotingCooldown; } + private class StreamModeComboBoxItem + { + public readonly StreamHandler.STREAM_MODE StreamMode; + public readonly string Text; + + public StreamModeComboBoxItem(string text, StreamHandler.STREAM_MODE streamMode) + { + this.Text = text; + this.StreamMode = streamMode; + } + + public override string ToString() => this.Text; + } + + private void PopulateStreamModes() + { + this.comboBoxSettingsStreamMode.Items.Add(new StreamModeComboBoxItem("Twitch", StreamHandler.STREAM_MODE.TWITCH)); + this.comboBoxSettingsStreamMode.Items.Add(new StreamModeComboBoxItem("YouTube", StreamHandler.STREAM_MODE.YOUTUBE)); + + this.comboBoxSettingsStreamMode.SelectedIndex = 0; + } + private void DoAutostart() { if (!this.checkBoxAutoStart.Checked) @@ -978,18 +1020,24 @@ private async void ButtonConnectStream_Click(object sender, EventArgs e) return; } - // TODO: When in YouTube mode, allow connecting without Client ID. - if (!string.IsNullOrEmpty(Config.Instance().StreamAccessToken) && !string.IsNullOrEmpty(Config.Instance().StreamClientID)) + // If there is something in the Client ID field + if (!string.IsNullOrEmpty(Config.Instance().StreamClientID)) { + // If the mode is Twitch and the Access Token field is empty + if (StreamHandler.IsTwitchMode() && string.IsNullOrEmpty(Config.Instance().StreamAccessToken)) + { + return; + } + this.buttonSwitchMode.Enabled = false; this.buttonConnectStream.Enabled = false; this.textBoxStreamAccessToken.Enabled = false; this.textBoxStreamClientID.Enabled = false; - this.stream = Config.Instance().Experimental_YouTubeConnection - ? new YouTubeChatConnection() - : Config.Instance().TwitchUsePolls ? new TwitchPollConnection() : new TwitchChatConnection(); + this.comboBoxSettingsStreamMode.Enabled = false; + + this.stream = StreamHandler.GetStreamConnection(); this.stream.OnRapidFireEffect += (_sender, rapidFireArgs) => this.Invoke(new Action(() => { @@ -1021,6 +1069,8 @@ private async void ButtonConnectStream_Click(object sender, EventArgs e) this.buttonConnectStream.Enabled = true; this.textBoxStreamAccessToken.Enabled = true; this.textBoxStreamClientID.Enabled = true; + + this.comboBoxSettingsStreamMode.Enabled = true; })); this.stream?.Kill(); this.stream = null; @@ -1037,6 +1087,8 @@ private async void ButtonConnectStream_Click(object sender, EventArgs e) this.textBoxStreamClientID.Enabled = false; this.checkBoxTwitchUsePolls.Enabled = false; + + this.comboBoxSettingsStreamMode.Enabled = false; })); this.stream.OnDisconnected += (_sender, _e) => this.Invoke(new Action(() => @@ -1055,6 +1107,8 @@ private async void ButtonConnectStream_Click(object sender, EventArgs e) this.checkBoxTwitchUsePolls.Enabled = true; + this.comboBoxSettingsStreamMode.Enabled = true; + this.buttonConnectStream.Text = "Connect to Stream"; if (!this.tabs.TabPages.Contains(this.tabEffects)) @@ -1071,8 +1125,19 @@ private async void ButtonConnectStream_Click(object sender, EventArgs e) private void UpdateStreamConnectButtonState() { - this.buttonConnectStream.Enabled = !string.IsNullOrEmpty(Config.Instance().StreamAccessToken) - && !string.IsNullOrEmpty(Config.Instance().StreamClientID); + bool enabled = true; + + if (string.IsNullOrEmpty(Config.Instance().StreamClientID)) + { + enabled = false; + } + + if (string.IsNullOrEmpty(Config.Instance().StreamAccessToken) && StreamHandler.IsTwitchMode()) + { + enabled = false; + } + + this.buttonConnectStream.Enabled = enabled; } private void TextBoxOAuth_TextChanged(object sender, EventArgs e) @@ -1096,8 +1161,6 @@ private void SwitchMode(bool isStreamMode) this.tabs.SelectedIndex = 0; this.tabs.TabPages.Remove(this.tabStream); - this.tabs.TabPages.Remove(this.tabPolls); - this.listLastEffectsMain.Items.Clear(); this.progressBarMain.Value = 0; @@ -1118,11 +1181,6 @@ private void SwitchMode(bool isStreamMode) this.tabs.SelectedIndex = 0; this.tabs.TabPages.Remove(this.tabMain); - if (Config.Instance().TwitchUsePolls && !this.tabs.TabPages.Contains(this.tabPolls)) - { - this.tabs.TabPages.Insert(2, this.tabPolls); - } - this.listLastEffectsStream.Items.Clear(); this.progressBarStream.Value = 0; @@ -1132,6 +1190,8 @@ private void SwitchMode(bool isStreamMode) this.SetEnabled(false); } + this.UpdatePollTabVisibility(); + EffectDatabase.ResetEffectCooldowns(); } @@ -1267,21 +1327,34 @@ private void SanAndreasToolStripMenuItem_Click(object sender, EventArgs e) private void CheckBoxStreamCombineVotingMessages_CheckedChanged(object sender, EventArgs e) => Config.Instance().StreamCombineChatMessages = this.checkBoxStreamCombineVotingMessages.Checked; - private void UpdatePollTabVisibility() + private void SetPollsTabVisible(bool visible) { - if (Config.Instance().TwitchUsePolls) + bool contains = this.tabs.TabPages.Contains(this.tabPolls); + + if (visible && !contains) { - if (!this.tabs.TabPages.Contains(this.tabPolls) && Shared.IsStreamMode) - { - this.tabs.TabPages.Insert(2, this.tabPolls); - } + this.tabs.TabPages.Insert(2, this.tabPolls); } - else + + if (!visible && contains) { this.tabs.TabPages.Remove(this.tabPolls); } } + private void UpdatePollTabVisibility() + { + this.SetPollsTabVisible(false); + + if (Shared.IsStreamMode) + { + if (StreamHandler.IsTwitchMode() && Config.Instance().TwitchUsePolls) + { + this.SetPollsTabVisible(true); + } + } + } + private void CheckBoxTwitchUsePolls_CheckedChanged(object sender, EventArgs e) { Config.Instance().TwitchUsePolls = this.checkBoxTwitchUsePolls.Checked; @@ -1606,8 +1679,6 @@ private void CheckBoxStreamMajorityVotes_CheckedChanged(object sender, EventArgs private void LinkLabelTwitchGetAccessToken_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => System.Diagnostics.Process.Start("https://chaos.lord.moe/"); - private void CheckBoxExperimentalYouTubeConnection_CheckedChanged(object sender, EventArgs e) => Config.Instance().Experimental_YouTubeConnection = this.checkBoxExperimentalYouTubeConnection.Checked; - private void TextBoxStreamClientID_TextChanged(object sender, EventArgs e) { Config.Instance().StreamClientID = this.textBoxStreamClientID.Text; @@ -1632,5 +1703,44 @@ private void buttonRestartWebsocket_Click(object sender, EventArgs e) } private void checkBoxSettingsCheckForUpdatesAtLaunch_CheckedChanged(object sender, EventArgs e) => Config.Instance().CheckForUpdatesAtLaunch = this.checkBoxSettingsCheckForUpdatesAtLaunch.Checked; + + private void comboBoxSettingsStreamMode_SelectedIndexChanged(object sender, EventArgs e) + { + // Stream mode change + StreamModeComboBoxItem item = (StreamModeComboBoxItem)this.comboBoxSettingsStreamMode.SelectedItem; + + Config.Instance().StreamMode = item.StreamMode; + + this.UpdateStreamTab(); + } + + private void UpdateStreamTab() + { + switch (StreamHandler.GetStreamMode()) + { + case StreamHandler.STREAM_MODE.TWITCH: + { + this.labelStreamClientID.Text = "Client ID:"; + this.textBoxStreamClientID.PasswordChar = '*'; + + this.labelStreamAccessToken.Visible = true; + this.textBoxStreamAccessToken.Visible = true; + + this.SetPollsTabVisible(true); + break; + } + case StreamHandler.STREAM_MODE.YOUTUBE: + { + this.labelStreamClientID.Text = "Livestream ID:"; + this.textBoxStreamClientID.PasswordChar = (char)0; + + this.labelStreamAccessToken.Visible = false; + this.textBoxStreamAccessToken.Visible = false; + + this.SetPollsTabVisible(false); + break; + } + } + } } } diff --git a/GTAChaos/GTAChaos.csproj b/GTAChaos/GTAChaos.csproj index c2f3a24..d3bb808 100644 --- a/GTAChaos/GTAChaos.csproj +++ b/GTAChaos/GTAChaos.csproj @@ -361,18 +361,19 @@ - + + - - - + + + - + Form1.cs diff --git a/GTAChaos/src/utils/Config.cs b/GTAChaos/src/utils/Config.cs index d488731..b190d0f 100644 --- a/GTAChaos/src/utils/Config.cs +++ b/GTAChaos/src/utils/Config.cs @@ -1,5 +1,6 @@ // Copyright (c) 2019 Lordmau5 using GTAChaos.Effects; +using GTAChaos.Utils.Stream; using System; using System.Collections.Generic; @@ -21,6 +22,8 @@ public class Config public Dictionary EnabledEffects = new(); public int EffectsCooldownNotActivating = -1; + public StreamHandler.STREAM_MODE StreamMode = StreamHandler.STREAM_MODE.TWITCH; + // Twitch Polls public bool TwitchUsePolls; @@ -55,7 +58,6 @@ public class Config // Experimental public bool Experimental_RunEffectOnAutoStart; public string Experimental_EffectName; - public bool Experimental_YouTubeConnection; public static Config Instance() { diff --git a/GTAChaos/src/utils/DebugConnection.cs b/GTAChaos/src/utils/stream/DebugConnection.cs similarity index 100% rename from GTAChaos/src/utils/DebugConnection.cs rename to GTAChaos/src/utils/stream/DebugConnection.cs diff --git a/GTAChaos/src/utils/IStreamConnection.cs b/GTAChaos/src/utils/stream/IStreamConnection.cs similarity index 100% rename from GTAChaos/src/utils/IStreamConnection.cs rename to GTAChaos/src/utils/stream/IStreamConnection.cs diff --git a/GTAChaos/src/utils/stream/StreamHandler.cs b/GTAChaos/src/utils/stream/StreamHandler.cs new file mode 100644 index 0000000..6cc1fc6 --- /dev/null +++ b/GTAChaos/src/utils/stream/StreamHandler.cs @@ -0,0 +1,30 @@ +namespace GTAChaos.Utils.Stream +{ + public class StreamHandler + { + public enum STREAM_MODE + { + TWITCH, + YOUTUBE + }; + + public static IStreamConnection GetStreamConnection() + { + switch (Config.Instance().StreamMode) + { + case STREAM_MODE.TWITCH: + { + return Config.Instance().TwitchUsePolls ? new TwitchPollConnection() : new TwitchChatConnection(); + } + case STREAM_MODE.YOUTUBE: return new YouTubeChatConnection(); + default: return new DebugConnection(); + } + } + + public static STREAM_MODE GetStreamMode() => Config.Instance().StreamMode; + + public static bool IsTwitchMode() => GetStreamMode() == STREAM_MODE.TWITCH; + + public static bool IsYouTubeMode() => GetStreamMode() == STREAM_MODE.YOUTUBE; + } +} diff --git a/GTAChaos/src/utils/TwitchChatConnection.cs b/GTAChaos/src/utils/stream/TwitchChatConnection.cs similarity index 100% rename from GTAChaos/src/utils/TwitchChatConnection.cs rename to GTAChaos/src/utils/stream/TwitchChatConnection.cs diff --git a/GTAChaos/src/utils/TwitchPollConnection.cs b/GTAChaos/src/utils/stream/TwitchPollConnection.cs similarity index 100% rename from GTAChaos/src/utils/TwitchPollConnection.cs rename to GTAChaos/src/utils/stream/TwitchPollConnection.cs diff --git a/GTAChaos/src/utils/YouTubeChatConnection.cs b/GTAChaos/src/utils/stream/YouTubeChatConnection.cs similarity index 99% rename from GTAChaos/src/utils/YouTubeChatConnection.cs rename to GTAChaos/src/utils/stream/YouTubeChatConnection.cs index 3cdadb4..a78124a 100644 --- a/GTAChaos/src/utils/YouTubeChatConnection.cs +++ b/GTAChaos/src/utils/stream/YouTubeChatConnection.cs @@ -262,7 +262,7 @@ private List ParseChatMessages(JToken actions) private void OnChatMessage(ChatItem chatItem) { - string username = this.RemoveSpecialCharacters(chatItem.Author); + string username = chatItem.Author; string message = this.RemoveSpecialCharacters(chatItem.Message, true); if (this.VotingMode == Shared.VOTING_MODE.RAPID_FIRE) @@ -280,7 +280,7 @@ private void OnChatMessage(ChatItem chatItem) this.RapidFireEffect(new RapidFireEventArgs() { - Effect = effect.SetSubtext(username) + Effect = effect.SetSubtext(this.RemoveSpecialCharacters(chatItem.Author)) }); this.rapidFireVoters.Add(username);