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

Adding WhisperCommand

This commit is contained in:
Tim Düsterhus 2012-09-07 22:58:13 +02:00
parent f777bc1d2e
commit 8e2154c994
2 changed files with 62 additions and 1 deletions

View File

@ -58,9 +58,11 @@ public function getFormattedMessage($outputType = 'text/html') {
WCF::getTPL()->assign(@unserialize($message));
$message = WCF::getLanguage()->getDynamicVariable('wcf.chat.message.'.$this->type);
break;
case self::TYPE_WHISPER:
$message = @unserialize($message);
$message = $message['message'];
case self::TYPE_NORMAL:
case self::TYPE_ME:
case self::TYPE_WHISPER:
if (!$this->enableHTML && $outputType == 'text/html') {
$message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, true, $this->enableSmilies);
}
@ -78,6 +80,10 @@ public function getFormattedUsername() {
$username = $this->getUsername();
if ($this->type != self::TYPE_INFORMATION && $this->type != self::TYPE_ERROR) $username = \wcf\util\ChatUtil::gradient($username, $this->color1, $this->color2);
if ($this->type == self::TYPE_WHISPER) {
$message = @unserialize($this->message);
$username .= ' -> '.$message['username'];
}
return '<strong>'.$username.'</strong>';
}

View File

@ -0,0 +1,55 @@
<?php
namespace wcf\system\chat\command\commands;
use \wcf\data\user\User;
/**
* Whispers a message.
*
* @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 be.bastelstu.wcf.chat
* @subpackage system.chat.command.commands
*/
class WhisperCommand extends \wcf\system\chat\command\AbstractCommand {
public $enableSmilies = \wcf\system\chat\command\ICommand::SMILEY_USER;
public $user = null, $message = '';
public function __construct(\wcf\system\chat\command\CommandHandler $commandHandler) {
parent::__construct($commandHandler);
$parameters = $commandHandler->getParameters();
if (($comma = strpos($parameters, ',')) !== false) {
$username = substr($parameters, 0, $comma);
$this->message = substr($parameters, $comma + 1);
}
else throw new \wcf\system\chat\command\NotFoundException();
$this->user = User::getUserByUsername($username);
if (!$this->user->userID) throw new \wcf\system\chat\command\UserNotFoundException($username);
$this->didInit();
}
/**
* @see \wcf\system\chat\command\ICommand::getType()
*/
public function getType() {
return \wcf\data\chat\message\ChatMessage::TYPE_WHISPER;
}
/**
* @see \wcf\system\chat\command\ICommand::getMessage()
*/
public function getMessage() {
return serialize(array('message' => $this->message, 'username' => $this->user->username));
}
/**
* @see \wcf\system\chat\command\ICommand::getReceiver()
*/
public function getReceiver() {
return $this->user->userID;
}
}