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

Merge branch 'master' into suspensionList

Conflicts:
	package.xml
This commit is contained in:
Tim Düsterhus 2013-06-22 14:41:40 +02:00
commit 4abb837878
14 changed files with 74 additions and 27 deletions

View File

@ -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;

View File

@ -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);
}
/**

View File

@ -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<string>
*/
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);

View File

@ -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;
}
}

View File

@ -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];

View File

@ -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();

View File

@ -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);

View File

@ -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')));
}
/**

View File

@ -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);

View File

@ -136,7 +136,7 @@
> .chatSidebarMenu {
background: @wcfContentBackgroundColor;
margin: -14px 0 0;
.borderRadius(0);
border-radius: 0px;
}
}
}

View File

@ -108,7 +108,7 @@
<item name="chat.general.profile"><![CDATA[Profil]]></item>
<item name="chat.general.information"><![CDATA[Information]]></item>
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte laden Sie die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
<item name="chat.general.information.suspension"><![CDATA[{lang}chat.suspension.{$suspension->type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]></item>
</category>

View File

@ -44,10 +44,12 @@
<minvalue>1</minvalue>
<maxvalue>5000</maxvalue>
</option>
<option name="chat_show_version">
<option name="chat_command_aliases">
<categoryname>chat.general</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>1</defaultvalue>
<optiontype>textarea</optiontype>
<defaultvalue>afk:away
col:color
msg:whisper</defaultvalue>
</option>
<!-- general chat options end -->

View File

@ -7,6 +7,7 @@
<isapplication>1</isapplication>
<version>3.0.0 Alpha 59</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date>
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
</packageinformation>
<authorinformation>

View File

@ -6,7 +6,7 @@
<dt>{lang}chat.general.copyright.leader{/lang}</dt>
<dd>
<ul>
<li><a href="http://tims.bastelstu.be/">Tim D&uuml;sterhus</a></li>
<li><a href="http://tims.bastelstu.be/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tim D&uuml;sterhus</a></li>
</ul>
</dd>
</dl>
@ -14,8 +14,8 @@
<dt>{lang}chat.general.copyright.developer{/lang}</dt>
<dd>
<ul>
<li><a href="http://tims.bastelstu.be/">Tim D&uuml;sterhus</a></li>
<li><a href="https://github.com/max-m">Maximilian Mader</a></li>
<li><a href="http://tims.bastelstu.be/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tim D&uuml;sterhus</a></li>
<li><a href="https://github.com/max-m"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Maximilian Mader</a></li>
</ul>
</dd>
</dl>
@ -23,7 +23,7 @@
<dt>{lang}chat.general.copyright.graphics{/lang}</dt>
<dd>
<ul>
<li><a href="http://www.cls-design.com/">Tom</a></li>
<li><a href="http://www.cls-design.com/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tom</a></li>
</ul>
</dd>
</dl>
@ -37,10 +37,10 @@
<dt>{lang}chat.general.copyright.thanks{/lang}</dt>
<dd>
<ul>
<li><a href="http://www.wbbaddons.de/user/2020-noone/">-noone-</a></li>
<li><a href="https://github.com/Gabbid">Gabi</a></li>
<li><a href="https://github.com/Leon-">Stefan Hahn</a></li>
<li><a href="http://www.wbbaddons.de">Martin Schwendowius</a></li>
<li><a href="http://www.wbbaddons.de/user/2020-noone/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>-noone-</a></li>
<li><a href="https://github.com/Gabbid"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Gabi</a></li>
<li><a href="https://github.com/Leon-"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Stefan Hahn</a></li>
<li><a href="http://www.wbbaddons.de"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Martin Schwendowius</a></li>
</ul>
</dd>
</dl>