Example #1
0
        private void parseCommand(string line)
        {
            if (line != "")
            {
                if (ContainsCommand(line, synthCmd))
                {
                    if (qss != null)
                    {
                        var    parts  = getParts(line, synthCmd);
                        string prompt = parts[1];
                        string player = getPlayer(parts[0]);

                        string[] blocked_words   = File.ReadAllLines("blocked_words.txt");
                        string[] replace         = File.ReadAllLines("replace.txt");
                        string[] regex_filter    = File.ReadAllLines("regex_filter.txt");
                        string   lowercasePrompt = prompt.ToLower();
                        bool     blockedWord     = false;
                        bool     regexIsMatch    = false;

                        if (HasRights(MainWindow.whitelistedOnlyTTS, player))
                        {
                            for (int i = 0; i <= blocked_words.Length - 1; i++)
                            {
                                string lowercaseBlocked_word = blocked_words[i].ToLower();

                                if (lowercasePrompt.Contains(lowercaseBlocked_word))
                                {
                                    blockedWord = true;
                                }
                            }

                            for (int i = 0; i <= replace.Length - 1; i++)
                            {
                                string[] replaceThing = replace[i].Split('=');

                                if (replaceThing.Length == 2)
                                {
                                    string replaceTrigger = replaceThing[0];
                                    string replaceWith    = replaceThing[1];

                                    if (prompt.Contains(replaceTrigger))
                                    {
                                        prompt = prompt.Replace(replaceTrigger, replaceWith);
                                    }
                                }
                            }

                            for (int i = 0; i <= regex_filter.Length - 1; i++)
                            {
                                try
                                {
                                    if (Regex.IsMatch(prompt, regex_filter[i]))
                                    {
                                        regexIsMatch = true;
                                    }
                                }
                                catch (ArgumentException e)
                                {
                                    MessageBox.Show("regex_filter caused an error:\n" + e.Message);
                                }
                            }

                            if (blockedWord == false)
                            {
                                if (MainWindow.invertRegexFilter == true)
                                {
                                    if (regexIsMatch == true)
                                    {
                                        qss.AddToQueue(new QSSQueueItem(prompt, player));
                                    }
                                }
                                else
                                {
                                    if (regexIsMatch == false)
                                    {
                                        qss.AddToQueue(new QSSQueueItem(prompt, player));
                                    }
                                }
                            }
                        }
                    }
                }
                else if (ContainsCommand(line, playCmd))
                {
                    var    parts  = getParts(line, playCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyPlayCmd, player))
                    {
                        TryParsePlay(line);
                    }
                }
                else if (ContainsCommand(line, playVideoCmd))
                {
                    var    parts  = getParts(line, playVideoCmd);
                    string prompt = parts[1];
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyPlayVideoCmd, player))
                    {
                        ape.PlayVideo(prompt, player);
                    }
                }
                else if (ContainsCommand(line, pauseCmd))
                {
                    var    parts  = getParts(line, pauseCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyPauseCmd, player))
                    {
                        ape.TogglePause();
                    }
                }
                else if (ContainsCommand(line, resumeCmd))
                {
                    var    parts  = getParts(line, resumeCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyResumeCmd, player))
                    {
                        ape.Resume();
                    }
                }
                else if (ContainsCommand(line, stopCmd))
                {
                    var    parts  = getParts(line, stopCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyStopCmd, player))
                    {
                        ape.Stop();
                    }
                }
                else if (ContainsCommand(line, skipCurrentCmd))
                {
                    var    parts  = getParts(line, skipCurrentCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlySkipCurrentCmd, player))
                    {
                        ape.SkipCurrent();
                    }
                }
                else if (ContainsCommand(line, clearQueueCmd))
                {
                    var    parts  = getParts(line, clearQueueCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyClearQueueCmd, player))
                    {
                        ape.ClearQueue();
                    }
                }
                else if (ContainsCommand(line, ttsSkipCurrentCmd))
                {
                    var    parts  = getParts(line, ttsSkipCurrentCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyTTSSkipCurrentCmd, player))
                    {
                        qss.SkipCurrent();
                    }
                }
                else if (ContainsCommand(line, ttsClearQueueCmd))
                {
                    var    parts  = getParts(line, ttsClearQueueCmd);
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyTTSClearQueueCmd, player))
                    {
                        qss.Clear();
                    }
                }
                else if (ContainsCommand(line, blockUserCmd))
                {
                    var    parts  = getParts(line, blockUserCmd);
                    string prompt = parts[1];
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyBlockUserCmd, player))
                    {
                        string blocked_users = File.ReadAllText("blocked_users.txt");

                        var    encodingForFile = GetEncoding("blocked_users.txt");
                        string lastline        = string.Empty;

                        string[] Lines = blocked_users.Split('\n');

                        if (Lines.Length == 0)
                        {
                            lastline = string.Empty;
                        }
                        else if (Lines.Length >= 1)
                        {
                            lastline = Lines[Lines.Length - 1];
                        }

                        if (lastline.Length == 0)
                        {
                            using (StreamWriter sw = new StreamWriter(File.Open("blocked_users.txt", FileMode.Append), encodingForFile))
                            {
                                sw.WriteLine(prompt);
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = new StreamWriter(File.Open("blocked_users.txt", FileMode.Append), encodingForFile))
                            {
                                sw.WriteLine();
                                sw.WriteLine(prompt);
                            }
                        }
                    }
                }
                else if (ContainsCommand(line, blockWordCmd))
                {
                    var    parts  = getParts(line, blockWordCmd);
                    string prompt = parts[1];
                    string player = getPlayer(parts[0]);

                    if (HasRights(MainWindow.whitelistedOnlyBlockWordCmd, player))
                    {
                        string blocked_words = File.ReadAllText("blocked_words.txt");

                        var    encodingForFile = GetEncoding("blocked_words.txt");
                        string lastline        = string.Empty;

                        string[] Lines = blocked_words.Split('\n');

                        if (Lines.Length == 0)
                        {
                            lastline = string.Empty;
                        }
                        else if (Lines.Length >= 1)
                        {
                            lastline = Lines[Lines.Length - 1];
                        }

                        if (lastline.Length == 0)
                        {
                            using (StreamWriter sw = new StreamWriter(File.Open("blocked_words.txt", FileMode.Append), encodingForFile))
                            {
                                sw.WriteLine(prompt);
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = new StreamWriter(File.Open("blocked_words.txt", FileMode.Append), encodingForFile))
                            {
                                sw.WriteLine();
                                sw.WriteLine(prompt);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private void AudioQueue_Pause_Click(object sender, RoutedEventArgs e)
 {
     ape.TogglePause();
 }