Пример #1
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            this.ircConfig = initor.IrcConfig;

            {
                MessageHandlerConfig config = new MessageHandlerConfig
                {
                    LineRegex  = @"^!broadcast\s+(?<bcastmsg>.+)",
                    LineAction = this.BroadcastHandler
                };

                MessageHandler bcastHandler = new MessageHandler(
                    config
                    );
                this.handlers.Add(bcastHandler);
            }

            {
                MessageHandlerConfig config = new MessageHandlerConfig
                {
                    LineRegex  = @"^!cc\s+\<(?<channel>\S+)\>\s+(?<ccmessage>.+)",
                    LineAction = this.CCHandler
                };

                MessageHandler ccHandler = new MessageHandler(
                    config
                    );
                this.handlers.Add(ccHandler);
            }
        }
Пример #2
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "CapsWatcher",
                "CapsWatcherConfig.xml"
                );

            this.log = initor.Log;

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.config      = XmlLoader.LoadCapsWatcherConfig(configPath);
            this.ignoreRegex = new Regex(CollectionToRegex(config.Ignores), RegexOptions.Compiled | RegexOptions.ExplicitCapture);
            this.config.Ignores.Clear(); // No need to eat-up RAM, we won't need this again.

            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = ".+",
                LineAction = this.HandleMessage
            };

            MessageHandler handler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(handler);
        }
Пример #3
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor pluginInit)
        {
            string configPath = Path.Combine(
                pluginInit.ChaskisConfigPluginRoot,
                "HttpServer",
                "HttpServerConfig.xml"
                );

            this.config = XmlLoader.LoadConfig(configPath);
            this.log    = pluginInit.Log;

            IChaskisEventCreator eventCreator = pluginInit.ChaskisEventCreator;

            ChaskisEventHandler coreEvent = eventCreator.CreateCoreEventHandler(
                ChaskisEventProtocol.IRC,
                this.OnConnect
                );

            this.handlers.Add(coreEvent);

            ConnectedEventConfig connectedEventConfig = new ConnectedEventConfig
            {
                ConnectedAction = this.OnConnect
            };

            this.handlers.Add(
                new ConnectedEventHandler(connectedEventConfig)
                );
        }
Пример #4
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor initor)
        {
            this.chaskisEventCreator = initor.ChaskisEventCreator;
            this.eventSender         = initor.ChaskisEventSender;
            this.ircConfig           = initor.IrcConfig;
            this.logger = initor.Log;

            this.pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "NewVersionNotifier"
                );

            string configPath = Path.Combine(
                this.pluginDir,
                "NewVersionNotifierConfig.xml"
                );

            this.config = XmlLoader.LoadConfig(configPath);

            this.cachedFilePath = Path.Combine(
                this.pluginDir,
                cacheFileName
                );

            if (File.Exists(this.cachedFilePath) == false)
            {
                this.cachedVersion = string.Empty;
            }
            else
            {
                string[] lines = File.ReadAllLines(this.cachedFilePath);
                if (lines.Length == 0)
                {
                    this.cachedVersion = string.Empty;
                }
                else
                {
                    this.cachedVersion = lines[0].Trim();
                }
            }

            ChaskisEventHandler eventHandler = this.chaskisEventCreator.CreatePluginEventHandler(
                "chaskis",
                this.HandleChaskisEvent
                );

            this.ircHandlers.Add(eventHandler);

            JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
            {
                JoinAction    = this.OnJoinChannel,
                RespondToSelf = true
            };
            JoinHandler joinHandler = new JoinHandler(joinHandlerConfig);

            this.ircHandlers.Add(joinHandler);
        }
Пример #5
0
        public void TestSetup()
        {
            this.mockEventCreator = new Mock <IChaskisEventCreator>(MockBehavior.Strict);
            this.mockEventSender  = new Mock <IChaskisEventSender>(MockBehavior.Strict);

            this.initor = new PluginInitor
            {
                ChaskisEventCreator = this.mockEventCreator.Object,
                ChaskisEventSender  = this.mockEventSender.Object
            };
        }
Пример #6
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "WelcomeBot",
                "WelcomeBotConfig.xml"
                );

            WelcomeBotConfig config = XmlLoader.LoadConfig(configPath);

            this.Init(initor, config);
        }
Пример #7
0
        public void TestSetup()
        {
            this.mockWriter = new Mock <IIrcWriter>(MockBehavior.Strict);
            this.ircConfig  = TestHelpers.GetTestIrcConfig();
            this.ircConfig.Channels.Add("#channel2");

            this.uut = new CrossChannelPlugin();

            PluginInitor initor = new PluginInitor();

            initor.IrcConfig = this.ircConfig;
            this.uut.Init(initor);
        }
