Ejemplo n.º 1
0
        public static TriggerHelp HelpNullWrap(this Trigger tr, string errorMsg)
        {
            var help = tr.Help;

            if (help == null)
            {
                help    = new TriggerHelp(errorMsg);
                tr.Help = help;
            }

            return(help);
        }
Ejemplo n.º 2
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
            }
        };
    }
Ejemplo n.º 3
0
        public bool CreateSchedulerJob(string jobName, string jobGroup, string jobData, string jobDesc, string trrigerName, string cron, DateTimeOffset start, DateTimeOffset end)
        {
            try
            {
                IScheduler scheduler   = SchedulerPool.Scheduler;
                IJobDetail job         = JobDetailHelp.CreateJobDetail(jobName, jobGroup, jobData, jobDesc);
                ITrigger   cronTrigger = (ICronTrigger)TriggerHelp.CreateTrigger <ICronTrigger>(trrigerName, jobGroup, cron, start, end);

                scheduler.ScheduleJob(job, cronTrigger);
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static bool Query(this TriggerHelp root, string[] fullCommand, out CommandHelp help)
        {
            help = null;
            var cmdHelpNodes = root.Commands;

            foreach (string cmdPart in fullCommand)
            {
                if (TryGetHelp(cmdPart, cmdHelpNodes, out help))
                {
                    cmdHelpNodes = help.Subcommands;
                }
                else
                {
                    help = null;
                    break;
                }
            }

            return(help != null);
        }
Ejemplo n.º 5
0
        HelpResult GetHelp(HelpRequest request, TriggerHelp trHelp)
        {
            // Help query for a trigger+command.
            if (request.HasRest)
            {
                // Check if we can find a command corresponding to the query.
                // Return help for command if we do.
                CommandHelp cmdHelp;
                if (trHelp.Query(request.Rest, out cmdHelp))
                {
                    return(request.ToResult(cmdHelp, footer));
                }
            }
            // Help query for just a trigger.
            else
            {
                return(request.ToResult(trHelp, footer));
            }

            return(HelpResult.Failure);
        }
Ejemplo n.º 6
0
        void TriggerFooter(StringBuilder sb, string triggerId, TriggerHelp help)
        {
            var trigger = help.ParentTrigger;

            // Select trigger identifiers that are for this trigger and
            // filter out the current trigger id.
            var alternativeIds =
                from id in trigger.Identifiers
                where triggers.IsRegisteredAs(trigger, id)
                where id != triggerId
                select id;

            // For each related trigger select the first identifier that is known to us (prime id).
            var relatedTriggers = triggers.PrimeIds(trigger.RelatedTriggers);
            // The possible commands might also be pertinent.
            var commands = help.Commands.Select(cmd => triggerId + pathSep + cmd.Command);

            var alternative = Join(triggers.Prefix, alternativeIds);
            var related     = Join(
                triggers.Prefix,
                relatedTriggers.Concat(commands)
                );

            if (alternative != string.Empty)
            {
                sb.Append(altTrigSection).Append(alternative);
            }

            if (related != string.Empty)
            {
                if (sb.Length > 0)
                {
                    sb.Append(sectionSep);
                }

                sb.Append(relatedSection).Append(related);
            }
        }
Ejemplo n.º 7
0
    public MiscUtils(IIrcComm ircComm, IMeidoComm meido)
    {
        irc       = ircComm;
        log       = meido.CreateLogger(this);
        timerTrig = new TimerTrigger();

        var timerHelp = new TriggerHelp(
            "<duration> [message]",
            "Starts a timer. Duration is either in the form of '1h45m30s' (where each part, h/m/s, is optional) or " +
            "just a number, which is taken to be minutes. If called with no arguments this'll give an overview of " +
            "all your running timers.",

            new CommandHelp(
                "stop", "[index]",
                "Stops previously started timer. If called without an index all timers are stopped."),
            new CommandHelp(
                "change", "<index> <delta>",
                "Change previously started timer by `delta`. Delta is either in the form of '1h45m30s' or just " +
                "minutes as a bare number. Delta can be prefixed with either + or -, to substract or add to " +
                "the timer (in fact, the shorthand requires you do so).\nShorthand: timer <delta> [index]")
            );

        Triggers = new Trigger[] {
            new Trigger("timer", timerTrig.Timer)
            {
                Help = timerHelp
            },

            new Trigger("say", Say)
            {
                Help = new TriggerHelp(
                    "[channel] <message>",
                    "If bot is in the specified channel, send message to the channel. If no channel is given, " +
                    "message will be sent to current channel.")
            }
        };
    }