コード例 #1
0
ファイル: NuwaniSisters.php プロジェクト: xhoogland/Monique
 public static function addNuwaniSistersCommands(Commands $moduleManager)
 {
     $unusableCommandsArray = array('pm', 'admin', 'say', 'getid', 'msg', 'announce', 'mute', 'jail', 'ban', 'kick');
     foreach ($unusableCommandsArray as $command) {
         $moduleManager->registerCommand(new \Command($command, function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) use($command) {
             if (!\LVP\NuwaniSisters::$isMasterBotAvailable && (strtolower($sChannel) == '#xanland.logging' || strtolower($sChannel) == '#lvp.echo')) {
                 echo 'Due to ' . \LVP\NuwaniSisters::MASTER_BOT_NAME . ' (main-bot) being offline, no commands can be handled until it is restarted. You can request a restart in #LVP (or #LVP.Dev).';
                 return \Command::OUTPUT_ERROR;
             }
         }));
     }
     $moduleManager->registerCommand(new \Command('players', function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (!\LVP\NuwaniSisters::$isMasterBotAvailable && (strtolower($sChannel) == '#lvp' || strtolower($sChannel) == '#lvp.echo')) {
             if (!isset($aParams[0])) {
                 Seen::syncOnlinePlayers();
                 $aIngamePlayers = new Model('lvp_person_last_seen', 'sReason', 'online');
                 $aIngamePlayers = $aIngamePlayers->getAll();
                 $sEcho = '7Online players - 4No information about status and/or level available! (' . count($aIngamePlayers) . '): ';
                 foreach ($aIngamePlayers as $sPlayer) {
                     $sEcho .= $sPlayer->lvp_person_last_seen_id . ', ';
                 }
                 // 512 (max IRC message length) - 2 (\r\n) - 50 (max channel name) - 10 (PRIVMSG part + safety) = 450
                 echo wordwrap(substr($sEcho, 0, -2), 450, PHP_EOL);
             } else {
                 echo 'If ' . $aParams[0] . ' is a registered player on Las Venturas Playground, the latest information can be found here: http://profile.sa-mp.nl/' . urlencode($aParams[0]) . '';
                 return \Command::OUTPUT_INFO;
             }
         }
     }));
     $moduleManager->registerCommand(new \Command('getname', function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (!\LVP\NuwaniSisters::$isMasterBotAvailable && (strtolower($sChannel) == '#lvp' || strtolower($sChannel) == '#lvp.echo')) {
             if (!isset($aParams[0])) {
                 echo '!getname [playerId] - 4No information about status and/or level available!';
                 return \Command::OUTPUT_USAGE;
             } else {
                 $oMatchingPlayer = new Model('lvp_person_last_seen', 'iId', $aParams[0]);
                 if ($oMatchingPlayer->lvp_person_last_seen_id === null) {
                     echo 'There is no player with ID ' . $aParams[0] . ' online at the moment. - 4No information about status and/or level available!';
                 } else {
                     echo 'Player with ID ' . $aParams[0] . ' has nickname "' . $oMatchingPlayer->lvp_person_last_seen_id . '". - 4No information about status and/or level available!';
                 }
                 return \Command::OUTPUT_INFO;
             }
         }
     }));
     $moduleManager->registerCommand(new \Command('getid', function ($pBot, $sDestination, $sChannel, $sNickname, $aParams, $sMessage) {
         if (!\LVP\NuwaniSisters::$isMasterBotAvailable && (strtolower($sChannel) == '#lvp' || strtolower($sChannel) == '#lvp.echo')) {
             if (!isset($aParams[0])) {
                 echo '!getid [nickname] - 4No information about status and/or level available!';
                 return \Command::OUTPUT_USAGE;
             } else {
                 $oMatchingPlayers = new Model('lvp_person_last_seen', 'lvp_person_last_seen_id', '%' . $aParams[0] . '%');
                 if ($oMatchingPlayers->lvp_person_last_seen_id === null) {
                     echo 'No online players found matching "' . $aParams[0] . '". - 4No information about status and/or level available!';
                 } else {
                     $oMatchingPlayers = $oMatchingPlayers->getAll();
                     $sEcho = 'Online players found (%count($oMatchingPlayers)%): ';
                     $i = 0;
                     foreach ($oMatchingPlayers as $oPlayer) {
                         if ($oPlayer->sReason == 'online') {
                             $sEcho .= $oPlayer->lvp_person_last_seen_id . ' (ID: ' . $oPlayer->iId . '), ';
                             $i++;
                         }
                     }
                     $sEcho = str_replace('%count($oMatchingPlayers)%', $i, $sEcho);
                     $sEcho = substr($sEcho, 0, -2);
                     $sEcho .= ' - 4No information about status and/or level available!';
                     // 512 (max IRC message length) - 2 (\r\n) - 50 (max channel name) - 10 (PRIVMSG part + safety) = 450
                     echo wordwrap($sEcho, 450, PHP_EOL);
                 }
                 return \Command::OUTPUT_INFO;
             }
         }
     }));
 }
コード例 #2
0
ファイル: Module.php プロジェクト: xhoogland/Monique
 /**
  * Here we process each individual message if it matches the right user and
  * channel. If so we can send it to the specific module to process it.
  *
  * @param  Bot          $pBot
  * @param  string $channel
  * @param  string $sNickname
  * @param  string $message
  */
 public function onChannelPrivmsg(Bot $pBot, $sChannel, $sNickname, $sMessage)
 {
     if ($sChannel[0] == '+' || $sChannel[0] == '%' || $sChannel[0] == '@' || $sChannel[0] == '&' || $sChannel[0] == '~') {
         $channel = substr($sChannel, 1);
     }
     $channel = strtolower($sChannel);
     $message = Util::stripFormat($sMessage);
     if ($channel == self::ECHO_CHANNEL || $channel == self::LOGGING_CHANNEL) {
         $pConfiguration = Configuration::getInstance();
         $aConfiguration = $pConfiguration->get('LVP');
         if (in_array($sNickname, $aConfiguration['NuwaniSistersEchoBots'])) {
             if ($message == '*** Global Gamemode Initialization') {
                 Seen::resetOnlinePlayersAtGamemodeInit();
                 Merchant::resetInformation();
             } else {
                 Seen::setPersonInformation($message);
                 Merchant::setInformation($message);
                 TempHistory::messageHandler($message);
                 if ($pBot['Nickname'] == 'Monique') {
                     QuoteDevice::setInformation($pBot, $message);
                 }
             }
         }
         if ($message == '!players') {
             Seen::syncOnlinePlayers();
         }
     }
     if ($channel == self::RADIO_CHANNEL && $sNickname == 'LVP_Radio') {
         Radio::setNowPlayingInformation($message);
     }
 }