Esempio n. 1
0
        void ICommand.Process(MessageInfo message)
        {
            Match match = commandRegex.Match(message.Content);

            if (match.Success)
            {
                Model.Quote quote;
                if (!string.IsNullOrWhiteSpace(match.Groups["attribution"].Value))
                {
                    string attribution = match.Groups["attribution"].Value;

                    //match nicknames
                    NicknameRegex nickMatch = nicknameRegex.FirstOrDefault(n => n.Regex.IsMatch(attribution));
                    if (nickMatch != null)
                    {
                        attribution = nickMatch.Nickname.Username;
                    }

                    quote = quoteRepo.GetRandomByName(attribution);
                }
                else
                {
                    quote = quoteRepo.GetRandom();
                }

                if (quote != null)
                {
                    tw.RespondMessage(string.Format("\"{0}\" -{1} {2}"
                                                    , quote.Text
                                                    , quote.AttributedTo
                                                    , quote.AttributedDate.ToString(DATE_FORMAT, CultureInfo.InvariantCulture)));
                }
            }
        }
Esempio n. 2
0
        void IKeyword.Process(MessageInfo message)
        {
            string response = string.Empty;

            Match match = quoteRegex.Match(message.Content);

            if (match.Success)
            {
                string   attribution     = match.Groups["attribution"].Value;
                string   quoteText       = match.Groups["text"].Value;
                DateTime attributionDate = DateTime.Now;

                //match nicknames
                NicknameRegex nickMatch = nicknameRegex.FirstOrDefault(n => n.Regex.IsMatch(attribution));
                if (nickMatch != null)
                {
                    attribution = nickMatch.Nickname.Username;
                }

                Model.Quote quote = new Model.Quote
                {
                    Text           = quoteText,
                    AttributedTo   = attribution,
                    AttributedDate = DateTime.Now, //TODO: parse this from regex
                    CreatedBy      = message.Username
                };

                //add to db
                quoteRepo.AddUpdate(quote);

                tw.RespondMessage(string.Format("Added new quote: \"{0}\" -{1} {2}"
                                                , quoteText
                                                , attribution
                                                , attributionDate.ToString(DATE_FORMAT, CultureInfo.InvariantCulture)));
            }
        }