Beispiel #1
0
        void ICommand.Process(MessageInfo message)
        {
            Match match = regUser.Match(message.Content);

            if (match.Success)
            {
                if ((!string.IsNullOrWhiteSpace(match.Groups["user"].Value)))
                {
                    //query note by username
                    GetNote(match.Groups["user"].Value);

                    return;
                }
            }

            match = regNote.Match(message.Content);

            if (match.Success)
            {
                if (!string.IsNullOrWhiteSpace(match.Groups["note"].Value))
                {
                    //update user bnet info
                    string bnet = match.Groups["note"].Value;

                    repo.AddUpdateNote(message.Username, bnet);

                    tw.RespondMessage(string.Format("Updated note for {0}.", message.Username));
                }
                else
                {
                    //query note by current user
                    GetNote(message.Username);
                }
            }
        }
Beispiel #2
0
        void ICommand.Process(MessageInfo message)
        {
            //get data
            var stream = api.Stream(message.Channel);

            if (stream != null && stream.stream != null)
            {
                string streamID = stream.stream._id;

                int uniqueViewers = repo.GetUniqueViewerCount(message.Channel.Trim(), streamID);

                if (uniqueViewers > 0)
                {
                    tw.RespondMessage(string.Format("{0} is playing {1} and currently has {2} viewers", message.Channel, stream.stream.game, stream.stream.viewers));
                    tw.RespondMessage(string.Format("There have been {0} unique viewers since the beginning of {1}'s stream", uniqueViewers, message.Channel));
                }
            }
        }
Beispiel #3
0
        public void Process(MessageInfo message)
        {
            Match match = regHowLong.Match(message.Content);

            if (match.Success)
            {
                if (!string.IsNullOrWhiteSpace(match.Groups["user"].Value))
                {
                    if (match.Groups["user"].Value.ToLowerInvariant() == "roflgator")
                    {
                        tw.RespondMessage("6 inches of salt");
                    }
                    else
                    {
                        RespondFollowMesssage(match.Groups["user"].Value, message.Channel);
                    }
                }
                else
                {
                    RespondFollowMesssage(message.Username, message.Channel);
                }
            }
        }
Beispiel #4
0
        void IKeyword.Process(MessageInfo message)
        {
            //get template
            string template = string.Empty;
            Match  match    = regQuestion.Match(message.Content);

            if (match.Success &&
                !string.IsNullOrWhiteSpace(match.Groups["user"].Value) && match.Groups["user"].Value.ToLowerInvariant() == Config.Nickname &&
                !string.IsNullOrWhiteSpace(match.Groups["prefix"].Value))
            {
                string subject = match.Groups["user"].Value;
                string answer  = string.Empty;

                switch (match.Groups["prefix"].Value.ToLowerInvariant())
                {
                case "who":
                case "which":
                    answer = Who(message);
                    break;

                case "where":
                case "how":
                    answer = What();
                    break;

                case "when":
                    answer = "Soon.";
                    break;

                case "what":
                    answer = What();
                    break;

                case "why":
                    answer = What() + " and why not?";
                    break;

                default:
                    answer = Can();
                    break;
                }

                if (!string.IsNullOrEmpty(answer))
                {
                    tw.RespondMessage(answer);
                }
            }
        }
Beispiel #5
0
        void ICommand.Process(MessageInfo message)
        {
            //get template
            string template = string.Empty;
            Match  match    = regDefine.Match(message.Content);

            if (match.Success && !string.IsNullOrWhiteSpace(match.Groups["word"].Value))
            {
                //get data
                var definition = repo.GetDefinition(match.Groups["word"].Value);

                if (definition != null)
                {
                    tw.RespondMessage(string.Format("{0} ({1}): {2}", definition.Word, definition.PartOfSpeech.ToLowerInvariant(), definition.Definition));
                }
            }
        }
