Provide an option to show all command aliases in the usage text and only
show the first alias in the big list. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6525 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.StringTokenizer;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
@@ -106,7 +107,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
*/
|
*/
|
||||||
public String getUsage (String command)
|
public String getUsage (String command)
|
||||||
{
|
{
|
||||||
return MessageBundle.tcompose(_usageKey, command);
|
return MessageBundle.tcompose(_usageKey,
|
||||||
|
_showAliasesInUsage ? Joiner.on('|').join(_aliases) : command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,6 +138,9 @@ public class ChatDirector extends BasicDirector
|
|||||||
|
|
||||||
/** The command's usage message translation key. */
|
/** The command's usage message translation key. */
|
||||||
protected String _usageKey;
|
protected String _usageKey;
|
||||||
|
|
||||||
|
/** The command's translated aliases. */
|
||||||
|
protected String[] _aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,14 +269,9 @@ public class ChatDirector extends BasicDirector
|
|||||||
handler._usageKey = "m.usage_" + command;
|
handler._usageKey = "m.usage_" + command;
|
||||||
|
|
||||||
String key = "c." + command;
|
String key = "c." + command;
|
||||||
if (msg.exists(key)) {
|
handler._aliases = msg.exists(key) ? msg.get(key).split("\\s+") : new String[] { command };
|
||||||
StringTokenizer st = new StringTokenizer(msg.get(key));
|
for (String alias : handler._aliases) {
|
||||||
while (st.hasMoreTokens()) {
|
_handlers.put(alias, handler);
|
||||||
_handlers.put(st.nextToken(), handler);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// fall back to just using the English command
|
|
||||||
_handlers.put(command, handler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,7 +993,11 @@ public class ChatDirector extends BasicDirector
|
|||||||
matches.put(entry.getKey(), entry.getValue());
|
matches.put(entry.getKey(), entry.getValue());
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
matches.put(entry.getKey(), entry.getValue());
|
// if we're providing the full list and we show aliases in the usage text,
|
||||||
|
// only map to the first alias
|
||||||
|
String key = (_showAliasesInUsage && command.equals("")) ?
|
||||||
|
entry.getValue()._aliases[0] : entry.getKey();
|
||||||
|
matches.put(key, entry.getValue());
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
@@ -1496,6 +1500,10 @@ public class ChatDirector extends BasicDirector
|
|||||||
/** A history of chat commands. */
|
/** A history of chat commands. */
|
||||||
protected static ArrayList<String> _history = Lists.newArrayList();
|
protected static ArrayList<String> _history = Lists.newArrayList();
|
||||||
|
|
||||||
|
/** If set, only show the first alias (translation) of each command in the full list
|
||||||
|
* and show the full list of aliases in the command usage. */
|
||||||
|
protected static boolean _showAliasesInUsage;
|
||||||
|
|
||||||
/** The maximum number of chatter usernames to track. */
|
/** The maximum number of chatter usernames to track. */
|
||||||
protected static final int MAX_CHATTERS = 6;
|
protected static final int MAX_CHATTERS = 6;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user