本文整理汇总了PHP中Services::getDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Services::getDB方法的具体用法?PHP Services::getDB怎么用?PHP Services::getDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Services
的用法示例。
在下文中一共展示了Services::getDB方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if ($target[0] != '#') {
$target = $messageEx[1];
unset($messageEx[1]);
$messageEx = array_values($messageEx);
}
if (!$this->bot->isRegistered($target)) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.notRegistered'));
}
$access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
if ($access < 500) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
}
$sql = "SELECT\n\t\t\t\tunregistercode\n\t\t\tFROM\n\t\t\t\tchanserv_channels\n\t\t\tWHERE\n\t\t\t\tchannel = '" . escapeString($target) . "'";
$row = Services::getDB()->getFirstRow($sql);
$code = $row['unregistercode'];
if (isset($messageEx[1])) {
if ($code != trim($messageEx[1])) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.codeWrong', $target));
}
// TODO: Validate unregistercode
$this->bot->unregister($target);
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $target));
} else {
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.code', $code));
}
}
示例2: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if ($target[0] != '#') {
$target = $messageEx[1];
unset($messageEx[1]);
$messageEx = array_values($messageEx);
}
$access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
if ($access < $this->bot->getNeededAccess($target, $this->originalName)) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
}
if (count($messageEx) == 1) {
$sql = "SELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tchanserv_channel_accessLevel\n\t\t\t\tWHERE\n\t\t\t\t\tchannel = '" . escapeString($target) . "'\n\t\t\t\tORDER BY \n\t\t\t\t\taccessLevel DESC";
$result = Services::getDB()->sendQuery($sql);
while ($row = Services::getDB()->fetchArray($result)) {
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.' . $row['function']) . ': ' . $row['accessLevel']);
}
} else {
if (count($messageEx) == 3) {
if ($access < $messageEx[2]) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.tooHigh'));
}
if (!$this->bot->getNeededAccess($target, $messageEx[1])) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.unknown'));
}
$sql = "UPDATE\n\t\t\t\t\t\tchanserv_channel_accessLevel\n\t\t\t\t\tSET\n\t\t\t\t\t\taccessLevel = " . $messageEx[2] . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tfunction = '" . escapeString($messageEx[1]) . "'";
Services::getDB()->sendQuery($sql);
} else {
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
}
}
}
示例3: __construct
/**
* Creates a new instance of LanguageManager
*/
public function __construct()
{
$sql = "SELECT\r\n\t\t\t\t\t*\r\n\t\t\t\tFROM\r\n\t\t\t\t\tlanguage";
$result = Services::getDB()->sendQuery($sql);
while ($row = Services::getDB()->fetchArray($result)) {
$this->availableLanguages[] = $row;
$this->items[intval($row['languageID'])] = array();
}
$sql = "SELECT\r\n\t\t\t\t\t*\r\n\t\t\t\tFROM\r\n\t\t\t\t\tlanguage_item";
$result = Services::getDB()->sendQuery($sql);
while ($row = Services::getDB()->fetchArray($result)) {
$this->items[intval($row['languageID'])][$row['name']] = $row['value'];
}
}
示例4: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if ($target[0] != '#') {
$target = $messageEx[1];
unset($messageEx[1]);
$messageEx = array_values($messageEx);
}
if (count($messageEx) == 1) {
$sql = "SELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tchanserv_channels c\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tauthserv_users a\n\t\t\t\t\t\tON\n\t\t\t\t\t\t\tc.registrar = a.userID\n\t\t\t\tWHERE\n\t\t\t\t\tchannel = '" . escapeString($target) . "'";
$row = Services::getDB()->getFirstRow($sql);
$this->bot->sendMessage($user->getUuid(), 'Time: ' . date('d.m.Y H:i:s', $row['time']));
$this->bot->sendMessage($user->getUuid(), 'Registrar: ' . $row['accountname']);
}
}
示例5: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if ($target[0] != '#') {
$target = $messageEx[1];
unset($messageEx[1]);
$messageEx = array_values($messageEx);
}
$access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
if ($access < $this->bot->getNeededAccess($target, 'access')) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
}
if (count($messageEx) == 3) {
if ($messageEx[2] >= $access) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.tooHigh'));
} else {
if ($messageEx[2] > 500) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.tooHigh'));
}
}
if ($access <= $this->bot->getAccess($target, Services::getUserManager()->getUserByNick($messageEx[1])->accountname)) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
}
$authServ = Services::getModuleManager()->lookupModule('AuthServ');
$userID = call_user_func(array($authServ, 'getUserID'), $messageEx[1]);
if (!$userID) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.invalidUser'));
}
if ($messageEx[0] < 1) {
$sql = "DELETE FROM chanserv_channels_to_users WHERE channel = '" . escapeString($target) . "' AND userID = " . $userID;
} else {
$sql = "INSERT INTO chanserv_channels_to_users (channel, userID, accessLevel)\n\t\t\t\t\tVALUES ('" . escapeString($target) . "', " . $userID . ", " . intval($messageEx[2]) . ")\n\t\t\t\t\tON DUPLICATE KEY UPDATE accessLevel = VALUES(accessLevel)";
}
Services::getDB()->sendQuery($sql);
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
} else {
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
}
}
示例6: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if ($target[0] != '#') {
$target = $messageEx[1];
unset($messageEx[1]);
$messageEx = array_values($messageEx);
}
$access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
if ($access < $this->bot->getNeededAccess($target, 'access')) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
}
if (count($messageEx) == 1) {
$sql = "SELECT\n\t\t\t\t\tc.*,\n\t\t\t\t\ta.accountname\n\t\t\t\tFROM\n\t\t\t\t\tchanserv_channels_to_users c\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\tauthserv_users a\n\t\t\t\t\t\tON c.userID = a.userID\n\t\t\t\tWHERE\n\t\t\t\t\tchannel = '" . escapeString($target) . "'\n\t\t\t\tORDER BY \n\t\t\t\t\tc.accessLevel DESC";
$result = Services::getDB()->sendQuery($sql);
while ($row = Services::getDB()->fetchArray($result)) {
$this->bot->sendMessage($user->getUuid(), $row['accountname'] . ': ' . $row['accessLevel']);
}
} else {
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
}
}
示例7: execute
/**
* @see lib/modules/CommandModule::execute()
*/
public function execute($user, $target, $message)
{
// split message
$messageEx = explode(' ', $message);
if (count($messageEx) == 2) {
$password = $messageEx[1];
if (!$this->bot->isAuthed($user->getUuid())) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.notAuthed'));
}
$accountname = Services::getUserManager()->getUser($user->getUuid())->accountname;
if (!$this->bot->checkCredentials($accountname, $password)) {
return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.auth.invalidCredentials'));
}
$userID = $this->bot->getUserID($accountname);
$this->bot->delete($accountname);
// TODO: Kill user to log him out
$sql = "DELETE FROM chanserv_channels_to_users WHERE userID = " . $userID;
Services::getDB()->sendQuery($sql);
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
} else {
// send syntax hint
$this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
}
}
示例8: getAccessLevel
/**
* Returns the access level of $accountname
*
* @param string $accountname
* @return integer
*/
public static function getAccessLevel($accountname)
{
$sql = "SELECT\n\t\t\t\t\taccessLevel\n\t\t\t\tFROM\n\t\t\t\t\tauthserv_users\n\t\t\t\tWHERE\n\t\t\t\t\taccountname = '" . escapeString($accountname) . "'";
$row = Services::getDB()->getFirstRow($sql);
// workaround ...
if (!Services::getDB()->getNumRows()) {
return 0;
}
return intval($row['accessLevel']);
}
示例9: isRegistered
/**
* Checks whether the given channel is registered
*
* @param string $channel
* @return boolean
*/
public function isRegistered($channel)
{
$sql = "SELECT\r\n\t\t\t\tcount(*) as count\r\n\t\t\tFROM\r\n\t\t\t\tchanserv_channels\r\n\t\t\tWHERE\r\n\t\t\t\tchannel = '" . escapeString($channel) . "'";
$row = Services::getDB()->getFirstRow($sql);
return $row['count'] > 0;
}
示例10: bindCommand
/**
* Binds a command to $botAddress
* @param string $botAddress
* @param string $moduleAddress
* @param string $commandName
* @param boolean $appearInHelp
* @param boolean $fromDatabase
*/
public function bindCommand($botAddress, $moduleAddress, $commandName, $appearInHelp = true, $fromDatabase = false)
{
// validate
if (!$this->moduleLoaded($moduleAddress)) {
throw new ModuleException("Unknown module at address '" . $moduleAddress . "'");
}
if (!$this->moduleLoaded($botAddress)) {
throw new ModuleException("Unknown module at address '" . $botAddress . "'");
}
if ($this->moduleInformation[$botAddress]['type'] != 'Bot') {
throw new ModuleException("Commands can only bound to bots");
}
// bind
$this->runningBots[$botAddress]->registerCommand(new $moduleAddress($this->runningBots[$botAddress], strtoupper($commandName), $appearInHelp));
// write to db
if (!$fromDatabase) {
$sql = "INSERT INTO\r\n\t\t\t\t\t\tmodule_instance_command (address, commandName, appearInHelp, parentAddress)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t('" . escapeString($moduleAddress) . "', '" . escapeString(strtoupper($commandName)) . "', " . ($appearInHelp ? 1 : 0) . ", '" . escapeString($botAddress) . "')";
Services::getDB()->sendQuery($sql);
}
}
示例11: escapeString
/**
* @see Database::escapeString()
* @param string $str
*/
function escapeString($str)
{
return Services::getDB()->escapeString($str);
}