Beispiel #6
0
        void ICommand.Process(MessageInfo message)
        {
            //get data
            var data = repo.GetBlasphemy();

            var chatters = api.Chatters(message.Channel);

            if (data != null)
            {
                string response = data.Text;

                response = Regex.Replace(response, "god", message.Channel, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

                if (data.Names.Count() > 0)
                {
                    foreach (string word in data.Names)
                    {
                        if (chatters != null)
                        {
                            string randomViewer = RandomViewer(chatters);

                            response = Regex.Replace(response, word, randomViewer, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                        }
                    }
                }
                else
                {
                    Regex names = new Regex("\\b[A-Z][a-z]+\\b");
                    foreach (Match match in names.Matches(response))
                    {
                        if (chatters != null)
                        {
                            string randomViewer = RandomViewer(chatters);

                            response = Regex.Replace(response, match.Value, randomViewer, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                        }
                    }
                }

                tw.RespondMessage(response);
            }
        }
Beispiel #7
0
        void ICommand.Process(MessageInfo message)
        {
            //get template
            string template = string.Empty;
            Match  match    = regMadlib.Match(message.Content);

            if (match.Success)
            {
                if (!string.IsNullOrWhiteSpace(match.Groups["template"].Value))
                {
                    if (match.Groups["template"].Value.Contains(' '))
                    {
                        template = match.Groups["template"].Value;
                    }
                    else
                    {
                        //assume user
                        template = string.Format("{0} can you please not adverb verb a adjective noun?", match.Groups["template"].Value);
                    }
                }
                else
                {
                    template = string.Format("I want {0} to verb my noun.", message.Username);
                }
            }

            //get data
            var randomWords = repo.GetRandomWords();

            if (randomWords != null)
            {
                string response = template
                                  .Replace("adverb", randomWords.Adverb)
                                  .Replace("verb", randomWords.Verb)
                                  .Replace("adjective", randomWords.Adjective)
                                  .Replace("noun", randomWords.Noun);

                tw.RespondMessage(response);
            }
        }
Beispiel #8
0
        void ICommand.Process(MessageInfo message)
        {
            //get template
            char[] template = null;
            Match  match    = regFullWidth.Match(message.Content);

            if (match.Success)
            {
                if (!string.IsNullOrWhiteSpace(match.Groups["template"].Value))
                {
                    byte[] fromBytes = Encoding.UTF8.GetBytes(match.Groups["template"].Value);
                    byte[] toBytes   = UnicodeEncoding.Convert(Encoding.UTF8, Encoding.Unicode, fromBytes);

                    template = UnicodeEncoding.Unicode.GetChars(toBytes);

                    for (int i = 0; i < template.Length; i++)
                    {
                        if (template[i] >= 'a' && template[i] <= 'z')
                        {
                            template[i] = map[(int)template[i] - 97 + 1];
                        }
                        else if (template[i] >= 'A' && template[i] <= 'Z')
                        {
                            template[i] = map[(int)template[i] - 65 + 26 + 1];
                        }
                    }
                }
            }

            if (template != null)
            {
                string response = new string(template);

                tw.RespondMessage(response);
            }
        }
Beispiel #9
0
 public void ProcessMessage(MessageInfo message)
 {
     if (message.Action == MessageActionType.Message)
     {
         Match match = regCommand.Match(message.Content);
         if (match.Success)
         {
             if (!string.IsNullOrWhiteSpace(match.Groups["command"].Value))
             {
                 Command command;
                 if (Enum.TryParse <Command>(textInfo.ToTitleCase(match.Groups["command"].Value), out command))
                 {
                     ProcessCommand(command, message);
                 }
                 else
                 {
                     //ignore invalid command
                 }
             }
             else
             {
                 //no command, show state and command list
                 if (UserIsMod(message))
                 {
                     tw.RespondMessage(string.Format("20 Questions is currently {0}.  Commands: enable, disable, start, stop", GetStateString()));
                 }
                 else
                 {
                     tw.RespondMessage(string.Format("20 Questions is currently {0}.  Commands: start, stop", GetStateString()));
                 }
             }
         }
         else
         {
             //look for numeric answers
             int answerId;
             if (State == State.ListeningForAnswers &&
                 message.Content.Length < 5 &&
                 int.TryParse(message.Content, out answerId))
             {
                 AddAnswer(answerId - 1);
             }
         }
     }
 }
Beispiel #10
0
 public void Process(MessageInfo message)
 {
     tw.RespondMessage("Commands: !howlong [user], !uptime [channel], !viewers, !madlib [template] (template keywords: noun/adjective/verb/adverb)");
 }
Beispiel #11
0
        private void RespondUptimeMesssage(string channel, bool wet = false)
        {
            var streamData = api.Stream(channel);

            if (streamData != null)
            {
                if (streamData.stream != null)
                {
                    DateTime created = DateTime.SpecifyKind(streamData.stream.created_at, DateTimeKind.Utc).ToLocalTime();
                    TimeSpan uptime  = DateTime.Now - created;

                    StringBuilder sb = new StringBuilder();

                    sb.AppendFormat("@{0} has been streaming for", channel);

                    if (uptime.Days == 1)
                    {
                        sb.AppendFormat(" {0} day", uptime.Days);
                    }
                    else if (uptime.Days > 1)
                    {
                        sb.AppendFormat(" {0} days", uptime.Days);
                    }

                    if (uptime.Hours == 1)
                    {
                        sb.AppendFormat(" {0} hour", uptime.Hours);
                    }
                    else if (uptime.Hours > 1)
                    {
                        sb.AppendFormat(" {0} hours", uptime.Hours);
                    }
                    else if (uptime.Hours == 0 && uptime.Days > 0)
                    {
                        sb.Append(" 0 hours");
                    }

                    if (uptime.Minutes == 1)
                    {
                        sb.AppendFormat(" {0} minute", uptime.Minutes);
                    }
                    else if (uptime.Minutes > 1)
                    {
                        sb.AppendFormat(" {0} minutes", uptime.Minutes);
                    }
                    else if (uptime.Minutes == 0 && uptime.Hours > 0)
                    {
                        sb.Append(" 0 minutes");
                    }

                    if (uptime.Seconds == 1)
                    {
                        sb.AppendFormat(" {0} second", uptime.Seconds);
                    }
                    else if (uptime.Seconds > 1)
                    {
                        sb.AppendFormat(" {0} seconds", uptime.Seconds);
                    }

                    sb.AppendLine();

                    tw.RespondMessage(sb.ToString());
                }
                else
                {
                    tw.RespondMessage(string.Format("{0} is not currently streaming!", channel));
                }
            }
        }