mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Merge branch 'master' into suspensionList
Conflicts: package.xml
This commit is contained in:
commit
4abb837878
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -136,7 +136,7 @@
|
||||
> .chatSidebarMenu {
|
||||
background: @wcfContentBackgroundColor;
|
||||
margin: -14px 0 0;
|
||||
.borderRadius(0);
|
||||
border-radius: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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 -->
|
||||
|
||||
|
@ -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>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<dt>{lang}chat.general.copyright.leader{/lang}</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><a href="http://tims.bastelstu.be/">Tim Düsterhus</a></li>
|
||||
<li><a href="http://tims.bastelstu.be/"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>Tim Dü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ü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ü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>
|
||||
|
Loading…
Reference in New Issue
Block a user