예제 #1
0
        public override void Use(CommandArgs command)
        {
            var messages = StatsDatabase.GetMessages();

            var usage = messages.SelectMany(m => WordTools.GetWords(m.Message)).GroupBy(w => w).ToDictionary(g => g.Key, g => g.Count());

            StatsDatabase.IncrementWords(usage);
            command.Reply("done.");
        }
예제 #2
0
        public override void HandleMessage(MessageEvent ev)
        {
            if (!Client.IncludeChannel(ev.Message.Channel))
            {
                Logger.Log(null, "Dropping message because its channel should be excluded.");
                return;
            }

            var message = ev.Message;

            // Can't save statistics if we don't have a DB connection!
            if (StatsDatabase.ConnectionState == ConnectionState.Closed)
            {
                return;
            }

            // Add the message to the chat log
            StatsDatabase.AddMessage(message);
            var userId = message.Sender.DbUser.Id;

            // Increment actions/lines for the user
            if (message.Action)
            {
                StatsDatabase.IncrementActions(userId);
            }
            else
            {
                StatsDatabase.IncrementLineCount(userId);
            }
            // Increment words for the user
            var words = WordTools.GetWords(message.Body);

            StatsDatabase.IncrementWordCount(userId, words.Count);

            // Increment global line/word count
            StatsDatabase.IncrementVar("global_line_count");
            StatsDatabase.IncrementVar("global_word_count", words.Count);

            // Update emoticon usage
            foreach (var word in words.Where(word => Emoticons.List.Contains(word)))
            {
                StatsDatabase.IncrementEmoticon(word, userId);
            }

            // Process individual words
            foreach (var word in words)
            {
                ProcessWord(message, word, userId);
            }

            // Quote grabbing
            GenerateRandomQuote(ev, words);
            ProcessRandomEvents(ev);
        }