Exemplo n.º 1
0
 private void bot_OnPublicMessage(NielsRask.FnordBot.User user, string channel, string message)
 {
     if (message == "!wordgame")
     {
     //				Console.WriteLine("someone requested a game");
         log.Info("A game was requested on "+channel);
         if (gameList.ChannelExists( channel ) )
         {
             // game is already running
             log.Warn("A game is already running.");
         }
         else
         {
             Wordgame wg = new Wordgame(bot, channel, gameList, wordListPath);
             gameList.Add( wg );
             Thread gameThread = new Thread( new ThreadStart( wg.Start ) );
             gameThread.Name = "wordgame_"+channel;
             gameThread.IsBackground = true;
             gameThread.Start();
         }
     }
     else if (message == "!score")
     {
         // TODO: list the top10 wordgamers
     }
 }
Exemplo n.º 2
0
 public void Attach(NielsRask.FnordBot.FnordBot bot)
 {
     log.Info("Attaching stat plugin");
     try
     {
         this.bot = bot;
         bot.OnPublicMessage += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPublicMessage);
         bot.OnPrivateMessage += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPrivateMessage);
     }
     catch (Exception e)
     {
         log.Error("Error in Statplugin.attach", e);
     }
 }
Exemplo n.º 3
0
        // hmm ... this should really be a switch-case
        private void bot_OnPublicMessage(NielsRask.FnordBot.User user, string channel, string message)
        {
            try
            {
                // message is not a command and is more than 2 words - add to vocabulary
                if (!message.StartsWith("!") && message.Split(' ').Length > 2)
                {
                    ParseLine(message);
                }

                // make the bot say something random
                if (message == "!talk")
                {
                    bot.SendToChannel(channel, GenerateLine());
                }
                    // saves the vocabulary - need to trig it by a timer
                else if (message == "!save")
                {
                    SaveVocabulary();
                }
                    // loads the vocabulary - why? we load it at startup
                else if (message == "!load")
                {
                    LoadVocabulary();
                }
                    // non-commands are ignored
                else if (message.StartsWith("!"))
                {
                }
                    // someone mentioned the bot by name - cant let that go unanswered
                else if (message.Split(' ').Length >= 2)
                {
                    if (message.ToLower().IndexOf(bot.NickName.ToLower()) >= 0)
                    {
                        // remove the bots name from the message
                        string baseline = message.Replace(bot.NickName + ":", "");
                        baseline = message.Replace(bot.NickName, "");

                        // generate a reply based on the modified message
                        string line = GenerateAnswer(baseline);

                        // if reply contains the bot name, generate another one - potentially lots of tries here!
                        while (line.ToLower().IndexOf(bot.NickName.ToLower()) > 0)
                            line = GenerateAnswer(message);

                        bot.SendToChannel(channel, line);
                    }

                        // roll the dice to see if we'll answer
                    else if (bot.TakeChance(sortSnakAnswerChance))
                    {
                        string line = GenerateAnswer(message);
                        if (line.Length > 0)
                            bot.SendToChannel(channel, line);
                    }
                }
            } catch(Exception e)
            {
                log.Error( "Error in bot_OnPublicMessage with message \""+message+"\"", e );
            }
        }
Exemplo n.º 4
0
 // parse private messages
 private void bot_OnPrivateMessage(NielsRask.FnordBot.User user, string channel, string message)
 {
     try
     {
         if (message.StartsWith("!set_sortsnak_answerchance"))
         {
             string[] parts = message.Split(' ');
             sortSnakAnswerChance = int.Parse(parts[1]);
         }
         else if (message.StartsWith("!get_sortsnak_answerchance"))
         {
             bot.SendToUser(user.Name, sortSnakAnswerChance + "");
         }
         else if (message.StartsWith("!set_sortsnak_minimumoverlap"))
         {
             string[] parts = message.Split(' ');
             vocab.MinimumOverlap = int.Parse(parts[1]);
         }
         else if (message.StartsWith("!get_sortsnak_minimumoverlap"))
         {
             bot.SendToUser(user.Name, vocab.MinimumOverlap + "");
         }
         else if (message.StartsWith("!set_sortsnak_simplechance"))
         {
             string[] parts = message.Split(' ');
             vocab.SimpleMatchChance = int.Parse(parts[1]);
         }
         else if (message.StartsWith("!get_sortsnak_simplechance"))
         {
             bot.SendToUser(user.Name, vocab.SimpleMatchChance + "");
         }
         else if (message.StartsWith("!set_sortsnak_ambientsimplechance"))
         {
             string[] parts = message.Split(' ');
             vocab.MinimumOverlap = int.Parse(parts[1]);
         }
         else if (message.StartsWith("!get_sortsnak_ambientsimplechance"))
         {
             bot.SendToUser(user.Name, vocab.AmbientSimpleMatchChance + "");
         }
         else if (message.StartsWith("!get_sortsnak_stat"))
         {
             bot.SendToUser(user.Name, "Words known: " + vocab.Words.Count);
             bot.SendToUser(user.Name, "Fragments known: " + vocab.CenterSortedFragments.Count);
         }
         else if (message.StartsWith("!help sortsnak"))
         {
             bot.SendToUser(user.Name, "get/set_sortsnak_answerchance value");
             bot.SendToUser(user.Name, "get/set_sortsnak_minimumoverlap value");
             bot.SendToUser(user.Name, "get/set_sortsnak_simplechance value");
             bot.SendToUser(user.Name, "get/set_sortsnak_ambientsimplechance value");
             bot.SendToUser(user.Name, "get_sortsnak_stat");
         }
     } catch (Exception e)
     {
         log.Error( "Error in bot_OnPrivateMessage with message \""+message+"\"", e );
     }
 }