Пример #8
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "RssBot",
                "RssBotConfig.xml"
                );

            this.admins = initor.IrcConfig.Admins;

            this.pluginLogger = initor.Log;

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.scheduler = initor.EventScheduler;

            this.rssConfig = XmlLoader.ParseConfig(configPath);
            foreach (Feed feed in this.rssConfig.Feeds)
            {
                FeedReader reader = new FeedReader(feed, initor.HttpClient);

                reader.Init();

                int eventId = this.scheduler.ScheduleRecurringEvent(
                    feed.RefreshInterval,
                    delegate(IIrcWriter writer)
                {
                    CheckForUpdates(reader, writer, feed.Channels);
                }
                    );

                this.feedReaders.Add(eventId, reader);
            }

            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = @"!debug\s+rssbot\s+updatefeed\s+(?<url>\S+)",
                LineAction = this.HandleDebug
            };

            MessageHandler debugHandler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(debugHandler);
        }
Пример #9
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = handlerRegex,
                LineAction = MathHandler
            };

            MessageHandler handler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(handler);
        }
Пример #10
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "UserListBot",
                "UserListBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.userListConfig = XmlLoader.LoadConfig(configPath);

            // User query command:
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.userListConfig.Command,
                    LineAction = this.HandleGetUsersCommand,
                    CoolDown   = this.userListConfig.Cooldown
                };

                MessageHandler userQueryHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(userQueryHandler);
            }
            {
                AllHandlerConfig allHandlerConfig = new AllHandlerConfig
                {
                    AllAction = this.HandleNamesResponse
                };
                AllHandler nameResponseHandler = new AllHandler(allHandlerConfig);
                this.handlers.Add(nameResponseHandler);
            }

            {
                AllHandlerConfig allHandlerConfig = new AllHandlerConfig
                {
                    AllAction = this.HandleEndOfNamesResponse
                };
                AllHandler endOfNamesHandler = new AllHandler(allHandlerConfig);
                this.handlers.Add(endOfNamesHandler);
            }
        }
Пример #11
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = weatherCommand,
                LineAction = HandleWeatherCommand,
                CoolDown   = cooldown
            };

            MessageHandler weatherHandler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(weatherHandler);
        }
Пример #12
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            AllHandlerConfig allHandlerConfig = new AllHandlerConfig
            {
                AllAction = delegate(AllHandlerArgs args)
                {
                    Console.WriteLine(args.Line);
                }
            };

            AllHandler handler = new AllHandler(
                allHandlerConfig
                );

            this.handlers.Add(handler);
        }
Пример #13
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            // Search for EVERY message.  Our MessageFixer will then determine
            // what to do with it.
            MessageHandlerConfig config = new MessageHandlerConfig
            {
                LineRegex  = ".+",
                LineAction = this.HandleMessage
            };

            MessageHandler handler = new MessageHandler(
                config
                );

            this.handlers.Add(handler);
        }
Пример #14
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor initor)
        {
            this.logger = initor.Log;

            string pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "IsItDownBot"
                );

            string configPath = Path.Combine(
                pluginDir,
                "IsItDownBotConfig.xml"
                );

            this.config = XmlLoader.LoadConfig(configPath);
        }
Пример #15
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            this.urlReader = new UrlReader(initor.Log, initor.HttpClient);

            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = ".+",
                LineAction = this.HandleMessage
            };

            MessageHandler handler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(handler);
        }
Пример #16
0
        /// <summary>
        /// An initor that is used if we already know the config object.
        /// </summary>
        public void Init(PluginInitor initor, WelcomeBotConfig config)
        {
            if (this.isLoaded == false)
            {
                this.eventCreator = initor.ChaskisEventCreator;
                this.eventSender  = initor.ChaskisEventSender;

                if (config.EnableJoinMessages)
                {
                    JoinHandlerConfig joinHandlerConfig = new JoinHandlerConfig
                    {
                        JoinAction = this.JoinMessage
                    };
                    this.handlers.Add(new JoinHandler(joinHandlerConfig));
                }

                if (config.EnablePartMessages)
                {
                    PartHandlerConfig partHandlerConfig = new PartHandlerConfig
                    {
                        PartAction = PartMessage
                    };
                    this.handlers.Add(new PartHandler(partHandlerConfig));
                }

                if (config.EnableKickMessages)
                {
                    KickHandlerConfig kickHandlerConfig = new KickHandlerConfig
                    {
                        KickAction = KickMessage
                    };

                    this.handlers.Add(new KickHandler(kickHandlerConfig));
                }

                if (config.EnableJoinMessages && config.KarmaBotIntegration)
                {
                    ChaskisEventHandler karmaHandler = this.eventCreator.CreatePluginEventHandler(
                        "karmabot",
                        HandleKarmaQuery
                        );
                    this.handlers.Add(karmaHandler);
                }

                this.isLoaded = true;
            }
        }
