JakobOvrum / Diggler

IRC bot framework for the D programming language
http://jakobovrum.github.io/Diggler/
Other
6 stars 5 forks source link

Added support for sub-commands #16

Closed mitchgrout closed 7 years ago

mitchgrout commented 8 years ago

See issue #14 This change allows the user to define sub-commands, helping to keep commands modular. Usage:

class TimeCommands : CommandSet!TimeCommands
{
    mixin CommandContext!();
    string[string] tz;
    void time(string s = null)
    {
        import std.datetime;
        if(!s) time(user.nickName.idup);
        else if(s !in tz) return;
        else reply("Time for %s is %s", s, Clock.currTime(TimeZone.getTimeZone(tz[s])));
    }
    void time_set(string zone)
    {
        tz[user.nickName.idup] = zone;
    }
    void time_unset()
    {
        tz.remove(user.nickName.idup);
    }
}

These commands are callable via:

and are listed under the !help command as only time

JakobOvrum commented 8 years ago

It should handle subcommands arbitrarily deep; with foo_bar_a and foo_bar_b, a and b should be subcommands of foo bar.

JakobOvrum commented 8 years ago

How does this handle help text?

mitchgrout commented 8 years ago

Currently, this code does not handle help text. I can include that in this pull, however.