Пример #1
0
        private void Client_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e)
        {
            string message = e.ChatMessage.Message.ToLower();

            if (message.Length == 0 || message[0] != '!')
            {
                return;
            }
            if (e.ChatMessage.Message.ToLower() == "!commentators" || e.ChatMessage.Message.ToLower() == "!commentary")
            {
                if (Comm1Name.Text != "")
                {
                    string response = "Commentator 1: " + Comm1Name.Text;
                    if (Comm1Twitter.Text != "")
                    {
                        message += " Twitter: https://twitter.com/" + Comm1Twitter.Text.Replace("@", "");
                    }
                    client.SendMessage(client.JoinedChannels[0], response);
                }
                if (Comm2Name.Text != "")
                {
                    string response = "Commentator 2: " + Comm2Name.Text;
                    if (Comm2Twitter.Text != "")
                    {
                        message += " Twitter: https://twitter.com/" + Comm2Twitter.Text.Replace("@", "");
                    }
                    client.SendMessage(client.JoinedChannels[0], response);
                }
            }
            // if (!e.ChatMessage.IsModerator && !e.ChatMessage.IsBroadcaster) { return; }
            List <string> messageWords = e.ChatMessage.Message.Replace("!", "").Split(' ').ToList();

            if (messageWords[0] == "scene")
            {
                if (!obs)
                {
                    return;
                }
                var    scenes    = _obs.ListScenes();
                string sceneName = messageWords[1];
                foreach (var s in scenes)
                {
                    if (s.Name.ToLower() == sceneName)
                    {
                        _obs.SetCurrentScene(s.Name);
                        return;
                    }
                }
                client.SendMessage(client.JoinedChannels[0], "Could not find scene");
                return;
            }
            if (message == "!scoreboard")
            {
                List <string> controlNames = new List <string>();
                controls.Where(c => c is TextBox || c is NumericUpDown || c is ComboBox).ToList().ForEach(c => controlNames.Add(c.Name));
                client.SendWhisper(e.ChatMessage.Username, "To operate the scoreboard, type the name of a field (not case sensitive) followed by the value. Here is a list of fields: " + string.Join(", ", controlNames) + ". Other commands include !scoreboard and !reset");
                return;
            }
            else if (message.equalsIgnoreCase("!reset"))
            {
                resetButton.Invoke((MethodInvoker)(() => resetButton.PerformClick()));
                return;
            }
            message = message.Replace("!", "");

            if (messageWords.Count >= 2)
            {
                string controlName = messageWords[0];

                Console.WriteLine(controlName);

                Control control = controls.Find(c => c.Name.ToLower() == controlName.ToLower());
                if (control != null)
                {
                    int messageValue;
                    int.TryParse(messageWords[1], out messageValue);
                    if (messageValue != null && control is NumericUpDown)
                    {
                        NumericUpDown c = control as NumericUpDown;
                        c.Invoke((MethodInvoker)(() => c.Value = messageValue));
                        SendUpdateButton.Invoke((MethodInvoker)(() => SendUpdateButton.PerformClick()));
                        return;
                    }
                    control.Invoke((MethodInvoker)(() => control.Text = string.Join(" ", messageWords.GetRange(1, messageWords.Count - 1))));
                    SendUpdateButton.Invoke((MethodInvoker)(() => SendUpdateButton.PerformClick()));
                }
            }
        }
Пример #2
0
        private void Client_OnWhisperReceived(object sender, TwitchLib.Client.Events.OnWhisperReceivedArgs e)
        {
            string message = e.WhisperMessage.Message.ToLower();

            if (message.Length == 0 || message[0] != '!')
            {
                return;
            }
            if (e.WhisperMessage.Message.ToLower() == "!commentators")
            {
                if (Comm1Name.Text != "")
                {
                    string response = "Commentator 1: " + Comm1Name.Text;
                    if (Comm1Twitter.Text != "")
                    {
                        message += " Twitter: https://twitter.com/" + Comm1Twitter.Text.Replace("@", "");
                    }
                    client.SendMessage(client.JoinedChannels[0], response);
                }
                if (Comm2Name.Text != "")
                {
                    string response = "Commentator 2: " + Comm2Name.Text;
                    if (Comm2Twitter.Text != "")
                    {
                        message += " Twitter: https://twitter.com/" + Comm2Twitter.Text.Replace("@", "");
                    }
                    client.SendMessage(client.JoinedChannels[0], response);
                }
            }
            if (message == "!scoreboard" || message == "!help")
            {
                List <string> controlNames = new List <string>();
                controls.Where(c => c is TextBox || c is NumericUpDown || c is ComboBox).ToList().ForEach(c => controlNames.Add(c.Name));
                client.SendMessage(client.JoinedChannels[0], "To operate the scoreboard, type the name of a field (not case sensitive) followed by the value. Here is a list of useful fields: Player1Name, Player2Name, Player1Score, Player2Score, round. For a full list of fields type !fields. Other commands include !scoreboard and !reset");
                return;
            }
            else if (message == "!fields")
            {
            }
            else if (message.equalsIgnoreCase("!reset"))
            {
                resetButton.Invoke((MethodInvoker)(() => resetButton.PerformClick()));
                return;
            }
            message = message.Replace("!", "");
            List <string> messageWords = e.WhisperMessage.Message.Replace("!", "").Split(' ').ToList();

            if (messageWords.Count >= 2)
            {
                string controlName = messageWords[0];

                Console.WriteLine(controlName);

                Control control = controls.Find(c => c.Name.ToLower() == controlName.ToLower());
                if (control != null)
                {
                    int messageValue;
                    int.TryParse(messageWords[1], out messageValue);
                    if (messageValue != null && control is NumericUpDown)
                    {
                        NumericUpDown c = control as NumericUpDown;
                        c.Invoke((MethodInvoker)(() => c.Value = messageValue));
                        SendUpdateButton.Invoke((MethodInvoker)(() => SendUpdateButton.PerformClick()));
                        return;
                    }
                    control.Invoke((MethodInvoker)(() => control.Text = string.Join(" ", messageWords.GetRange(1, messageWords.Count - 1))));
                    SendUpdateButton.Invoke((MethodInvoker)(() => SendUpdateButton.PerformClick()));
                }
            }
        }