/** * Checks whether given message is an admin command and executes it if so. * * @param WiseChatUser $user * @param WiseChatUser $systemUser * @param WiseChatChannel $channel Name of the channel * @param string $message Content of the possible command * * @return boolean True if the message is processed and is not needed to be displayed */ public function resolve($user, $systemUser, $channel, $message) { if ($this->isPotentialCommand($message) && $this->usersDAO->isWpUserAdminLogged()) { // print typed command (visible only for admins): $this->messagesService->addMessage($user, $channel, $message, true); // execute command: $resolver = $this->getCommandResolver($channel, $message); if ($resolver !== null) { $resolver->execute(); } else { $this->messagesService->addMessage($systemUser, $channel, 'Command not found', true); } return true; } return false; }
/** * Endpoint for banning users by message ID. */ public function userBanEndpoint() { $this->verifyCheckSum(); $response = array(); try { $this->checkChatOpen(); $this->checkUserAuthentication(); $this->checkUserRight('ban_user'); $this->checkPostParams(array('channelId', 'messageId')); $channelId = trim($this->getPostParam('channelId')); $messageId = trim($this->getPostParam('messageId')); $channel = $this->channelsDAO->get($channelId); $this->checkChannel($channel); $this->checkChannelAuthorization($channel); $duration = $this->options->getIntegerOption('moderation_ban_duration', 1440); $this->bansService->banByMessageId($messageId, $channel, $duration . 'm'); $this->messagesService->addMessage($this->authentication->getSystemUser(), $channel, "User has been banned for {$duration} minutes", true); $response['result'] = 'OK'; } catch (WiseChatUnauthorizedAccessException $exception) { $response['error'] = $exception->getMessage(); $this->sendUnauthorizedStatus(); } catch (Exception $exception) { $response['error'] = $exception->getMessage(); $this->sendBadRequestStatus(); } echo json_encode($response); die; }
protected function addMessage($message) { $this->messagesService->addMessage($this->authentication->getSystemUser(), $this->channel, $message, true); }