mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Improve time intervals for commands
This commit is contained in:
parent
1cf7ad6f74
commit
f570e9d1a6
@ -40,7 +40,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
parent::__construct($commandHandler);
|
||||
|
||||
try {
|
||||
list($color[1], $color[2]) = explode(' ', $commandHandler->getParameters());
|
||||
list($color[1], $color[2]) = explode(' ', $commandHandler->getParameters(), 2);
|
||||
}
|
||||
catch (\wcf\system\exception\SystemException $e) {
|
||||
$color[1] = $color[2] = $commandHandler->getParameters();
|
||||
|
@ -24,12 +24,13 @@ class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
|
||||
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
|
||||
parent::__construct($commandHandler);
|
||||
|
||||
$parameters = $commandHandler->getParameters();
|
||||
if (($comma = strpos($parameters, ',')) !== false) {
|
||||
$username = substr($parameters, 0, $comma);
|
||||
$this->time = ChatUtil::timeModifier(substr($parameters, $comma + 1));
|
||||
try {
|
||||
list($username, $modifier) = explode(',', $commandHandler->getParameters(), 2);
|
||||
$modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier));
|
||||
$this->time = strtotime($modifier, TIME_NOW);
|
||||
$this->time = min(max(-0x80000000, $this->time), 0x7FFFFFFF);
|
||||
}
|
||||
else {
|
||||
catch (\wcf\system\exception\SystemException $e) {
|
||||
throw new \chat\system\command\NotFoundException();
|
||||
}
|
||||
|
||||
@ -48,7 +49,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
|
||||
public function executeAction() {
|
||||
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) {
|
||||
if ($suspension->time > TIME_NOW + $this->time) {
|
||||
if ($suspension->time > $this->time) {
|
||||
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
|
||||
}
|
||||
|
||||
@ -61,7 +62,7 @@ public function executeAction() {
|
||||
'userID' => $this->user->userID,
|
||||
'roomID' => ChatUtil::readUserData('roomID'),
|
||||
'type' => suspension\Suspension::TYPE_MUTE,
|
||||
'time' => TIME_NOW + $this->time
|
||||
'time' => $this->time
|
||||
)
|
||||
));
|
||||
$this->suspensionAction->executeAction();
|
||||
@ -91,7 +92,7 @@ public function getType() {
|
||||
public function getMessage() {
|
||||
return serialize(array(
|
||||
'link' => $this->link,
|
||||
'until' => TIME_NOW + $this->time,
|
||||
'until' => $this->time,
|
||||
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this)))
|
||||
));
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
$username = substr($parameters, 0, $comma);
|
||||
$this->message = substr($parameters, $comma + 1);
|
||||
}
|
||||
else throw new \chat\system\command\NotFoundException();
|
||||
else {
|
||||
throw new \chat\system\command\NotFoundException();
|
||||
}
|
||||
|
||||
$this->user = User::getUserByUsername($username);
|
||||
if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username);
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
namespace chat\system\option;
|
||||
|
||||
/**
|
||||
* TimeIntervalOptionType is an implementation of IOptionType for time intervals.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @copyright 2010-2013 Tim Düsterhus
|
||||
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||
* @package be.bastelstu.chat
|
||||
* @subpackage system.option
|
||||
*/
|
||||
class TimeIntervalOptionType extends \wcf\system\option\TextOptionType {
|
||||
/**
|
||||
* @see \wcf\system\option\IOptionType::getData()
|
||||
*/
|
||||
public function getData(\wcf\data\option\Option $option, $newValue) {
|
||||
return \chat\util\ChatUtil::timeModifier($newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\option\TextOptionType::getFormElement()
|
||||
*/
|
||||
public function getFormElement(\wcf\data\option\Option $option, $value) {
|
||||
$tmp = '';
|
||||
if ($value > 86400) {
|
||||
$tmp = floor($value / 86400).'d';
|
||||
$value -= floor($value / 86400) * 86400;
|
||||
}
|
||||
if ($value > 3600) {
|
||||
$tmp .= floor($value / 3600).'h';
|
||||
$value -= floor($value / 3600) * 3600;
|
||||
}
|
||||
$tmp .= floor($value / 60);
|
||||
if ($value % 60 != 0) {
|
||||
$tmp .= ','.($value % 60).'s';
|
||||
}
|
||||
|
||||
return parent::getFormElement($option, $tmp);
|
||||
}
|
||||
}
|
@ -127,6 +127,7 @@ public static function readUserData($field, \wcf\data\user\User $user = null) {
|
||||
|
||||
/**
|
||||
* Writes user data
|
||||
*
|
||||
* @param array $data
|
||||
* @param \wcf\data\user\User $user
|
||||
*/
|
||||
@ -166,50 +167,45 @@ public static function str_split($string, $length = 1) {
|
||||
* @return integer
|
||||
*/
|
||||
public static function timeModifier($time) {
|
||||
$regex = new \wcf\system\Regex('([0-9]+[s|h|d|w|m|y]?)', \wcf\system\Regex::CASE_INSENSITIVE);
|
||||
if (!$regex->match($time, true)) return 0;
|
||||
$regex = new \wcf\system\Regex('([0-9]+)([shdwmy]?)', \wcf\system\Regex::CASE_INSENSITIVE);
|
||||
if (!$regex->match($time, true, \wcf\system\Regex::ORDER_MATCH_BY_SET)) return 0;
|
||||
$matches = $regex->getMatches();
|
||||
|
||||
$result = 0;
|
||||
foreach ($matches[1] as $time) {
|
||||
// 60 seconds a minute
|
||||
$multiplier = 60;
|
||||
$modifier = substr($time, -1);
|
||||
$result = '';
|
||||
foreach ($matches as $match) {
|
||||
list(, $time, $modifier) = $match;
|
||||
|
||||
switch ($modifier) {
|
||||
case 'y':
|
||||
case 'Y':
|
||||
// twelve months a year
|
||||
$multiplier *= 12;
|
||||
$result .= '+'.$time.'year';
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
// about 4.3 weeks per month
|
||||
$multiplier *= 4.34812141;
|
||||
$result .= '+'.$time.'month';
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
// seven days a weeks
|
||||
$multiplier *= 7;
|
||||
$result .= '+'.$time.'week';
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
// 24 hours a day
|
||||
$multiplier *= 24;
|
||||
$result .= '+'.$time.'day';
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
// 60 minutes an hour
|
||||
$multiplier *= 60;
|
||||
$time = substr($time, 0, -1);
|
||||
$result .= '+'.$time.'hour';
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
// 60 seconds per minute
|
||||
$multiplier /= 60;
|
||||
$time = substr($time, 0, -1);
|
||||
$result .= '+'.$time.'second';
|
||||
break;
|
||||
default:
|
||||
$result .= '+'.$time.'minute';
|
||||
}
|
||||
|
||||
$result += $time * $multiplier;
|
||||
}
|
||||
|
||||
return (int) round($result, 0);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,18 +37,17 @@
|
||||
<item name="wcf.acp.option.category.chat.general"><![CDATA[Allgemein]]></item>
|
||||
<item name="wcf.acp.option.chat_active"><![CDATA[Chat aktivieren]]></item>
|
||||
<item name="wcf.acp.option.chat_reloadtime"><![CDATA[Nachladezeit]]></item>
|
||||
<item name="wcf.acp.option.chat_reloadtime.description"><![CDATA[Gibt die Zeit in Sekunden an, nach der neue Nachrichten geladen werden. (Standard: alle 5 Sekunden)]]></item>
|
||||
<item name="wcf.acp.option.chat_reloadtime.description"><![CDATA[Wartezeit zwischen zwei Anfragen zum Server. [Zeit in Sekunden]]]></item>
|
||||
<item name="wcf.acp.option.chat_lastmessages"><![CDATA[Anzahl der letzten Nachrichten]]></item>
|
||||
<item name="wcf.acp.option.chat_lastmessages.description"><![CDATA[Gibt die Zahl der Nachrichten an, die beim Betreten des Chats angezeigt werden. (Standard: 5)]]></item>
|
||||
<item name="wcf.acp.option.chat_lastmessages.description"><![CDATA[Anzahl der Nachrichten, die beim Betreten des Chats angezeigt werden.]]></item>
|
||||
<item name="wcf.acp.option.chat_display_join_leave"><![CDATA[Join- und Leave-Nachrichten anzeigen]]></item>
|
||||
<item name="wcf.acp.option.chat_display_join_leave.description"><![CDATA[Gibt an, ob eine Nachricht angezeigt werden soll, wenn ein Nutzer den Chat betritt oder verlässt.]]></item>
|
||||
<item name="wcf.acp.option.chat_display_join_leave.description"><![CDATA[Soll eine Nachricht angezeigt werden, wenn ein Nutzer den Chat betritt oder verlässt?]]></item>
|
||||
<item name="wcf.acp.option.chat_max_length"><![CDATA[Maximale Textlänge]]></item>
|
||||
<item name="wcf.acp.option.chat_max_length.description"><![CDATA[Gibt die maximale Länge einer Chatnachricht an.]]></item>
|
||||
|
||||
<item name="wcf.acp.option.category.chat.log"><![CDATA[Protokoll]]></item>
|
||||
<item name="wcf.acp.option.chat_log_active"><![CDATA[Protokoll aktivieren]]></item>
|
||||
<item name="wcf.acp.option.chat_log_archivetime"><![CDATA[Speicherzeit]]></item>
|
||||
<item name="wcf.acp.option.chat_log_archivetime.description"><![CDATA[Gibt die Zeit in Minuten an, die eine Nachricht im Protokoll gespeichert bleibt.]]></item>
|
||||
<item name="wcf.acp.option.chat_log_archivetime.description"><![CDATA[Zeit, die eine Nachricht im Protokoll abrufbar bleibt. [Zeit in Minuten, -1 für unendlich]]]></item>
|
||||
</category>
|
||||
|
||||
<category name="chat.error">
|
||||
|
11
option.xml
11
option.xml
@ -23,12 +23,16 @@
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>integer</optiontype>
|
||||
<defaultvalue>5</defaultvalue>
|
||||
<minvalue>1</minvalue>
|
||||
<maxvalue>15</maxvalue>
|
||||
<showorder>2</showorder>
|
||||
</option>
|
||||
<option name="chat_lastmessages">
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>integer</optiontype>
|
||||
<defaultvalue>5</defaultvalue>
|
||||
<minvalue>0</minvalue>
|
||||
<maxvalue>50</maxvalue>
|
||||
<showorder>4</showorder>
|
||||
</option>
|
||||
<option name="chat_display_join_leave">
|
||||
@ -41,6 +45,8 @@
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>integer</optiontype>
|
||||
<defaultvalue>500</defaultvalue>
|
||||
<minvalue>1</minvalue>
|
||||
<maxvalue>5000</maxvalue>
|
||||
<showorder>8</showorder>
|
||||
</option>
|
||||
<option name="chat_show_version">
|
||||
@ -60,8 +66,9 @@
|
||||
</option>
|
||||
<option name="chat_log_archivetime">
|
||||
<categoryname>chat.log</categoryname>
|
||||
<optiontype>timeInterval</optiontype>
|
||||
<defaultvalue>172800</defaultvalue>
|
||||
<optiontype>integer</optiontype>
|
||||
<defaultvalue>10080</defaultvalue>
|
||||
<minvalue>-1</minvalue>
|
||||
<showorder>2</showorder>
|
||||
</option>
|
||||
<!--log options end-->
|
||||
|
Loading…
Reference in New Issue
Block a user