Example #1
0
        void Bot_onChannelMessage(object sender, ChannelMessageEventArgs e)
        {
            UInt32 ChannelID = e.ChannelID;
            bool correctAnswer;

            if (ChannelID == _channelid && _inprogress)
            {
                if (bool.Parse(_autocorrect))
                {
                    if (Levenshtein.Compute(e.Message.ToLower(), _answer.ToLower()) <= 2)
                    {
                        correctAnswer = true;
                    }
                    else
                    {
                        correctAnswer = false;
                    }
                }
                else
                {
                    if (e.Message.ToLower() == _answer.ToLower())
                    {
                        correctAnswer = true;
                    }
                    else
                    {
                        correctAnswer = false;
                    }
                }

                if (correctAnswer)
                {
                    if (_scores.ContainsKey(e.Username))
                    {
                        _scores[e.Username]++;
                    }
                    else
                    {
                        _scores.Add(e.Username, 1);
                    }

                    Bot.SendChannelMessage(ChannelID, "{1}" + e.Username + " {0}got the correct answer of {1}" + _answer + "{0}!");

                    Bot.onChannelMessage -= Bot_onChannelMessage;
                    Pause();
                    while (tmrPause.Enabled) { };
                    Bot.onChannelMessage += Bot_onChannelMessage;

                    if (_questionnumber != _questioncount)
                    {
                        GetQuestion();
                        Bot.SendChannelMessage(ChannelID, "{0}Question #" + _questionnumber + " of " + _questioncount + ": [{1}" + _categorykey + "{0}] {1}" + _question);
                        tmrHint.Stop();
                        tmrHint.Start();
                    }
                    else
                    {
                        string temp = "";
                        _inprogress = false;
                        tmrHint.Stop();

                        List<KeyValuePair<string, int>> sortedScores = new List<KeyValuePair<string, int>>(_scores);
                        sortedScores.Sort((firstPair, nextPair) =>
                        {
                            return firstPair.Value.CompareTo(nextPair.Value);
                        });

                        if (sortedScores.Count == 1)
                        {
                            temp += "{1}" + sortedScores[0].Key + "{0}" + "(^w" + sortedScores[0].Value + "{0})" + " ";
                        }
                        else if (sortedScores.Count == 2)
                        {
                            temp += "{1}" + sortedScores[1].Key + "{0}" + "(^w" + sortedScores[1].Value + "{0})" + " ";
                            temp += "{1}" + sortedScores[0].Key + "{0}" + "(^w" + sortedScores[0].Value + "{0})" + " ";
                        }
                        else
                        {
                            for (int count = sortedScores.Count; count >= sortedScores.Count - 2; count--)
                            {
                                temp += "{1}" + sortedScores[count - 1].Key + "{0}" + "(^w" + sortedScores[count - 1].Value + "{0})" + " ";
                            }
                        }

                        Bot.SendChannelMessage(ChannelID, "{0}SCORE: " + temp);
                    }
                }
            }
        }
Example #2
0
 void Core_onChannelMessage(object sender, ChannelMessageEventArgs e)
 {
     for (int count = 0; count <= 8; count++)
     {
         if (ChannelID[count] == e.ChannelID)
         {
             this.Invoke(new EventHandler(
                 delegate
                 {
                     txtChat[count].AppendText(Environment.NewLine);
                     txtChat[count].AppendText("^770[" + DateTime.Now.ToShortTimeString() + "] ^880" + e.Username + ": ^999" + e.Message);
                 }));
         }
     }
 }