Пример #17
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor initor)
        {
            this.logger = initor.Log;

            this.pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                PluginName
                );

            this.defaultNotesDirectory = Path.Combine(
                this.pluginDir,
                "meeting_notes"
                );

            ReadConfigFiles();
            BuildRootHelpMsg();
        }
Пример #18
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "XmlBot",
                "XmlBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.ircConfig = initor.IrcConfig;

            this.handlers.AddRange(XmlLoader.LoadXmlBotConfig(configPath, this.ircConfig));
        }
Пример #19
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>

        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "CowSayBot",
                "CowSayBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.cowSayConfig = XmlLoader.LoadCowSayBotConfig(configPath);

            if (File.Exists(cowSayConfig.ExeCommand) == false)
            {
                throw new InvalidOperationException("Can not load cowsay program from " + cowSayConfig.ExeCommand);
            }

            this.cowSayInfo.FileName = cowSayConfig.ExeCommand;
            this.cowsayRegex         = ConstructRegex(this.cowSayConfig);

            Console.WriteLine("CowSayBot: Using Regex '" + this.cowsayRegex + "'");

            MessageHandlerConfig cowsayHandlerConfig = new MessageHandlerConfig
            {
                LineRegex      = this.cowsayRegex,
                LineAction     = this.HandleCowsayCommand,
                CoolDown       = (int)cowSayConfig.CoolDownTimeSeconds,
                ResponseOption = ResponseOptions.ChannelOnly
            };

            IIrcHandler cowSayHandler = new MessageHandler(
                cowsayHandlerConfig
                );

            this.handlers.Add(
                cowSayHandler
                );
        }
Пример #20
0
        // ---------------- Functions ----------------

        public void Init(PluginInitor pluginInit)
        {
            this.ircConfig           = pluginInit.IrcConfig;
            this.chaskisEventCreator = pluginInit.ChaskisEventCreator;
            this.chaskisEventSender  = pluginInit.ChaskisEventSender;

            this.AddPluginListHandler();
            this.AddSourceHandler();
            this.AddVersionHandler();
            this.AddAboutHandler();
            this.AddHelpHandler();
            this.AddAdminHandler();
            this.AddDebugHandlers();
            this.AddCtcpPingHandler();

            // Must always check for pings.
            this.handlers.Add(new PingHandler());

            // Must always handle pongs.
            this.handlers.Add(new PongHandler());
        }
Пример #21
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "IrcLogger"
                );

            string configPath = Path.Combine(
                pluginDir,
                "IrcLoggerConfig.xml"
                );

            this.config = XmlLoader.LoadIrcLoggerConfig(
                configPath
                );

            if (string.IsNullOrEmpty(config.LogFileLocation))
            {
                config.LogFileLocation = Path.Combine(pluginDir, "Logs");
            }
            if (string.IsNullOrEmpty(config.LogName))
            {
                config.LogName = "irclog";
            }

            this.logManager = new LogManager(config, initor.Log);

            AllHandlerConfig allHandlerConfig = new AllHandlerConfig
            {
                AllAction = this.HandleLogEvent
            };

            AllHandler handler = new AllHandler(
                allHandlerConfig
                );

            this.handlers.Add(handler);
        }
