Example #1
0
        public void LoadAndWatchConfig <T>(string filename, XmlConfig2 <T> xmlConf)
        {
            if (xmlConf == null)
            {
                throw new ArgumentNullException(nameof(xmlConf));
            }

            LoadAndWatchConfig(filename, xmlConf.LoadConfig);
        }
Example #2
0
        public UserAuthManager(string filename, WatchConfig watcher, Logger log)
        {
            this.log = log;
            // Setting up configuration.
            var xmlConf = new XmlConfig2 <AuthDictionary>(
                AuthDictionary.DefaultConfig(),
                (xml) => new AuthDictionary(xml),
                log,
                Configure
                );

            watcher.LoadAndWatch(filename, xmlConf.LoadConfig);
        }
Example #3
0
    public NyaaSpam(IIrcComm ircComm, IMeidoComm meidoComm)
    {
        meido = meidoComm;
        irc   = ircComm;
        log   = meido.CreateLogger(this);

        // Setting up configuration.
        var xmlConf = new XmlConfig2 <Config>(
            Config.DefaultConfig(),
            (xml) => new Config(xml),
            log,
            Configure
            );

        meido.LoadAndWatchConfig("NyaaSpam.xml", xmlConf);

        var bangs = new TopicHelp[] {
            new TopicHelp("nyaa bangs", Bangs())
        };
        var nyaaHelp = new TriggerHelp(
            () => string.Format(
                "Commands to manipulate which patterns are periodically checked for at {0}", conf.Feed),

            new CommandHelp(
                "add", "<pattern...>",
                "Adds pattern(s), separated by commas (,). Unless enclosed in quotation marks (\"), in which case " +
                "the pattern is added verbatim.")
        {
            AlsoSee = bangs
        },

            new CommandHelp(
                "del", "<index...> | <pattern...>",
                "Removes pattern(s) indicated by list of indices. Can also accept a list of patterns " +
                "(or parts thereof) to be deleted. Lists of indices/patterns are comma (,) separated and indices can " +
                "be specified as a number range (x-y). (Ex: nyaa del 4, 7, 0-2)"),

            new CommandHelp(
                "show", "Gives an overview of all patterns that are checked for.")
            )
        {
            AlsoSee = bangs
        };

        Triggers = new Trigger[] {
            new Trigger("nyaa", Nyaa, TriggerOption.ChannelOnly)
            {
                Help = nyaaHelp
            }
        };
    }
Example #4
0
    public IrcWeather(IIrcComm irc, IMeidoComm meido)
    {
        Triggers = Trigger.Group(

            new Trigger("w", WeatherSearch, TriggerThreading.Queue)
        {
            Help = new TriggerHelp(
                "<city>,[country] | <zip>,[country] | @<nick>",
                "Reports weather conditions at location. Location can have an optional 2-letter country code " +
                "(ISO 3166) at the end to more precisely indicate the location. " +
                "Will use your default location if called without arguments. (Powered by OpenWeatherMap)")
        },

            new Trigger("W", SetWeatherLocation, TriggerThreading.Queue)
        {
            Help = new TriggerHelp(
                "<city>,[country] | <zip>,[country]",
                "Sets your default weather location.")
        }
            );

        this.irc = irc;
        log      = meido.CreateLogger(this);

        // Setting up configuration.
        var xmlConf = new XmlConfig2 <Config>(
            Config.DefaultConfig(),
            (xml) => new Config(xml),
            log,
            Configure
            );

        meido.LoadAndWatchConfig("WeatherService.xml", xmlConf);

        // Setting up locations database/dict.
        storagePath = meido.DataPathTo("weather-locations.xml");
        try
        {
            defaultLocations = Storage <string> .Deserialize(storagePath);
        }
        catch (FileNotFoundException)
        {
            defaultLocations = new Storage <string>();
        }
    }
Example #5
0
    public IrcRandom(IIrcComm ircComm, IMeidoComm meido)
    {
        var threading = TriggerThreading.Threadpool;

        Triggers = new Trigger[] {
            new Trigger(Choose, "choose", "decide", "d")
            {
                Help = new TriggerHelp(
                    "<option...>",
                    @"Takes a list of options separated by "","" and/or ""or"". " +
                    "If the list of options contains neither, then options will be separated by space.")
            },

            new Trigger(Countdown, threading, "countdown", "cd")
            {
                Help = new TriggerHelp(
                    "[seconds]",
                    "Want to simulwatch something? Countdown is the tool for you! Invoking this will provide you " +
                    "with an automatic countdown (default/min: 3s, max: 10s) and a spectacular launch!")
            },

            new Trigger(EightBall, threading, "8ball")
            {
                Help = new TriggerHelp(
                    "[question]",
                    "Ask the Magic 8-Ball any yes or no question.")
            }
        };

        // Setting up configuration.
        var xmlConf = new XmlConfig2 <Config>(
            Config.DefaultConfig(),
            (xml) => new Config(xml),
            meido.CreateLogger(this),
            Configure
            );

        meido.LoadAndWatchConfig("RandomChoice.xml", xmlConf);
        irc = ircComm;
    }
Example #6
0
    public UrlTitler(IIrcComm irc, IMeidoComm meido)
    {
        this.meido = meido;
        log        = meido.CreateLogger(this);

        manager   = new ChannelThreadManager(irc, log);
        qTriggers = new QueryTriggers();

        // Setting up main configuration.
        var xmlConf = new XmlConfig2 <Config>(
            Config.DefaultConfig(),
            (xml) => new Config(xml),
            log,
            manager.Configure, qTriggers.Configure
            );

        meido.LoadAndWatchConfig("UrlTitling.xml", xmlConf);

        // Setting up black- and whitelist configuration.
        meido.LoadAndWatchConfig("blacklist", WrappedIO(LoadBlacklist));
        meido.LoadAndWatchConfig("whitelist", WrappedIO(LoadWhitelist));

        // For handling messages/actions that can potentially containg URL(s).
        IrcHandlers = new IIrcHandler[] {
            new IrcHandler <IIrcMsg>(UrlHandler)
        };

        // Trigger handling.
        Triggers = Trigger.Group(

            new Trigger("disable", Disable, TriggerOption.ChannelOnly)
        {
            Help = new TriggerHelp(
                "Temporarily disable URL-Titling for you in current channel.")
        },
            new Trigger("enable", Enable, TriggerOption.ChannelOnly)
        {
            Help = new TriggerHelp(
                "Re-enable (previously disabled) URL-Titling for you.")
        }
            ).AddGroup(
            new Trigger(msg => qTriggers.Query(msg, false), TriggerThreading.Threadpool,
                        "query", "q")
        {
            Help = new TriggerHelp(
                "<url...>",
                "Query given URL(s) and return title or error.")
        },
            new Trigger(msg => qTriggers.Query(msg, true), TriggerThreading.Threadpool,
                        "query-dbg", "qd")
        {
            Help = new TriggerHelp(
                "<url...>",
                "Query given URL(s) and return title or error. (Includes extra information)")
        }
            ).AddGroup(
            new Trigger("dump", Dump)
        {
            Help = new TriggerHelp(
                "<url...>",
                "Dumps HTML content of given URL(s) to a local file for inspection. (Owner only)")
        }
            );
    }