diff --git a/file/lib/data/message/MessageAction.class.php b/file/lib/data/message/MessageAction.class.php index 128d389..4c6f0e7 100644 --- a/file/lib/data/message/MessageAction.class.php +++ b/file/lib/data/message/MessageAction.class.php @@ -125,6 +125,9 @@ public function validateSend() { catch (\chat\system\command\UserNotFoundException $e) { throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.userNotFound', array('exception' => $e))); } + catch (\InvalidArgumentException $e) { + throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.invalidArgument', array('exception' => $e))); + } } else { $this->parameters['type'] = Message::TYPE_NORMAL; diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index e55376d..e5ed79e 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -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); } /** diff --git a/file/lib/system/command/CommandHandler.class.php b/file/lib/system/command/CommandHandler.class.php index d8a60c6..c575e62 100644 --- a/file/lib/system/command/CommandHandler.class.php +++ b/file/lib/system/command/CommandHandler.class.php @@ -14,19 +14,19 @@ final class CommandHandler { /** * char that indicates a command - * @var string + * @var string */ const COMMAND_CHAR = '/'; /** * message text - * @var string + * @var string */ private $text = ''; /** * current room - * @var \chat\data\room\Room + * @var \chat\data\room\Room */ private $room = null; @@ -39,6 +39,29 @@ final class CommandHandler { public function __construct($text, \chat\data\room\Room $room = null) { $this->text = $text; $this->room = $room; + + $aliases = self::getAliasMap(); + foreach ($aliases as $search => $replace) { + $this->text = \wcf\system\Regex::compile('^'.preg_quote(self::COMMAND_CHAR.$search).'( |$)')->replace($this->text, self::COMMAND_CHAR.$replace.' '); + } + + $this->text = \wcf\system\Regex::compile('^//')->replace($this->text, '/plain '); + } + + /** + * Returns the alias map. Key is the alias, value is the target. + * + * @return array + */ + 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; } /** @@ -86,13 +109,9 @@ public function getParameters() { public function loadCommand() { $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); - if ($this->isCommand($parts[0])) { - return new commands\PlainCommand($this); - } - $class = '\chat\system\command\commands\\'.ucfirst(strtolower($parts[0])).'Command'; if (!class_exists($class)) { - throw new NotFoundException(); + throw new NotFoundException($parts[0]); } return new $class($this); diff --git a/file/lib/system/command/NotFoundException.class.php b/file/lib/system/command/NotFoundException.class.php index 55cd1c2..18b7c5a 100644 --- a/file/lib/system/command/NotFoundException.class.php +++ b/file/lib/system/command/NotFoundException.class.php @@ -10,4 +10,23 @@ * @package be.bastelstu.chat * @subpackage system.chat.command */ -class NotFoundException extends \Exception { } +class NotFoundException extends \Exception { + /** + * given command + * @var string + */ + private $command = ''; + + public function __construct($command) { + $this->command = $command; + } + + /** + * Returns the given command + * + * @return string + */ + public function getCommand() { + return $this->command; + } +} diff --git a/file/lib/system/command/commands/ColorCommand.class.php b/file/lib/system/command/commands/ColorCommand.class.php index 16fada1..f8263a1 100644 --- a/file/lib/system/command/commands/ColorCommand.class.php +++ b/file/lib/system/command/commands/ColorCommand.class.php @@ -55,7 +55,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) foreach ($color as $key => $val) { if (isset(self::$colors[$val])) $color[$key] = self::$colors[$val]; else { - if (!$regex->match($val)) throw new \chat\system\command\NotFoundException(); + if (!$regex->match($val)) throw new \InvalidArgumentException(); $matches = $regex->getMatches(); $val = $matches[1]; diff --git a/file/lib/system/command/commands/FreeCommand.class.php b/file/lib/system/command/commands/FreeCommand.class.php index 833473f..6297d8f 100644 --- a/file/lib/system/command/commands/FreeCommand.class.php +++ b/file/lib/system/command/commands/FreeCommand.class.php @@ -15,7 +15,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) parent::__construct($commandHandler); if (\wcf\util\StringUtil::toLowerCase($this->commandHandler->getParameters()) != 'the fish') { - throw new \chat\system\command\NotFoundException(); + throw new \InvalidArgumentException(); } $this->didInit(); diff --git a/file/lib/system/command/commands/MuteCommand.class.php b/file/lib/system/command/commands/MuteCommand.class.php index 4c8371d..5cb252f 100644 --- a/file/lib/system/command/commands/MuteCommand.class.php +++ b/file/lib/system/command/commands/MuteCommand.class.php @@ -39,7 +39,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) $this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF); } catch (\wcf\system\exception\SystemException $e) { - throw new \chat\system\command\NotFoundException(); + throw new \InvalidArgumentException(); } $this->user = User::getUserByUsername($username); diff --git a/file/lib/system/command/commands/PlainCommand.class.php b/file/lib/system/command/commands/PlainCommand.class.php index 81913eb..0c08093 100644 --- a/file/lib/system/command/commands/PlainCommand.class.php +++ b/file/lib/system/command/commands/PlainCommand.class.php @@ -24,7 +24,7 @@ public function getType() { * @see \chat\system\command\ICommand::getMessage() */ public function getMessage() { - return \wcf\system\bbcode\PreParser::getInstance()->parse(\wcf\util\StringUtil::substring($this->commandHandler->getText(), 1), explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes'))); + return \wcf\system\bbcode\PreParser::getInstance()->parse(\chat\system\command\CommandHandler::COMMAND_CHAR.$this->commandHandler->getParameters(), explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes'))); } /** diff --git a/file/lib/system/command/commands/WhisperCommand.class.php b/file/lib/system/command/commands/WhisperCommand.class.php index 04333c5..38faa18 100644 --- a/file/lib/system/command/commands/WhisperCommand.class.php +++ b/file/lib/system/command/commands/WhisperCommand.class.php @@ -26,7 +26,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) $this->message = \wcf\util\StringUtil::trim($message); } catch (\wcf\system\exception\SystemException $e) { - throw new \chat\system\command\NotFoundException(); + throw new \InvalidArgumentException(); } $this->user = User::getUserByUsername($username); diff --git a/file/style/be.bastelstu.wcf.chat.less b/file/style/be.bastelstu.wcf.chat.less index 0d6c12f..86ebcb7 100644 --- a/file/style/be.bastelstu.wcf.chat.less +++ b/file/style/be.bastelstu.wcf.chat.less @@ -136,7 +136,7 @@ > .chatSidebarMenu { background: @wcfContentBackgroundColor; margin: -14px 0 0; - .borderRadius(0); + border-radius: 0px; } } } diff --git a/language/de.xml b/language/de.xml index df5d9a8..a57bf1a 100644 --- a/language/de.xml +++ b/language/de.xml @@ -108,7 +108,7 @@ - + type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]> diff --git a/option.xml b/option.xml index 29a6eff..bef3647 100644 --- a/option.xml +++ b/option.xml @@ -44,10 +44,12 @@ 1 5000 - diff --git a/package.xml b/package.xml index 9417b3c..961162b 100644 --- a/package.xml +++ b/package.xml @@ -7,6 +7,7 @@ 1 3.0.0 Alpha 59 2011-11-26 + ]]> diff --git a/template/__copyright.tpl b/template/__copyright.tpl index 3cf1757..cf12ef3 100644 --- a/template/__copyright.tpl +++ b/template/__copyright.tpl @@ -6,7 +6,7 @@
{lang}chat.general.copyright.leader{/lang}
@@ -14,8 +14,8 @@
{lang}chat.general.copyright.developer{/lang}
@@ -23,7 +23,7 @@
{lang}chat.general.copyright.graphics{/lang}
@@ -37,10 +37,10 @@
{lang}chat.general.copyright.thanks{/lang}