Пример #22
0
        // -------- Functions --------

        /// <summary>
        /// Loads the given list of plugins.
        /// Any errors are logged to the passed in logger.
        /// </summary>
        /// <param name="assemblyList">List of assemblies we are to load.</param>
        /// <param name="existingPlugins">Already created plugins that do not need to be inited via reflection.</param>
        /// <param name="ircConfig">The irc config we are using.</param>
        /// <param name="chaskisConfigRoot">The root of the chaskis config.</param>
        public bool LoadPlugins(
            IList <AssemblyConfig> assemblyList,
            IList <PluginConfig> existingPlugins,
            IIrcConfig ircConfig,
            IChaskisEventScheduler scheduler,
            IChaskisEventSender eventSender,
            HttpClient httpClient,
            string chaskisConfigRoot
            )
        {
            bool success = true;

            foreach (AssemblyConfig assemblyConfig in assemblyList)
            {
                try
                {
                    Assembly dll = Assembly.LoadFrom(assemblyConfig.AssemblyPath);

                    // Grab all the plugins, which have the ChaskisPlugin Attribute attached to them.
                    var types = from type in dll.GetTypes()
                                where type.IsDefined(typeof(ChaskisPlugin), false)
                                select type;

                    foreach (Type type in types)
                    {
                        // Make instance
                        object  instance = Activator.CreateInstance(type);
                        IPlugin plugin   = instance as IPlugin;
                        if (plugin == null)
                        {
                            string errorString = string.Format(
                                "Can not cast {0} to {1}, make sure your {0} class implements {1}",
                                type.Name,
                                nameof(IPlugin)
                                );

                            throw new InvalidCastException(errorString);
                        }

                        ChaskisPlugin chaskisPlugin = type.GetCustomAttribute <ChaskisPlugin>();

                        this.plugins.Add(
                            chaskisPlugin.PluginName,
                            new PluginConfig(
                                assemblyConfig.AssemblyPath,
                                chaskisPlugin.PluginName,
                                assemblyConfig.BlackListedChannels,
                                plugin,
                                new GenericLogger()
                                )
                            );

                        StaticLogger.Log.WriteLine("Successfully loaded plugin: " + chaskisPlugin.PluginName);
                    }
                }
                catch (Exception e)
                {
                    StringBuilder errorString = new StringBuilder();
                    errorString.AppendLine("*************");
                    errorString.AppendLine("Warning! Error when loading assembly " + assemblyConfig.AssemblyPath + ":");
                    errorString.AppendLine(e.Message);
                    errorString.AppendLine();
                    errorString.AppendLine(e.StackTrace);
                    errorString.AppendLine();
                    if (e.InnerException != null)
                    {
                        errorString.AppendLine("\tInner Exception:");
                        errorString.AppendLine("\t\t" + e.InnerException.Message);
                        errorString.AppendLine("\t\t" + e.InnerException.StackTrace);
                    }
                    errorString.AppendLine("*************");

                    success = false;

                    StaticLogger.Log.ErrorWriteLine(errorString.ToString());
                }
            }

            foreach (PluginConfig existingPlugin in existingPlugins)
            {
                this.plugins.Add(existingPlugin.Name, existingPlugin);
            }

            this.eventFactory = ChaskisEventFactory.CreateInstance(this.plugins.Keys.ToList());
            foreach (KeyValuePair <string, PluginConfig> plugin in this.plugins)
            {
                try
                {
                    PluginInitor initor = new PluginInitor
                    {
                        PluginPath          = plugin.Value.AssemblyPath,
                        IrcConfig           = ircConfig,
                        EventScheduler      = scheduler,
                        ChaskisEventSender  = eventSender,
                        ChaskisConfigRoot   = chaskisConfigRoot,
                        ChaskisEventCreator = this.eventFactory.EventCreators[plugin.Key],
                        HttpClient          = httpClient,
                        Log = plugin.Value.Log
                    };

                    initor.Log.OnWriteLine += delegate(string msg)
                    {
                        StaticLogger.Log.WriteLine("{0}> {1}", plugin.Value.Name, msg);
                    };

                    initor.Log.OnErrorWriteLine += delegate(string msg)
                    {
                        StaticLogger.Log.ErrorWriteLine("{0}> {1}", plugin.Value.Name, msg);
                    };

                    plugin.Value.Plugin.Init(initor);

                    StaticLogger.Log.WriteLine("Successfully inited plugin: " + plugin.Value.Name);
                }
                catch (Exception e)
                {
                    StringBuilder errorString = new StringBuilder();
                    errorString.AppendLine("*************");
                    errorString.AppendLine("Warning! Error when initing plugin " + plugin.Key + ":");
                    errorString.AppendLine(e.Message);
                    errorString.AppendLine();
                    errorString.AppendLine(e.StackTrace);
                    errorString.AppendLine();

                    Exception innerException = e.InnerException;

                    if (innerException != null)
                    {
                        errorString.AppendLine("\tInner Exception:");
                        errorString.AppendLine("\t\t" + e.InnerException.Message);
                        errorString.AppendLine("\t\t" + e.InnerException.StackTrace);
                        innerException = innerException.InnerException;
                    }
                    errorString.AppendLine("*************");

                    success = false;

                    StaticLogger.Log.ErrorWriteLine(errorString.ToString());
                }
            }

            return(success);
        }
