private void ButtonConnectTwitch_Click(object sender, EventArgs e) { if (Twitch != null && Twitch.Client.IsConnected) { Twitch.Kill(); Twitch = null; checkBoxTwitchDontActivateEffects.Enabled = true; checkBoxTwitchDontActivateEffects.Checked = false; checkBoxTwitchAllowVoting.Enabled = true; checkBoxTwitchIsHost.Enabled = true; checkBoxTwitchIsHost.Checked = false; comboBoxVotingTime.Enabled = true; comboBoxVotingCooldown.Enabled = true; textBoxTwitchChannel.Enabled = true; textBoxTwitchUsername.Enabled = Config.Instance.TwitchIsHost; textBoxTwitchOAuth.Enabled = Config.Instance.TwitchIsHost; buttonConnectTwitch.Text = "Connect to Twitch"; Config.Instance.TwitchDontActivateEffects = false; if (!tabSettings.TabPages.Contains(tabEffects)) { tabSettings.TabPages.Insert(tabSettings.TabPages.IndexOf(tabTwitch), tabEffects); } return; } if (textBoxTwitchChannel.Text != "") { buttonConnectTwitch.Enabled = false; Twitch = new TwitchConnection(textBoxTwitchChannel.Text, textBoxTwitchUsername.Text, textBoxTwitchOAuth.Text); Twitch.OnVotingModeChange += (_sender, votingArgs) => { Invoke(new Action(() => SwitchTwitchListenerMode(votingArgs.IsVoting, votingArgs.Duration))); }; Twitch.OnEffectActivated += (_sender, effectArgs) => { Invoke(new Action(() => AddEffectToListBox(EffectDatabase.RunEffect(effectArgs.Id, false)))); }; Twitch.Client.OnIncorrectLogin += (_sender, _e) => { MessageBox.Show("There was an error trying to log in to the account. Wrong username / OAuth token?", "Twitch Login Error"); Invoke(new Action(() => { buttonConnectTwitch.Enabled = true; })); Twitch.Kill(); }; Twitch.Client.OnConnected += (_sender, _e) => { MessageBox.Show("Successfully connected to Twitch!", "Twitch Login Succeeded"); Invoke(new Action(() => { buttonConnectTwitch.Enabled = true; buttonTwitchToggle.Enabled = Config.Instance.TwitchIsHost; checkBoxTwitchIsHost.Enabled = false; buttonConnectTwitch.Text = "Disconnect"; textBoxTwitchChannel.Enabled = false; textBoxTwitchUsername.Enabled = false; textBoxTwitchOAuth.Enabled = false; if (!Config.Instance.TwitchIsHost) { checkBoxTwitchDontActivateEffects.Enabled = false; checkBoxTwitchDontActivateEffects.Checked = false; checkBoxTwitchIsHost.Checked = false; comboBoxVotingTime.Enabled = false; comboBoxVotingCooldown.Enabled = false; checkBoxTwitchAllowVoting.Enabled = false; Config.Instance.TwitchDontActivateEffects = false; tabSettings.TabPages.Remove(tabEffects); } })); }; } }
private void ButtonConnectTwitch_Click(object sender, EventArgs e) { if (twitch != null && twitch.Client.IsConnected) { twitch?.Kill(); twitch = null; comboBoxVotingTime.Enabled = true; comboBoxVotingCooldown.Enabled = true; textBoxTwitchChannel.Enabled = true; textBoxTwitchUsername.Enabled = true; textBoxTwitchOAuth.Enabled = true; buttonConnectTwitch.Text = "Connect to Twitch"; if (!tabSettings.TabPages.Contains(tabEffects)) { tabSettings.TabPages.Insert(tabSettings.TabPages.IndexOf(tabTwitch), tabEffects); } return; } if (Config.Instance().TwitchChannel != "" && Config.Instance().TwitchUsername != "" && Config.Instance().TwitchOAuthToken != "") { buttonConnectTwitch.Enabled = false; twitch = new TwitchConnection(); twitch.OnRapidFireEffect += (_sender, rapidFireArgs) => { Invoke(new Action(() => { if (Config.Instance().TwitchVotingMode == 2) { rapidFireArgs.Effect.RunEffect(); AddEffectToListBox(rapidFireArgs.Effect); } })); }; twitch.Client.OnIncorrectLogin += (_sender, _e) => { MessageBox.Show("There was an error trying to log in to the account. Wrong username / OAuth token?", "Twitch Login Error"); Invoke(new Action(() => { buttonConnectTwitch.Enabled = true; })); twitch.Kill(); }; twitch.Client.OnConnected += (_sender, _e) => { Invoke(new Action(() => { buttonConnectTwitch.Enabled = true; buttonTwitchToggle.Enabled = true; buttonAutoStart.Enabled = true; buttonConnectTwitch.Text = "Disconnect"; textBoxTwitchChannel.Enabled = false; textBoxTwitchUsername.Enabled = false; textBoxTwitchOAuth.Enabled = false; })); }; } }