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

Make commands more flexible

Now aliases like “toRoot:whisper root,” are possible.
This commit is contained in:
Tim Düsterhus 2013-06-17 23:56:28 +02:00
parent 098f048e29
commit 8ccefdb971

View File

@ -39,6 +39,11 @@ final class CommandHandler {
public function __construct($text, \chat\data\room\Room $room = null) { public function __construct($text, \chat\data\room\Room $room = null) {
$this->text = $text; $this->text = $text;
$this->room = $room; $this->room = $room;
$aliases = self::getAliasMap();
foreach ($aliases as $search => $replace) {
$this->text = \wcf\system\Regex::compile('^'.preg_quote($search))->replace($this->text, $replace);
}
} }
/** /**
@ -106,9 +111,6 @@ 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();