# Create a command alias for gccg. # # Copyright (C) 2005 Neil Moore . Distributed with NO WARRANTY # under the terms of the GPL, version 2 (only). # if(msg.box != NULL) { Msg("Loading {gold}alias.include"); } # prefix(m) - Return the function prefix for mode m. If m is anything other # than "play", "chat", or "watch", it is treated as though # it were "any" def prefix { if(ARG == "play") { return("PlayCommand"); } else if(ARG == "chat") { return("ChatCommand"); } else if(ARG == "watch") { return("WatchCommand"); } else { return("Command"); } } # alias(m,a,f) - Defines a as an alias for command f in mode m. If m is # anything other than "play", "chat", or "watch", it is treated as though # it were "any". # # This overrides any previous definition for the command named a, so be # careful. def alias { push(type); push(alias); push(target); push(fprefix); type = ARG[0]; alias = ARG[1]; target = ARG[2]; fprefix = prefix(type); if(fprefix == "Command") { type = "any"; } eval( "def " + fprefix + ucfirst(alias) + " { " + "return(" + fprefix + ucfirst(target) + "(ARG));" + " }" ); HELP{type}{alias} = HELP{type}{target}; fprefix = pop(); target = pop(); alias = pop(); type = pop(); } def CommandAlias { push(mode); push(alias); push(target); if(length(ARG) == 2 || length(ARG) == 3) { if(length(ARG) == 3) { mode = ARG[0]; alias = ARG[1]; target = ARG[2]; } else { mode = "any"; alias = ARG[0]; target = ARG[1]; } if(!isfunction(prefix(mode) + ucfirst(target))) { Msg("{red}Undefined command {cyan}" + target + "{red}."); } else { if(isfunction(prefix(mode) + ucfirst(alias)) > 0) { Msg("{orange}Redefining command {cyan}" + alias + "{orange}."); } else { Msg("{gold}Defining new alias {cyan}" + alias + "{gold}."); } alias(mode,alias,target); } } else { Msg("{red}Command {gold}alias{red} requires three arguments"); } target = pop(); alias = pop(); mode = pop(); } HELP{"any"}{"alias"}=("[mode],alias,command","create an alias",NULL, "Make {yellow}{white} an alias for the command {yellow}{white} in mode {yellow}{white}. {yellow}{white} is one of {orange}any{white}, {orange}chat{white}, {orange}play{white}, or {orange}watch{white}; if another value is given, or if {yellow}{white} is unspecified, mode {orange}any{white} is assumed." );