コード例 #1
0
ファイル: LVPModel.php プロジェクト: xhoogland/Monique
 /**
  * Also set the changed data and update the table.
  *
  * @return boolean
  */
 public function save()
 {
     if ($this->_aLoadedData == []) {
         $this->_aMutableData = array($this->_sIdColumn => $this->_sId) + $this->_aMutableData;
     }
     foreach ($this->_aMutableData as $sVarName => $sVarValue) {
         if ($this->_aLoadedData != null && $sVarValue == $this->_aLoadedData[$sVarName]) {
             continue;
         }
         if ($this->_aLoadedData == []) {
             $sQueryWithColumns = "insert into `" . $this->_sTable . "` (`" . $this->_sIdColumn . "`, ";
             foreach ($this->_aMutableData as $sColumn => $sValue) {
                 if ($sColumn == $this->_sIdColumn) {
                     continue;
                 }
                 $sQueryWithColumns .= "`" . $sColumn . "`, ";
             }
             $sQuery = substr($sQueryWithColumns, 0, -2) . ')';
             $sQueryWithValues = "select :sVarValue, ";
             foreach ($this->_aMutableData as $sColumn => $sValue) {
                 if ($sColumn == $this->_sIdColumn) {
                     continue;
                 }
                 $sQueryWithValues .= ":" . $sColumn . ", ";
             }
             $sQuery .= substr($sQueryWithValues, 0, -2);
         } else {
             $sQuery = "update " . $this->_sTable . "\n                           set " . $sVarName . " = :sVarValue\n                           where " . $this->_sIdColumn . " like CONVERT(:sId USING utf8) COLLATE utf8_bin;";
         }
         //echo str_replace (array (':sVarValue', ':sId'), array ($sVarValue, $this -> _sId), $sQuery) . PHP_EOL;
         try {
             if ($this->_pPDO == null) {
                 $this->connectToDatabase();
             }
             $oStmt = $this->_pPDO->prepare($sQuery);
             $oStmt->bindParam(':sVarValue', $sVarValue);
             if ($this->_aLoadedData != null) {
                 $oStmt->bindParam(':sId', $this->_sId);
             } else {
                 foreach ($this->_aMutableData as $sColumn => $sValue) {
                     if ($sColumn == $this->_sIdColumn) {
                         continue;
                     }
                     if (stringH::IsNullOrWhiteSpace($sValue)) {
                         $sValue = null;
                     }
                     $oStmt->bindValue(':' . $sColumn, $sValue);
                 }
             }
             if ($oStmt->execute()) {
                 if ($this->_aLoadedData == []) {
                     $this->fillLoadedData();
                 } else {
                     $this->_aLoadedData[$sVarName] = $sVarValue;
                 }
                 //                    if ($sVarName == $this->_sIdColumn)
                 //                        $this->_sId = $sVarValue;
             } else {
                 ob_start();
                 var_dump($oStmt->errorInfo());
                 $varDump = ob_get_contents();
                 ob_end_clean();
                 file_put_contents('error.log', $varDump, FILE_APPEND);
             }
         } catch (\PDOException $e) {
             return false;
         }
     }
     return true;
 }
コード例 #2
0
ファイル: Seen.php プロジェクト: xhoogland/Monique
 /**
  * Registers the .seen-command in the commands-module for use in-game
  *
  * @param Commands $moduleManager Object so the command can be registered in the commands-module
  */
 public static function addSeenCommand(Commands $moduleManager)
 {
     $moduleManager->registerCommand(new \Command('.seen', function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (stringH::IsNullOrWhiteSpace($aParams[0]) || count($aParams) != 1) {
             echo '!msg * Usage: .seen <username>';
         } else {
             $oLastSeenPerson = self::getPersonSeenData('lvp_person_last_seen_id', $aParams[0]);
             if (!stringH::IsNullOrWhiteSpace($oLastSeenPerson->lvp_person_last_seen_id)) {
                 if ($oLastSeenPerson->sReason != 'online') {
                     echo stringH::Format('!msg {0} was last seen online {1}{2}.', $oLastSeenPerson->lvp_person_last_seen_id, date('H:i:s @ d-m-Y', $oLastSeenPerson->iTime), $oLastSeenPerson->sReason);
                 } else {
                     echo stringH::Format('!msg {0} is already online for {1}.', $oLastSeenPerson->lvp_person_last_seen_id, \Util::formatTime(time() - $oLastSeenPerson->iTime));
                 }
             } else {
                 echo '!msg * Error: Sorry, this username has not (yet) been found.';
             }
         }
     }));
 }
コード例 #3
0
ファイル: ZNotification.php プロジェクト: xhoogland/Monique
 /**
  * To know on which command we have to reply on when someone wants to set a notification, we
  * have to register the command with the Commands-module.
  */
 private function registerTellCommand()
 {
     $moduleManager = ModuleManager::getInstance()->offsetGet('Commands');
     $moduleManager->registerCommand(new \Command(self::NOTIFICATION_COMMAND_NAME, function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (stringH::IsNullOrWhiteSpace($sMessage)) {
             echo '7* Usage: nickname message';
             return;
         }
         list($sReceiver, $sNotification) = explode(' ', $sMessage, 2);
         if (strtolower($sReceiver) == strtolower($sNickname)) {
             echo '10* Info: You cannot send notifications to yourself.';
             return;
         }
         $oNotification = new Model(self::NOTIFICATION_TABLE, 'sReceiver', $sReceiver);
         if (count($oNotification->getAll()) >= self::NOTIFICATION_MESSAGE_LIMIT) {
             echo '10* Info: The message could not be stored, because there are already ' . self::NOTIFICATION_MESSAGE_LIMIT . ' messages waiting for ' . $sReceiver;
             return;
         }
         $oNotification = new Model(self::NOTIFICATION_TABLE, 'iTimestamp', time());
         $oNotification->sReceiver = $sReceiver;
         $oNotification->sSender = $sNickname;
         $oNotification->sMessage = $sNotification;
         $oNotification->iTimestamp = time();
         $oNotification->sNetwork = $pBot['Network'];
         $oNotification->sChannel = $sChannel;
         if ($oNotification->save()) {
             $sReceiver = strtolower($oNotification->sReceiver);
             if (!in_array($sReceiver, $this->notifiedUsers)) {
                 $this->notifiedUsers[] = $sReceiver;
             }
             echo 'Sure ' . $sNickname . '!';
         }
         return;
     }));
 }
コード例 #4
0
ファイル: Module.php プロジェクト: xhoogland/Monique
 private function GetNicknameFromValidEchoLine(string $servername, array $messageParts, string $messageType) : string
 {
     if ($servername == 'LVP') {
         if ($messageType == 'privmsg') {
             return str_replace(':', '', $messageParts[1]);
         }
         if ($messageType == 'action') {
             if (!stringH::IsNullOrWhiteSpace($messageParts[1])) {
                 return $messageParts[1];
             }
             return '';
         }
         if ($messageType == 'worldmsg') {
             return str_replace(':', '', $messageParts[4]);
         }
         if ($messageType == 'vipmsg') {
             return str_replace(':', '', $messageParts[3]);
         }
     } else {
         if ($servername == 'OAS MC') {
             if ($messageType == 'privmsg') {
                 return str_replace(array('<', '>'), '', $messageParts[1]);
             }
             if ($messageType == 'action') {
                 $nickname = strstr($messageParts[0], '***');
                 unset($nickname[0]);
                 return $nickname;
             }
         }
     }
     return '';
 }