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; if ($command == 'Plain') continue;
$this->commands[] = \wcf\util\StringUtil::toLowerCase($command); $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

@ -14,19 +14,19 @@
final class CommandHandler { final class CommandHandler {
/** /**
* char that indicates a command * char that indicates a command
* @var string * @var string
*/ */
const COMMAND_CHAR = '/'; const COMMAND_CHAR = '/';
/** /**
* message text * message text
* @var string * @var string
*/ */
private $text = ''; private $text = '';
/** /**
* current room * current room
* @var \chat\data\room\Room * @var \chat\data\room\Room
*/ */
private $room = null; private $room = null;
@ -41,6 +41,22 @@ public function __construct($text, \chat\data\room\Room $room = null) {
$this->room = $room; $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. * Checks whether the given text is a command.
*/ */
@ -90,6 +106,9 @@ public function loadCommand() {
return new commands\PlainCommand($this); 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'; $class = '\chat\system\command\commands\\'.ucfirst(strtolower($parts[0])).'Command';
if (!class_exists($class)) { if (!class_exists($class)) {
throw new NotFoundException(); throw new NotFoundException();

View File

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

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription> <packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription> <packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication> <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> <date>2011-11-26</date>
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license> <license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
</packageinformation> </packageinformation>