mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Add MuteCommand and BanCommand
This commit is contained in:
parent
539dcb2a4e
commit
963203224d
@ -65,6 +65,12 @@ window.console ?=
|
|||||||
fish: null
|
fish: null
|
||||||
init: (@config, @titleTemplate, @messageTemplate) ->
|
init: (@config, @titleTemplate, @messageTemplate) ->
|
||||||
console.log 'Initializing'
|
console.log 'Initializing'
|
||||||
|
|
||||||
|
@events =
|
||||||
|
newMessage: $.Callbacks()
|
||||||
|
userMenu: $.Callbacks()
|
||||||
|
submit: $.Callbacks()
|
||||||
|
|
||||||
@bindEvents()
|
@bindEvents()
|
||||||
@events.newMessage.add $.proxy @notify, @
|
@events.newMessage.add $.proxy @notify, @
|
||||||
|
|
||||||
@ -186,11 +192,11 @@ window.console ?=
|
|||||||
icon = element.find 'img'
|
icon = element.find 'img'
|
||||||
if element.data('status') is 1
|
if element.data('status') is 1
|
||||||
element.data 'status', 0
|
element.data 'status', 0
|
||||||
icon.attr 'src', icon.attr('src').replace /enabled(Inverse)?.([a-z]{3})$/, 'disabled$1.$2'
|
icon.attr 'src', icon.attr('src').replace /enabled(.*).svg$/, 'disabled$1.svg'
|
||||||
element.attr 'title', element.data 'enableMessage'
|
element.attr 'title', element.data 'enableMessage'
|
||||||
else
|
else
|
||||||
element.data 'status', 1
|
element.data 'status', 1
|
||||||
icon.attr 'src', icon.attr('src').replace /disabled(Inverse)?.([a-z]{3})$/, 'enabled$1.$2'
|
icon.attr 'src', icon.attr('src').replace /disabled(.*).svg$/, 'enabled$1.svg'
|
||||||
element.attr 'title', element.data 'disableMessage'
|
element.attr 'title', element.data 'disableMessage'
|
||||||
|
|
||||||
$('#timsChatInput').focus()
|
$('#timsChatInput').focus()
|
||||||
|
39
file/lib/system/chat/command/commands/BanCommand.class.php
Normal file
39
file/lib/system/chat/command/commands/BanCommand.class.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
namespace wcf\system\chat\command\commands;
|
||||||
|
use \wcf\data\chat\suspension;
|
||||||
|
use \wcf\data\user\User;
|
||||||
|
use \wcf\system\WCF;
|
||||||
|
use \wcf\util\ChatUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bans a user.
|
||||||
|
*
|
||||||
|
* @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 BanCommand extends MuteCommand {
|
||||||
|
public function executeAction() {
|
||||||
|
if ($suspension = suspension\ChatSuspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\ChatSuspension::TYPE_BAN)) {
|
||||||
|
if ($suspension->time > TIME_NOW + $this->time) {
|
||||||
|
$this->fail = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = new suspension\ChatSuspensionEditor($suspension);
|
||||||
|
$editor->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->suspensionAction = new suspension\ChatSuspensionAction(array(), 'create', array(
|
||||||
|
'data' => array(
|
||||||
|
'userID' => $this->user->userID,
|
||||||
|
'roomID' => ChatUtil::readUserData('roomID'),
|
||||||
|
'type' => suspension\ChatSuspension::TYPE_BAN,
|
||||||
|
'time' => TIME_NOW + $this->time
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->suspensionAction->executeAction();
|
||||||
|
}
|
||||||
|
}
|
113
file/lib/system/chat/command/commands/MuteCommand.class.php
Normal file
113
file/lib/system/chat/command/commands/MuteCommand.class.php
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
namespace wcf\system\chat\command\commands;
|
||||||
|
use \wcf\data\chat\suspension;
|
||||||
|
use \wcf\data\user\User;
|
||||||
|
use \wcf\system\WCF;
|
||||||
|
use \wcf\util\ChatUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mutes a user.
|
||||||
|
*
|
||||||
|
* @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 MuteCommand extends \wcf\system\chat\command\AbstractRestrictedCommand {
|
||||||
|
public $user = null;
|
||||||
|
public $time = 0;
|
||||||
|
public $suspensionAction = null;
|
||||||
|
public $link = '';
|
||||||
|
public $fail = false;
|
||||||
|
public $room = null;
|
||||||
|
|
||||||
|
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->time = ChatUtil::timeModifier(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);
|
||||||
|
|
||||||
|
$color = ChatUtil::readUserData('color', $this->user);
|
||||||
|
$profile = \wcf\system\request\LinkHandler::getInstance()->getLink('User', array(
|
||||||
|
'object' => $this->user
|
||||||
|
));
|
||||||
|
$this->link = '<span class="userLink" data-user-id="'.$this->user->userID.'" />';
|
||||||
|
|
||||||
|
$this->executeAction();
|
||||||
|
|
||||||
|
$this->didInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function executeAction() {
|
||||||
|
if ($suspension = suspension\ChatSuspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\ChatSuspension::TYPE_MUTE)) {
|
||||||
|
if ($suspension->time > TIME_NOW + $this->time) {
|
||||||
|
$this->fail = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = new suspension\ChatSuspensionEditor($suspension);
|
||||||
|
$editor->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->suspensionAction = new suspension\ChatSuspensionAction(array(), 'create', array(
|
||||||
|
'data' => array(
|
||||||
|
'userID' => $this->user->userID,
|
||||||
|
'roomID' => ChatUtil::readUserData('roomID'),
|
||||||
|
'type' => suspension\ChatSuspension::TYPE_MUTE,
|
||||||
|
'time' => TIME_NOW + $this->time
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->suspensionAction->executeAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \wcf\system\chat\command\IRestrictedChatCommand::checkPermission()
|
||||||
|
*/
|
||||||
|
public function checkPermission() {
|
||||||
|
parent::checkPermission();
|
||||||
|
|
||||||
|
$this->room = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->request->room;
|
||||||
|
$ph = new \wcf\system\chat\permission\ChatPermissionHandler();
|
||||||
|
if (!$ph->getPermission($this->room, 'mod.can'.str_replace(array('wcf\system\chat\command\commands\\', 'Command'), '', get_class($this)))) throw new \wcf\system\exception\PermissionDeniedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see wcf\system\chat\command\ICommand::getReceiver()
|
||||||
|
*/
|
||||||
|
public function getReceiver() {
|
||||||
|
if ($this->fail) return WCF::getUser()->userID;
|
||||||
|
|
||||||
|
return parent::getReceiver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \wcf\system\chat\command\ICommand::getType()
|
||||||
|
*/
|
||||||
|
public function getType() {
|
||||||
|
if ($this->fail) return \wcf\data\chat\message\ChatMessage::TYPE_INFORMATION;
|
||||||
|
return \wcf\data\chat\message\ChatMessage::TYPE_MODERATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \wcf\system\chat\command\ICommand::getMessage()
|
||||||
|
*/
|
||||||
|
public function getMessage() {
|
||||||
|
if ($this->fail) return WCF::getLanguage()->get('wcf.chat.suspension.exists');
|
||||||
|
|
||||||
|
return serialize(array(
|
||||||
|
'link' => $this->link,
|
||||||
|
'until' => TIME_NOW + $this->time,
|
||||||
|
'type' => str_replace(array('wcf\system\chat\command\commands\\', 'command'), '', strtolower(get_class($this)))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -108,6 +108,7 @@ Hinweis: Setzen Sie diese Einstellung nur, wenn Sie wissen, was sie bewirkt. Die
|
|||||||
<!-- 5 = TYPE_MODERATE -->
|
<!-- 5 = TYPE_MODERATE -->
|
||||||
<item name="wcf.chat.message.5.restore"><![CDATA[hat {@$link} zurückgesetzt.]]></item>
|
<item name="wcf.chat.message.5.restore"><![CDATA[hat {@$link} zurückgesetzt.]]></item>
|
||||||
<item name="wcf.chat.message.5.mute"><![CDATA[hat {@$link} bis {@$until|plainTime} geknebelt.]]></item>
|
<item name="wcf.chat.message.5.mute"><![CDATA[hat {@$link} bis {@$until|plainTime} geknebelt.]]></item>
|
||||||
|
<item name="wcf.chat.message.5.ban"><![CDATA[hat {@$link} bis {@$until|plainTime} gebannt.]]></item>
|
||||||
|
|
||||||
<!-- 7 = TYPE_WHISPER -->
|
<!-- 7 = TYPE_WHISPER -->
|
||||||
<item name="wcf.chat.message.7"><![CDATA[flüstert{if $showReceiver} an {$username}{/if}:]]></item>
|
<item name="wcf.chat.message.7"><![CDATA[flüstert{if $showReceiver} an {$username}{/if}:]]></item>
|
||||||
|
Loading…
Reference in New Issue
Block a user