Beispiel #1
0
        public void ProcessMessage(IrcMessage message)
        {
            // Can't save statistics if we don't have a DB connection!
            if (message.Client.StatsDatabase.ConnectionState == ConnectionState.Closed) return;

            var userId = message.Client.StatsDatabase.GetIdFromUser(message.Sender);
            Logger.Log(this, $"Processing message for {message.Sender.Nick} (uid: {userId})");
            AddMessageToIrcLog(message, userId);

            if (message.Action)
                message.Client.StatsDatabase.IncrementActions(userId);
            else
                message.Client.StatsDatabase.IncrementLineCount(userId);

            var words = WordTools.GetWords(message.Message);
            message.Client.StatsDatabase.IncrementWordCount(userId, words.Count);

            message.Client.StatsDatabase.IncrementVar("global_line_count");
            message.Client.StatsDatabase.IncrementVar("global_word_count", words.Count);
            GenerateRandomQuote(message, words, userId);
            ProcessRandomEvents(message);
            GetEmoticons(message.Client.StatsDatabase, userId, words);
            foreach (var word in words)
            {
                ProcessWord(message, word, userId);
            }
        }
Beispiel #2
0
 private void AddMessageToIrcLog(IrcMessage message, int userId)
 {
     message.Client.StatsDatabase.AddIrcMessage(DateTime.Now, userId, message.Channel, message.Sender.Nick,
         message.Action
         ? $"*{message.Sender.Nick} {message.Message}*"
         : message.Message);
 }
Beispiel #3
0
        public void ProcessMessage(IrcMessage message)
        {
            Logger.Log(this, "Processing command: " + message.Message);
            if (message.Message.Equals(Bot.CommandIdentifier)) return;

            var cmdInfo = CommandArgs.FromMessage(message);
            ProcessCommand(cmdInfo);
        }
Beispiel #4
0
        private void GenerateRandomQuote(IrcMessage message, List<string> words, int userId)
        {
            if (message.Action)
            {
                message.Message = "*" + message.Sender.Nick + " " + message.Message + "*";
            }

            if (ControlVariables.SnagNextLine)
            {
                ControlVariables.SnagNextLine = false;
                message.Client.StatsDatabase.Snag(message);
                message.ReturnMessage("Snagged line on request.");
                return;
            }
            if (ControlVariables.SnagNextLineBy != null && ControlVariables.SnagNextLineBy == message.Sender.Nick)
            {
                ControlVariables.SnagNextLineBy = null;
                message.Client.StatsDatabase.Snag(message);
                message.ReturnMessage("Snagged line on request.");
                return;
            }

            TryTakeQuote(message, words, userId);
        }
Beispiel #5
0
        private void TryTakeQuote(IrcMessage message, List<string> words, int userId)
        {
            var last = message.Client.StatsDatabase.GetLastQuotedLine(userId);
            if (last.HasValue)
            {
                if ((DateTime.Now - last.Value).Hours < ConfigManager.Config.Quotes.MinDelayHours)
                {
                    return;
                }
            }

            var snagChance = ConfigManager.Config.Quotes.Chance;
            var silenceChance = ConfigManager.Config.Quotes.SilentQuoteChance;

            if (words.Count > 6)
            { // Do not snag if the amount of words to be snagged is less than 7
                if (rand.NextDouble() <= snagChance)
                {
                    var allowSnagMessage = ConfigManager.Config.Quotes.AllowQuoteNotifications;
                    var hideSnagMessage = rand.NextDouble() <= silenceChance;
                    if (!allowSnagMessage || hideSnagMessage)
                    { // Check if snag message should be displayed
                        Logger.Log(this, "Silently snagging this message");
                        message.Client.StatsDatabase.Snag(message);
                    }
                    else
                    {
                        var randint = rand.Next(snagMessages.Length * 2); // Determine whether to simply say "Snagged!" or use a randomized snag message.
                        if (randint < snagMessages.Length)
                        {
                            TakeQuote(message, snagMessages[randint]);
                        }
                        else
                        {
                            TakeQuote(message, "Snagged!");
                        }
                    }
                }
            }
        }
Beispiel #6
0
 private void TakeQuote(IrcMessage message, string snagMessage)
 {
     message.ReturnMessage(snagMessage);
     message.Client.StatsDatabase.Snag(message);
 }
Beispiel #7
0
 private void ProcessWord(IrcMessage message, string word, int sender)
 {
     var lword = word.ToLower();
     var cword = textOnly.Replace(lword, string.Empty);
     if (word.StartsWith("http://") || word.StartsWith("https://"))
     {
         message.Client.StatsDatabase.IncrementUrl(word, sender, message.Message);
     }
     else if (!WordTools.IsIgnoredWord(cword) && cword.Length >= 3)
     {
         message.Client.StatsDatabase.IncrementWord(cword);
     }
     if (WordTools.IsProfanity(lword))
     {
         message.Client.StatsDatabase.IncrementProfanities(sender);
     }
 }
Beispiel #8
0
 private void ProcessRandomEvents(IrcMessage message)
 {
     if (message.Sender.Nick == "Ralph" && message.Message.ToLower().Contains("baggybot"))
     {
         message.ReturnMessage("Shut up you fool");
     }
     else if (message.Message.ToLower().Contains("f**k you baggybot"))
     {
         message.ReturnMessage("pls ;___;");
     }
 }