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

Adding PlainCommand

This commit is contained in:
Tim Düsterhus 2012-02-04 12:32:56 +01:00
parent 64fb4bec06
commit 08a27db4ed
2 changed files with 49 additions and 3 deletions

View File

@ -11,9 +11,9 @@
* @package timwolla.wcf.chat * @package timwolla.wcf.chat
* @subpackage system.chat.commands * @subpackage system.chat.commands
*/ */
class CommandHandler { final class CommandHandler {
const COMMAND_CHAR = '/'; const COMMAND_CHAR = '/';
public $text = ''; private $text = '';
/** /**
* Initialises the CommandHandler * Initialises the CommandHandler
@ -32,6 +32,15 @@ public function isCommand($text = null) {
return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR;
} }
/**
* Returns the whole message.
*
* @return string
*/
public function getText() {
return $this->text;
}
/** /**
* Returns the parameter-string. * Returns the parameter-string.
* *
@ -40,6 +49,7 @@ public function isCommand($text = null) {
public function getParameters() { public function getParameters() {
$parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2);
if (!isset($parts[1])) return '';
return $parts[1]; return $parts[1];
} }
@ -50,7 +60,7 @@ public function loadCommand() {
$parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2);
if ($this->isCommand($parts[0])) { if ($this->isCommand($parts[0])) {
return new commands\commands\PlainCommand($this); return new commands\Plain($this);
} }
$class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]); $class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]);

View File

@ -0,0 +1,36 @@
<?php
namespace wcf\system\chat\commands\commands;
/**
* Sends a message that starts with a slash.
*
* @author Tim Düsterhus
* @copyright 2010-2012 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package timwolla.wcf.chat
* @subpackage system.chat.commands.commands
*/
class Plain extends \wcf\system\chat\commands\AbstractCommand {
public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_USER;
/**
* @see \wcf\system\chat\commands\ICommand::getType()
*/
public function getType() {
return \wcf\data\chat\message\ChatMessage::TYPE_NORMAL;
}
/**
* @see \wcf\system\chat\commands\ICommand::getMessage()
*/
public function getMessage() {
return \wcf\util\StringUtil::substring($this->commandHandler->getText(), 1);
}
/**
* @see \wcf\system\chat\commands\ICommand::getReceiver()
*/
public function getReceiver() {
return null;
}
}