diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index 9de2527..544a5f0 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -34,6 +34,7 @@ class ChatMessage extends \wcf\data\DatabaseObject { const TYPE_CLEAR = 9; const TYPE_TEAM = 10; const TYPE_GLOBALMESSAGE = 11; + const TYPE_ERROR = 12; /** * @see \wcf\data\chat\message\ChatMessage::getFormattedMessage() diff --git a/file/lib/system/chat/commands/AbstractCommand.class.php b/file/lib/system/chat/commands/AbstractCommand.class.php new file mode 100644 index 0000000..5fd3494 --- /dev/null +++ b/file/lib/system/chat/commands/AbstractCommand.class.php @@ -0,0 +1,22 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +abstract class AbstractCommand implements ICommand { + public $commandHandler = null; + + public function __construct(CommandHandler $commandHandler) { + EventHandler::getInstance()->fireAction($this, 'shouldInit'); + $this->commandHandler = $commandHandler; + EventHandler::getInstance()->fireAction($this, 'didInit'); + } +} diff --git a/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php new file mode 100644 index 0000000..1619dff --- /dev/null +++ b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php @@ -0,0 +1,24 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +abstract class AbstractRestrictedCommand extends AbstractCommand implements IRestrictedCommand { + public function __construct(CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + $this->checkPermission(); + } + + public function checkPermission() { + EventHandler::getInstance()->fireAction($this, 'checkPermission'); + } +} diff --git a/file/lib/system/chat/commands/ChatCommandHandler.class.php b/file/lib/system/chat/commands/ChatCommandHandler.class.php deleted file mode 100644 index 6e24a6a..0000000 --- a/file/lib/system/chat/commands/ChatCommandHandler.class.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @package timwolla.wcf.chat - * @subpackage system.chat.commands - */ -class ChatCommandHandler { - const COMMAND_CHAR = '/'; - - /** - * Checks whether the given text is a command. - * - * @param string $text - * @return boolean - */ - public function isCommand($text) { - return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; - } -} diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php new file mode 100644 index 0000000..56271d5 --- /dev/null +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -0,0 +1,52 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +class CommandHandler { + const COMMAND_CHAR = '/'; + public $text = ''; + + /** + * Initialises the CommandHandler + * + * @param string $text + */ + public function __construct($text) { + $this->text = $text; + } + + /** + * Checks whether the given text is a command. + */ + public function isCommand($text = null) { + if ($text === null) $text = $this->text; + return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; + } + + /** + * Loads the command. + */ + public function loadCommand() { + $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); + + if ($this->isCommand($parts[0])) { + return new \wcf\system\chat\commands\PlainCommand(); + } + + $class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]); + if (!class_exists($class)) { + throw new NotFoundException(); + } + + return new $class($this); + } +} diff --git a/file/lib/system/chat/commands/ICommand.class.php b/file/lib/system/chat/commands/ICommand.class.php new file mode 100644 index 0000000..8cb458d --- /dev/null +++ b/file/lib/system/chat/commands/ICommand.class.php @@ -0,0 +1,20 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +interface ICommand { + const SMILEY_OFF = 0; + const SMILEY_ON = 1; + const SMILEY_USER = 2; + + public function getType(); + public function getMessage(); +} diff --git a/file/lib/system/chat/commands/IRestrictedCommand.class.php b/file/lib/system/chat/commands/IRestrictedCommand.class.php new file mode 100644 index 0000000..285d22d --- /dev/null +++ b/file/lib/system/chat/commands/IRestrictedCommand.class.php @@ -0,0 +1,15 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +interface IRestrictedCommand { + protected function checkPermission(); +} diff --git a/file/lib/system/chat/commands/NotFoundException.class.php b/file/lib/system/chat/commands/NotFoundException.class.php new file mode 100644 index 0000000..f62e63e --- /dev/null +++ b/file/lib/system/chat/commands/NotFoundException.class.php @@ -0,0 +1,13 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +class NotFoundException extends \Exception { } \ No newline at end of file diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php new file mode 100644 index 0000000..a6bfdfe --- /dev/null +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -0,0 +1,23 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Free extends \wcf\system\chat\commands\AbstractCommand { + const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_USER; + + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_ME; + } + + public function getMessage() { + return 'freed the fish'; + } +}