Ejemplo n.º 1
0
 /**
  * Add the .seen-command provided by the Seen-module
  */
 public function __construct()
 {
     $commandsModule = ModuleManager::getInstance()->offsetGet('Commands');
     Seen::addSeenCommand($commandsModule);
     NuwaniSisters::addNuwaniSistersCommands($commandsModule);
     QuoteDevice::addMqdCommands($commandsModule);
     self::add8ballCommand($commandsModule);
     TempHistory::addTempHistoryCommand($commandsModule);
 }
Ejemplo n.º 2
0
 /**
  * This function gets invoked when someone invites a person or a bot in to
  * a channel. This could be us, and after all, it'd be fancy if the bot
  * owner would be capable of inviting his/her bots in various channels.
  * 
  * @param Bot $pBot The bot who received the invite message.
  * @param string $sInviter Nickname of the person who invites someone.
  * @param string $sInvitee Nickname of the person being invited.
  * @param string $sChannel Channel in which the invitation occurs.
  */
 public function onInvite(Bot $pBot, $sInviter, $sInvitee, $sChannel)
 {
     if ($pBot['Nickname'] != $sInvitee) {
         return false;
     }
     $pEvaluationModule = ModuleManager::getInstance()->offsetGet('Evaluation');
     if ($pEvaluationModule !== false) {
         if (!$pEvaluationModule->checkSecurity($pBot, ISecurityProvider::BOT_OWNER)) {
             return false;
         }
         $pBot->send('JOIN ' . $sChannel);
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Well, queries should be ignored as well.
  *
  * @param Bot $pBot The bot which received this message.
  * @param string $sNickname Nickname who is PM'ing us.
  * @param string $sMessage The message being send to us.
  */
 public function onPrivmsg(Bot $pBot, $sNickname, $sMessage)
 {
     if (substr($sMessage, 0, 6) == 'login ' && $this->checkIgnore((string) $pBot->In->User)) {
         /** Directed at the Evaluation module, always allow this. **/
         $pEval = ModuleManager::getInstance()->offsetGet('Evaluation');
         if ($pEval instanceof ModuleBase) {
             $pEval->onPrivmsg($pBot, $sNickname, $sMessage);
         }
     }
     /** Ignore all other messages, but only if this person's ignored of course. **/
     return $this->handleCommand($pBot, $sMessage, $sNickname);
 }
Ejemplo n.º 4
0
 /**
  * Returns the security manager for this bot particulair bot. Throws an Exception when called on a slave bot,
  * as those don't need a security manager and thus don't have it.
  *
  * @throws Exception If called on a slave bot.
  * @return \Nuwani\SecurityManager The security manager for this bot.
  */
 public function getSecurityManager()
 {
     if ($this->isSlave()) {
         throw new Exception('Slave bots don\'t have a security manager.');
     }
     if ($this->m_pSecurityManager == null) {
         $this->m_pSecurityManager = new SecurityManager();
         ModuleManager::getInstance()->registerCallbackObject($this->m_pSecurityManager);
     }
     return $this->m_pSecurityManager;
 }
Ejemplo n.º 5
0
 /**
  * Practically the same as the prepare () method, we're catching the error
  * and sending it to the debug channel.
  * 
  * @param string $sQuery The query to execute.
  * @param integer $nResultMode The way you want to receive the result.
  * @return mixed
  */
 public function query($sQuery, $nResultMode = MYSQLI_STORE_RESULT)
 {
     ob_start();
     $mResult = parent::query($sQuery, $nResultMode);
     $sUnwanted = ob_get_clean();
     if ($mResult == false) {
         ModuleManager::getInstance()->offsetGet('LVPEchoHandler')->error(null, LVP::DEBUG_CHANNEL, 'Executing query failed: ' . $this->error);
         ModuleManager::getInstance()->offsetGet('LVPEchoHandler')->error(null, LVP::DEBUG_CHANNEL, $sUnwanted);
     }
     return $mResult;
 }
Ejemplo n.º 6
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;
     }));
 }
