Example #1
0
 public static function addTempHistoryCommand(Commands $commandsModule)
 {
     $commandsModule->registerCommand(new Command('temphistory', function ($bot, $destination, $channel, $nickname, $params, $message) {
         if (strtolower($channel) != '#lvp.crew' && strtolower($channel) != '#xanland.logging') {
             return;
         }
         if (count($params) < 1 || count($params) > 2) {
             echo '!temphistory [playerName] [items=5]';
             return Command::OUTPUT_USAGE;
         }
         $tempedPlayer = $params[0];
         $lvpTemphistorySingle = new Model('lvp_temphistory', 'temped_player', $tempedPlayer);
         $lvpTemphistoryArray = $lvpTemphistorySingle->getAll('start_timestamp desc');
         $amountOfTempRows = count($lvpTemphistoryArray);
         if ($amountOfTempRows == 0) {
             echo stringH::Format('{0}*** No items found for player {1}.', ModuleBase::COLOUR_RED, $tempedPlayer);
             return;
         }
         $items = $params[1] ?? 5;
         if ($items > $amountOfTempRows) {
             $items = $amountOfTempRows;
         }
         $s = 's';
         if ($amountOfTempRows == 1) {
             $s = '';
         }
         echo stringH::Format('{0}*** Temp. admin log for {1} ({2}/{3} item{4}){5}', ModuleBase::COLOUR_RED, $tempedPlayer, $items, $amountOfTempRows, $s, PHP_EOL);
         $i = 0;
         foreach ($lvpTemphistoryArray as $lvpTemphistory) {
             $startTimestamp = $lvpTemphistory->start_timestamp;
             $endTimestamp = $lvpTemphistory->end_timestamp;
             $takenByOrIngame = 'taken by: ' . $lvpTemphistory->temp_taken_by;
             if (is_null($lvpTemphistory->temp_taken_by) && is_null($endTimestamp)) {
                 $takenByOrIngame = 'currently in-game';
                 $endTimestamp = 'now';
             }
             echo stringH::Format('{0}[{1}] {2}(Granted by: {3}, {4}){5}: {6} - {7} {8}({9}){10}', ModuleBase::COLOUR_RED, date('d-m-Y', $startTimestamp), ModuleBase::COLOUR_DARKGREEN, $lvpTemphistory->temp_granted_by, $takenByOrIngame, ModuleBase::CLEAR, date('H:i:s', $startTimestamp), $endTimestamp == 'now' ? 'now' : date('H:i:s', $endTimestamp), ModuleBase::COLOUR_GREY, Util::formatTime(($endTimestamp == 'now' ? strtotime($endTimestamp) : $endTimestamp) - $startTimestamp, true), PHP_EOL);
             // 8, 9, 10
             if ($i++ == $items - 1) {
                 break;
             }
         }
     }));
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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;
     }));
 }
Example #4
0
 /**
  * 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.';
             }
         }
     }));
 }
Example #5
0
 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 '';
 }
Example #6
0
 /**
  * To know what the quoteDevice now wants we need to parse the information we are receiving in #LVP.echo from a
  * Nuwani-sisters-bot.
  *
  * @param Bot    $pBot
  * @param string $sMessage The message with the information for the quoteDevice.
  */
 public static function setInformation(Bot $pBot, string $sMessage)
 {
     $aParameters = explode(' ', \Util::stripFormat($sMessage . ' '));
     $aNewParameters = explode(' ', \Util::stripFormat($sMessage . ' '));
     unset($aNewParameters[0], $aNewParameters[1]);
     $sNewMessage = implode(' ', $aNewParameters);
     $sPathToLogFile = stringH::Format('Data/Logs/{0}-{1}-{2}-#lvp.echo.log', date('Y'), date('m'), date('d'));
     if (strstr($aParameters[0], '[') !== false && strstr($aParameters[0], ']') !== false) {
         if (strstr($aParameters[1], ':') !== false) {
             file_put_contents($sPathToLogFile, stringH::Format('[{0}] <{1}> {2}' . PHP_EOL, date('H:i:s'), trim($aParameters[1], ':'), $sNewMessage), FILE_APPEND);
         } elseif (strstr($aParameters[1], ':') === false && strstr($aParameters[1], '***') === false) {
             file_put_contents($sPathToLogFile, stringH::Format('[{0}] * {1} {2}' . PHP_EOL, date('H:i:s'), trim($aParameters[1], ':'), $sNewMessage), FILE_APPEND);
         } elseif ($aParameters[1] == '***' && strstr($aParameters[6], 'kicked') !== false) {
             file_put_contents($sPathToLogFile, stringH::Format('[{0}] *** {1} was kicked by {2}' . PHP_EOL, date('H:i:s'), $aParameters[2], 'LasVenturasPlayground'), FILE_APPEND);
         }
     } elseif ($aParameters[2] == 'on' && $aParameters[3] == 'IRC:') {
         unset($aNewParameters[2], $aNewParameters[3]);
         $sNewMessage = implode(' ', $aNewParameters);
         file_put_contents($sPathToLogFile, stringH::Format('[{0}] <{1}> {2}' . PHP_EOL, date('H:i:s'), trim($aParameters[1], ':'), $sNewMessage), FILE_APPEND);
     }
     if (strstr(strtolower($sMessage), 'monique') && !strstr(strtolower($sMessage), 'monique:') && file_get_contents(self::$m_sMqdFileName) != '') {
         self::sendRandomMessage($pBot);
     }
     return;
 }