/**
  * @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));
     }
 }
 /**
  * @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) == 2) {
         // check target access
         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'));
         } else {
             Services::getConnection()->getProtocol()->sendKick($this->bot->getUuid(), $target, $messageEx[1], $user->getNick());
         }
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     } else {
         unset($messageEx[0]);
         $username = $messageEx[1];
         unset($messageEx[1]);
         // check target access
         // todo: abort when target has no account
         if ($access < $this->bot->getAccess($target, Services::getUserManager()->getUserByNick($username)->accountname)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
         } else {
             Services::getConnection()->getProtocol()->sendKick($this->bot->getUuid(), $target, $username, $user->getNick() . ': ' . implode(' ', $messageEx));
         }
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) >= 2) {
         // get channel name
         $channel = $messageEx[1];
         // avoid empty strings
         if (empty($channel)) {
             $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
         }
         // add the #
         if ($channel[0] != '#') {
             $channel = '#' . $channel;
         }
         unset($messageEx[0]);
         unset($messageEx[1]);
         $message = implode(' ', $messageEx);
         $this->bot->part($channel, $message);
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $channel));
     } else {
         // send syntax hint
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
     }
 }
 /**
  * @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'));
         }
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) == 2) {
         $email = $messageEx[1];
         if (!$this->bot->isAuthed($user->getUuid())) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.notAuthed'));
         }
         $this->bot->email(Services::getUserManager()->getUser($user->getUuid())->accountname, $email);
         $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'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     // BIND <bot> <module> <command> <appearInHelp>
     if (count($messageEx) >= 3) {
         $botAddress = Services::getModuleManager()->lookupModule($messageEx[1]);
         $moduleAddress = Services::getModuleManager()->lookupModule($messageEx[2]);
         $commandName = $messageEx[3];
         $appearInHelp = (bool) (isset($messageEx[4]) ? $messageEx[4] : true);
         Services::getModuleManager()->bindCommand($botAddress, $moduleAddress, $commandName, $appearInHelp);
         $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'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) == 2 and !empty($messageEx[1])) {
         // get module name
         $moduleName = $messageEx[1];
         try {
             // try to load module
             Services::getModuleManager()->loadModule(SDIR . 'lib/modules/' . ucfirst($moduleName) . '.class.php');
         } catch (Exception $ex) {
             $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.cannotLoad', $ex->getMessage()));
         }
     } else {
         // send syntax hint
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) == 3) {
         $oldPassword = $messageEx[1];
         $newPassword = $messageEx[2];
         if (!$this->bot->isAuthed($user->getUuid())) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.notAuthed'));
         }
         if (!$this->bot->checkCredentials($accountname, $oldPassword)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.auth.invalidCredentials'));
         }
         $this->bot->pass(Services::getUserManager()->getUser($user->getUuid())->accountname, $newPassword);
         $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'));
     }
 }
 /**
  * @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'));
     }
 }
 /**
  * @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]);
     }
     $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) {
         $this->bot->setStandardModes($target);
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     } else {
         unset($messageEx[0]);
         $modeString = implode(' ', $messageEx);
         Services::getConnection()->getProtocol()->sendMode($this->bot->getUuid(), $target, str_replace(array('q', 'r', 'a', 'v', 'o', 'b', 'h', 'A', 'O', 'e', 'P'), '', $modeString));
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     }
 }
 /**
  * @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'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) == 3) {
         $accountname = $messageEx[1];
         $password = $messageEx[2];
         if ($this->bot->isAuthed($user->getUuid())) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.alreadyAuthed'));
         }
         if (!$this->bot->checkCredentials($accountname, $password)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.invalidCredentials'));
         }
         $users = $this->bot->getUsers($accountname);
         foreach ($users as $uuid) {
             $this->bot->sendMessage($uuid, Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.login'));
         }
         $this->bot->setAccount($user->getUuid(), $accountname);
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $accountname));
     } else {
         // send syntax hint
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
     }
 }
 /**
  * @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'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if (count($messageEx) == 4) {
         $accountname = $messageEx[1];
         $password = $messageEx[2];
         $email = $messageEx[3];
         if ($this->bot->isAuthed($user->getUuid())) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.alreadyAuthed'));
         }
         if ($this->bot->accountExists($accountname)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.accountExists'));
         }
         if ($this->bot->emailExists($email)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.emailExists'));
         }
         $this->bot->create($accountname, $password, $email);
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $accountname));
     } else {
         // send syntax hint
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.syntaxHint'));
     }
 }
 /**
  * @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 . '.alreadyRegistered'));
     }
     $users = Services::getChannelManager()->getChannel($target)->getUserList();
     foreach ($users as $channelUser) {
         if ($channelUser['user']->getUuid() == $user->getUuid()) {
             if (stripos($channelUser['mode'], 'o')) {
                 $this->bot->register($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
                 Services::getConnection()->getProtocol()->sendMode($this->bot->getUuid(), $target, '+q ' . $user->getNick());
                 return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $target));
             }
         }
     }
     return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.noOp'));
 }
 /**
  * Spits out the help
  *
  * @param	UserType	$user
  * @param	string		$target
  * @param	string		$message
  * @return	void
  */
 public function generateHelp(UserType $user, $target, $message)
 {
     $inputEx = explode(' ', $message);
     if (!isset($inputEx[1])) {
         $this->sendMessage($user->getUuid(), COLOR_BOLD . COLOR_UNDERLINE . Services::getLanguage()->get($user->languageID, 'bot.global.help', $this->getNick()) . COLOR_UNDERLINE . COLOR_BOLD);
         $longestCommandName = 0;
         foreach ($this->commands as $key => $command) {
             if ($command->appearInHelp and strlen($command->commandName) > $longestCommandName) {
                 $longestCommandName = strlen($command->commandName);
             }
         }
         foreach ($this->commands as $key => $command) {
             if ($command->appearInHelp and $this->getPermissions($user, $command->neededPermissions)) {
                 $this->sendMessage($user->getUuid(), str_pad($command->commandName, $longestCommandName + 3) . Services::getLanguage()->get($user->languageID, 'command.' . $command->originalName));
             }
         }
     } else {
         foreach ($this->commands as $key => $command) {
             if ($command->commandName == strtoupper($inputEx[1])) {
                 $this->sendMessage($user->getUuid(), $command->commandName);
                 $this->sendMessage($user->getUuid(), COLOR_BOLD . COLOR_UNDERLINE . "Syntax:" . COLOR_UNDERLINE . COLOR_BOLD . " " . Services::getLanguage()->get($user->languageID, 'command.' . $command->originalName . '.syntaxHint'));
                 if ($command->neededPermissions > 0) {
                     $this->sendMessage($user->getUuid(), COLOR_BOLD . Services::getLanguage()->get($user->languageID, 'bot.global.neededPermissions') . COLOR_BOLD . " " . $command->neededPermissions);
                 }
                 if (Services::getLanguage()->get($user->languageID, 'command.' . $command->originalName . '.description') != 'command.' . $command->originalName . '.description') {
                     $this->sendMessage($user->getUuid(), 'command.' . $command->originalName . '.description');
                 }
                 return;
             }
         }
         $this->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'bot.global.noSuchCommand'));
     }
 }