JakobOvrum / Diggler

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

Options for commands #14

Open mitchgrout opened 9 years ago

mitchgrout commented 9 years ago

A command such as !time may require several options: One to add, another to remove, and one to show. They may be called by !time add [nick] [zone], !time remove [nick], and !time [nick]. Currently, to implement this, you may do something like

void time(string[] args...){
    switch(args[0].toLower){
        case "add": ... break;
        case "remove": ... break;
        default: ... break;
    }
}

My suggestion is to define multiple functions which state which option they accept, delimited by an underscore

void time_add(string nick, string zone){ ... }
void time_remove(string nick){ ... }
void time(string nick){ ... }

In addition to better code readability, this change would make the options for a command more visible when using !help.