1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Implement command aliases

Closes #35
This commit is contained in:
Tim Düsterhus 2013-06-17 23:48:59 +02:00
parent c5102d63a9
commit 098f048e29
4 changed files with 31 additions and 7 deletions

View File

@ -146,6 +146,9 @@ public function readCommands() {
if ($command == 'Plain') continue;
$this->commands[] = \wcf\util\StringUtil::toLowerCase($command);
}
$this->commands = array_merge($this->commands, array_keys(\chat\system\command\CommandHandler::getAliasMap()));
sort($this->commands);
}
/**

View File

@ -41,6 +41,22 @@ public function __construct($text, \chat\data\room\Room $room = null) {
$this->room = $room;
}
/**
* Returns the alias map. Key is the alias, value is the target.
*
* @return array<string>
*/
public static function getAliasMap() {
$result = array();
foreach (explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CHAT_COMMAND_ALIASES))) as $line) {
list($key, $val) = explode(':', $line, 2);
$result[$key] = $val;
}
return $result;
}
/**
* Checks whether the given text is a command.
*/
@ -90,6 +106,9 @@ public function loadCommand() {
return new commands\PlainCommand($this);
}
$aliases = self::getAliasMap();
if (isset($aliases[$parts[0]])) $parts[0] = $aliases[$parts[0]];
$class = '\chat\system\command\commands\\'.ucfirst(strtolower($parts[0])).'Command';
if (!class_exists($class)) {
throw new NotFoundException();

View File

@ -44,10 +44,12 @@
<minvalue>1</minvalue>
<maxvalue>5000</maxvalue>
</option>
<option name="chat_show_version">
<option name="chat_command_aliases">
<categoryname>chat.general</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>1</defaultvalue>
<optiontype>textarea</optiontype>
<defaultvalue>afk:away
col:color
msg:whisper</defaultvalue>
</option>
<!-- general chat options end -->

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication>
<version>3.0.0 Alpha 56</version><!-- Codename: Codenames are overrated -->
<version>3.0.0 Alpha 58</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date>
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
</packageinformation>