Ejemplo n.º 7
0
 /**
  * We recieved a message! Oh joy!
  * @param Bot $pBot
  * @param string $sChannel
  * @param string $sNickname
  * @param string $sMessage
  */
 public function onChannelPrivmsg(Bot $pBot, $sChannel, $sNickname, $sMessage)
 {
     $pEval = ModuleManager::getInstance()->offsetGet('Evaluation');
     if (!$pEval->checkSecurity($pBot, 9999)) {
         // Not the (logged in) owner.
         return;
     }
     $aParts = Util::parseMessage($sMessage);
     switch ($aParts[0]) {
         case '!locktopic':
             $this->lockTopic($sChannel);
             $pBot->send('PRIVMSG ' . $sChannel . ' :4Notice: Topic locked.');
             file_put_contents('Data/TopicLock.dat', serialize($this->m_aChannels));
             break;
         case '!unlocktopic':
             $this->unlockTopic($sChannel);
             $pBot->send('PRIVMSG ' . $sChannel . ' :4Notice: Topic unlocked.');
             file_put_contents('Data/TopicLock.dat', serialize($this->m_aChannels));
             break;
         case '!listtopic':
             if ($aParts[1] === null) {
                 $pBot->send('PRIVMSG ' . $sChannel . ' :4Listing topics: ');
                 foreach (array_keys($this->m_aChannels) as $sCurrentChannel) {
                     $pBot->send('PRIVMSG ' . $sChannel . ' :[' . $sCurrentChannel . '] -> ' . $this->m_aChannels[$sCurrentChannel]['Topic']);
                 }
                 break;
             } else {
                 $pBot->send('PRIVMSG ' . $sChannel . ' :4Topic for channel ' . $aParts[1] . ': ' . $this->m_aChannels[$aParts[1]]['Topic']);
                 break;
             }
     }
 }
Ejemplo n.º 8
0
 /**
  * After we have confirmed the identity of the one evaluating code on
  * this bot, we're ready to parse the evaluation string into the options.
  *
  * @param Bot $pBot Bot that should handle the evaluation.
  * @param string $sDestination Where should the output be redirected?
  * @param string $sEvaluation Line of code that should be executed.
  */
 private function parseEvaluation(Bot $pBot, $sDestination, $sEvaluation)
 {
     $nFirstSpace = strpos($sEvaluation, ' ');
     if ($nFirstSpace === false) {
         return false;
     }
     $sEvaluationIdent = substr($sEvaluation, 0, $nFirstSpace);
     $sEvaluation = substr($sEvaluation, strlen($sEvaluationIdent) + 1);
     $aOptions = array('Type' => 'PHP', 'Buffering' => true, 'Operation' => $sEvaluation, 'Delay' => 0, 'MaxLines' => 4);
     if (strlen($sEvaluationIdent) != strlen($this->m_sPrefix)) {
         $sEvaluationIdent = str_replace($this->m_sPrefix, '', $sEvaluationIdent);
         if (strpos($sEvaluationIdent, '!') !== false) {
             $sEvaluationIdent = str_replace('!', '', $sEvaluationIdent);
             $aOptions['Type'] = 'EXEC';
         } else {
             if (strpos($sEvaluationIdent, '@') !== false) {
                 $sEvaluationIdent = str_replace('@', '', $sEvaluationIdent);
                 $aOptions['Type'] = 'SQL';
                 $aOptions['MaxLines'] = 5;
             }
         }
         $aMatches = array();
         preg_match_all('/(\\d+)(s|m|h)/', $sEvaluationIdent, $aMatches);
         foreach ($aMatches[0] as $iIndex => $sMatch) {
             $nThisDelay = $aMatches[1][$iIndex];
             switch ($aMatches[2][$iIndex]) {
                 case 'h':
                 case 'H':
                     $nThisDelay *= 60;
                     // drop through
                 // drop through
                 case 'm':
                 case 'M':
                     $nThisDelay *= 60;
                     break;
             }
             $sEvaluationIdent = str_replace($sMatch, '', $sEvaluationIdent);
             $aOptions['Delay'] += $nThisDelay;
         }
         if (strpos($sEvaluationIdent, 'out') !== false) {
             $sEvaluationIdent = str_replace('out', '', $sEvaluationIdent);
             $aOptions['Buffering'] = false;
         }
         if ($sEvaluationIdent != '') {
             /** Some weird f****d up prefix, ignore the line. **/
             return false;
         }
     }
     if ($aOptions['Delay'] > 0) {
         Timer::create(function () use($pBot, $sDestination, $aOptions) {
             $pModules = ModuleManager::getInstance();
             if (isset($pModules['Evaluation'])) {
                 $pModules['Evaluation']->doEvaluation($pBot, $sDestination, $aOptions);
             }
         }, $aOptions['Delay'] * 1000, Timer::TIMEOUT);
         return true;
     }
     $this->doEvaluation($pBot, $sDestination, $aOptions);
     return true;
 }