Fixed uppercase file names
This commit is contained in:
130
application/core/Chat.php
Normal file
130
application/core/Chat.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Chat utility class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class Chat {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_PREFIX = 'Messages Prefix';
|
||||
const SETTING_FORMAT_INFORMATION = 'Information Format';
|
||||
const SETTING_FORMAT_SUCCESS = 'Success Format';
|
||||
const SETTING_FORMAT_ERROR = 'Error Format';
|
||||
const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct chat utility
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_PREFIX, 'MC» ');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FORMAT_INFORMATION, '$fff');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FORMAT_SUCCESS, '$0f0');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FORMAT_ERROR, '$f00');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FORMAT_USAGEINFO, '$f80');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prefix
|
||||
*
|
||||
* @param string|bool $prefix
|
||||
* @return string
|
||||
*/
|
||||
private function getPrefix($prefix) {
|
||||
if (is_string($prefix)) {
|
||||
return $prefix;
|
||||
}
|
||||
if ($prefix === true) {
|
||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a chat message to the given login
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function sendChat($message, $login = null, $prefix = true) {
|
||||
if (!$this->maniaControl->client) {
|
||||
return false;
|
||||
}
|
||||
$client = $this->maniaControl->client;
|
||||
$chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z';
|
||||
if ($login === null) {
|
||||
return $client->query('ChatSendServerMessage', $chatMessage);
|
||||
}
|
||||
return $client->query('ChatSendServerMessageToLogin', $chatMessage, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an information message to the given login
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function sendInformation($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a success message to the given login
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function sendSuccess($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_SUCCESS);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an error message to the given login
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function sendError($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an usage info message to the given login
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function sendUsageInfo($message, $login = null, $prefix = false) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_USAGEINFO);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user