Example #1
0
 protected void AddPotentialQuote(Quote quote, string channel)
 {
     if (!PotentialQuotesPerChannel.ContainsKey(channel))
     {
         PotentialQuotesPerChannel[channel] = new List <Quote>(Config.RememberForQuotes + 1);
     }
     PotentialQuotesPerChannel[channel].Add(quote);
 }
Example #2
0
        protected void CleanOutPotentialQuotes(string channel)
        {
            // clean out
            if (!PotentialQuotesPerChannel.ContainsKey(channel))
            {
                return;
            }

            var thisChannelPotentialQuotes = PotentialQuotesPerChannel[channel];

            if (thisChannelPotentialQuotes.Count > Config.RememberForQuotes)
            {
                thisChannelPotentialQuotes.RemoveRange(0, thisChannelPotentialQuotes.Count - Config.RememberForQuotes);
            }
        }
Example #3
0
        protected virtual void HandleRememberCommand(CommandMatch cmd, IChannelMessageEventArgs msg)
        {
            var nick      = (string)cmd.Arguments[0];
            var substring = (string)cmd.Arguments[1];

            if (substring.StartsWith(" "))
            {
                substring = substring.Substring(1);
            }

            string lowercaseSubstring = substring.ToLowerInvariant();

            string registeredNick          = ConnectionManager.RegisteredNameForNick(nick) ?? nick;
            string lowercaseRegisteredNick = registeredNick.ToLowerInvariant();

            string normalizedNick = ConnectionManager.RegisteredNameForNick(msg.SenderNickname) ?? msg.SenderNickname;

            if (lowercaseRegisteredNick == normalizedNick.ToLowerInvariant())
            {
                ConnectionManager.SendChannelMessageFormat(
                    msg.Channel,
                    "Sorry, {0}, someone else has to remember your quotes.",
                    msg.SenderNickname
                    );
                return;
            }

            // find it
            Quote matchedQuote = PotentialQuotesPerChannel.ContainsKey(msg.Channel)
                ? PotentialQuotesPerChannel[msg.Channel]
                                 .OrderByDescending(potQuote => potQuote.Timestamp)
                                 .FirstOrDefault(potQuote => potQuote.Author.ToLower() == lowercaseRegisteredNick && potQuote.Body.ToLower().Contains(lowercaseSubstring))
                : null;

            if (matchedQuote == null)
            {
                ConnectionManager.SendChannelMessageFormat(
                    msg.Channel,
                    "Sorry, {0}, I don't remember what {1} said about \"{2}\".",
                    msg.SenderNickname,
                    nick,
                    substring
                    );
                return;
            }

            using (var ctx = GetNewContext())
            {
                ctx.Quotes.Add(matchedQuote);
                ctx.SaveChanges();
                LastQuoteIDs[msg.Channel] = matchedQuote.ID;
            }

            ConnectionManager.SendChannelMessageFormat(
                msg.Channel,
                "Remembering {0}",
                FormatQuote(matchedQuote, 0)
                );

            // invalidate these
            ShuffledAnyQuotes  = null;
            ShuffledBadQuotes  = null;
            ShuffledGoodQuotes = null;
        }