Exemplo n.º 5
0
 private void bot_OnTopicChange(NielsRask.FnordBot.User user, string channel, string topic)
 {
     WriteToFile( channel, "*** "+user.Name+" sets new topic: "+topic );
 }
Exemplo n.º 6
0
 private void bot_OnPublicNotice(NielsRask.FnordBot.User user, string channel, string message)
 {
     WriteToFile( channel, "[Notice] "+message );
 }
Exemplo n.º 7
0
 private void bot_OnPublicMessage(NielsRask.FnordBot.User user, string channel, string message)
 {
     WriteToFile( channel, "<"+user.Name+"> "+message );
 }
Exemplo n.º 8
0
 private void bot_OnPrivateNotice(NielsRask.FnordBot.User user, string channel, string message)
 {
     WriteToFile( user.NickName, "[Notice] "+message );
 }
Exemplo n.º 9
0
        public void Attach(NielsRask.FnordBot.FnordBot bot)
        {
            log.Info("Attaching logger plugin");
            try
            {
                this.bot = bot;

                bot.OnPublicMessage +=new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPublicMessage);
                bot.OnPrivateMessage += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPrivateMessage);
                bot.OnChannelJoin += new NielsRask.FnordBot.FnordBot.ChannelActionHandler(bot_OnChannelJoin);
                bot.OnChannelPart += new NielsRask.FnordBot.FnordBot.ChannelActionHandler(bot_OnChannelPart);
                bot.OnChannelMode += new NielsRask.FnordBot.FnordBot.ChannelActionHandler(bot_OnChannelMode);
                bot.OnChannelKick += new NielsRask.FnordBot.FnordBot.ChannelActionHandler(bot_OnChannelKick);
                bot.OnServerQuit += new NielsRask.FnordBot.FnordBot.ChannelActionHandler(bot_OnServerQuit);
                bot.OnPrivateNotice += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPrivateNotice);
                bot.OnPublicNotice += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPublicNotice);
                bot.OnTopicChange += new NielsRask.FnordBot.FnordBot.ChannelTopicHandler(bot_OnTopicChange);
                bot.OnPublicAction += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPublicAction);
                bot.OnPrivateAction += new NielsRask.FnordBot.FnordBot.MessageHandler(bot_OnPrivateAction);
                bot.OnSendToChannel += new NielsRask.FnordBot.FnordBot.BotMessageHandler(bot_OnSendToChannel);
                bot.OnSendToUser += new NielsRask.FnordBot.FnordBot.BotMessageHandler(bot_OnSendToUser);
                bot.OnSendNotice +=new NielsRask.FnordBot.FnordBot.BotMessageHandler(bot_OnSendNotice);
                bot.OnSetMode += new NielsRask.FnordBot.FnordBot.BotMessageHandler(bot_OnSetMode);
                alarmClock.AddAlarm( new DelegateCaller(DateTime.Today.AddDays(1), new AlarmMethod( OnMidnight ) ) );
            }
            catch (Exception e)
            {
                log.Error("Failed in Logger.Attach",e);
            }
        }
Exemplo n.º 10
0
 private void bot_OnPublicMessage(NielsRask.FnordBot.User user, string channel, string message)
 {
     if (!done) {
         if (string.Compare(this.channel, channel, true)==0)
         {
             if (string.Compare(message, secretWord, true) == 0)
             {
                 done = true;
     //						Console.WriteLine("Word guessed, stopping game");
                 log.Info("Word '"+secretWord+"' guessed by "+user.NickName+". Game on "+channel+" has ended.");
                 bot.SendToChannel( channel, "Woohoo "+user.Name+"!! You got it... "+secretWord+"", true );
                 string strOldScore = user.CustomSettings.GetCustomValue("wordgame", "score");
                 int oldScore = 0;
                 try
                 {
                     if ( strOldScore == null || strOldScore.Length == 0 )
                         strOldScore = "0";
                     oldScore = int.Parse( strOldScore );
                 }
                 catch ( Exception e )
                 {
                     log.Error("error parsiong old score", e);
                 }
                 try
                 {
                     user.CustomSettings.SetCustomValue("wordgame", "score", (oldScore + 1) + "");
                     user.Save();
                 }
                 catch ( Exception e)
                 {
                     log.Error("error saving user score",e);
                 }
             }
         }
     }
 }