Пример #23
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "ServerDiagnostics",
                "ServerDiagnosticsConfig.xml"
                );

            this.config    = XmlLoader.LoadConfig(configPath);
            this.ircConfig = initor.IrcConfig;

            if (string.IsNullOrEmpty(config.UpTimeCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.UpTimeCmd,
                    LineAction = HandleUpTimeCmd,
                    CoolDown   = coolDown
                };

                MessageHandler utimeHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(utimeHandler);
            }

            if (string.IsNullOrEmpty(config.OsVersionCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.OsVersionCmd,
                    LineAction = HandleOsVersionCmd,
                    CoolDown   = coolDown
                };

                MessageHandler osHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(osHandler);
            }

            if (string.IsNullOrEmpty(config.ProcessorCountCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.ProcessorCountCmd,
                    LineAction = HandleProcessorCountCmd,
                    CoolDown   = coolDown
                };

                MessageHandler procCoundHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(procCoundHandler);
            }

            if (string.IsNullOrEmpty(config.TimeCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.TimeCmd,
                    LineAction = HandleTimeCmd,
                    CoolDown   = coolDown
                };

                MessageHandler timeHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(timeHandler);
            }
        }
Пример #24
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string karmaBotRoot = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "KarmaBot"
                );

            string dbPath = Path.Combine(
                karmaBotRoot,
                "karmabot.ldb"
                );

            string configPath = Path.Combine(
                karmaBotRoot,
                "KarmaBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.config       = XmlLoader.LoadKarmaBotConfig(configPath);
            this.dataBase     = new KarmaBotDatabase(dbPath);
            this.eventSender  = initor.ChaskisEventSender;
            this.eventCreator = initor.ChaskisEventCreator;

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.IncreaseCommandRegex,
                    LineAction = HandleIncreaseCommand
                };

                MessageHandler increaseHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(increaseHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.DecreaseCommandRegex,
                    LineAction = HandleDecreaseCommand
                };

                MessageHandler decreaseCommand = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(decreaseCommand);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.config.QueryCommand,
                    LineAction = HandleQueryCommand
                };

                MessageHandler queryCommand = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(queryCommand);
            }

            {
                ChaskisEventHandler chaskisQuery = initor.ChaskisEventCreator.CreatePluginEventHandler(
                    this.HandleChaskisQueryCommand
                    );
                this.handlers.Add(chaskisQuery);
            }
        }
Пример #25
0
        public void Init(PluginInitor pluginInit)
        {
            this.log = pluginInit.Log;

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = sleepPattern,
                    LineAction = this.HandleSleep
                };

                MessageHandler sleepHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(sleepHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = forceSleepPattern,
                    LineAction = this.HandleForceSleep
                };

                MessageHandler forceSleepHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(forceSleepHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = canaryPattern,
                    LineAction = this.HandleCanary
                };

                MessageHandler canaryHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(canaryHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = asyncAwaitThreadTestPattern,
                    LineAction = this.DoAsyncTest
                };

                MessageHandler asyncHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(asyncHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = asyncAwaitExceptionTestPattern,
                    LineAction = this.DoAsyncExceptionTest
                };

                MessageHandler asyncHandler = new MessageHandler(
                    msgConfig
                    );

                this.handlers.Add(asyncHandler);
            }
        }
Пример #26
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string quoteBotRoot = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "QuoteBot"
                );

            string configPath = Path.Combine(
                quoteBotRoot,
                "QuoteBotConfig.xml"
                );

            if (File.Exists(configPath) == false)
            {
                throw new FileNotFoundException(
                          "Can not open " + configPath
                          );
            }

            this.ircConfig = initor.IrcConfig;

            this.quoteBotConfig = XmlLoader.LoadConfig(configPath);
            this.parser         = new QuoteBotParser(this.quoteBotConfig);
            this.db             = new QuoteBotDatabase(Path.Combine(quoteBotRoot, "quotes.ldb"));

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.quoteBotConfig.AddCommand,
                    LineAction = this.AddHandler
                };

                MessageHandler addHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(addHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.quoteBotConfig.DeleteCommand,
                    LineAction = this.DeleteHandler
                };

                MessageHandler deleteHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(deleteHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.quoteBotConfig.RandomCommand,
                    LineAction = this.RandomHandler
                };

                MessageHandler randomHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(randomHandler);
            }

            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = this.quoteBotConfig.GetCommand,
                    LineAction = this.GetHandler
                };

                MessageHandler getHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlers.Add(getHandler);
            }
        }