Exemplo n.º 1
0
 public function command()
 {
     // We don't want any trailing \n, \r or anything in that area.
     $command = \Library\FunctionCollection::removeLineBreaks(implode(' ', $this->arguments));
     $user = \Library\FunctionCollection::getUserNickName($this->data);
     $time = @end(explode(' in ', $command));
     $message = str_replace(' in ' . $time, '', $command);
     $currTime = time();
     if (!preg_match('/(\\d+)(s|m|h|d)/i', $time, $out)) {
         $this->say('Invalid arguments.');
         return;
     }
     $newtime = 0;
     switch ($out[2]) {
         case 's':
             $newtime = $currTime + $out[1];
             break;
         case 'm':
             $newtime = $currTime + $out[1] * 60;
             break;
         case 'h':
             $newtime = $currTime + $out[1] * 60 * 60;
             break;
         case 'd':
             $newtime = $currTime + $out[1] * 60 * 60 * 24;
             break;
     }
     $message = $user . ', ' . $message;
     $this->bot->reminders[$newtime] = $message;
     $this->say('Reminder "' . $message . '" set at ' . date('d-m-Y H:i:s', $newtime) . ' GMT+1, current time: ' . date('d-m-Y H:i:s'));
 }
Exemplo n.º 2
0
 public function command()
 {
     // We don't want any trailing \n, \r or anything in that area.
     $subcomm = $this->arguments[0];
     $command = \Library\FunctionCollection::removeLineBreaks(implode(' ', $this->arguments));
     $user = \Library\FunctionCollection::getUserNickName($this->data);
     if (!empty($subcomm)) {
         switch ($subcomm) {
             case 'show':
                 $this->arguments[1] = (int) $this->arguments[1];
                 if (!empty($this->notes[$user][$this->arguments[1]])) {
                     $this->say('Note #' . $this->arguments[1] . ': ' . $this->notes[$user][$this->arguments[1]]['note']);
                 } else {
                     $this->say('No note with ID ' . $this->arguments[1] . ' found.');
                 }
                 break;
             case 'delete':
                 $this->arguments[1] = (int) $this->arguments[1];
                 if (!empty($this->notes[$user][$this->arguments[1]])) {
                     $this->say('Note #' . $this->arguments[1] . ': "' . $this->notes[$user][$this->arguments[1]]['name'] . '" was deleted.');
                     unset($this->notes[$user][$this->arguments[1]]);
                 } else {
                     $this->say('No note with ID ' . $this->arguments[1] . ' found.');
                 }
                 break;
             case 'list':
                 if (!empty($this->notes[$user])) {
                     $notenames = array();
                     foreach ($this->notes[$user] as $id => $note) {
                         $notenames[] = '#' . $id . ': ' . $note['name'];
                     }
                     $this->say($user . ', I have ' . count($this->notes[$user]) . ' notes for you: ' . implode(', ', $notenames));
                 } else {
                     $this->say($user . ', I don\'t have any notes for you.');
                 }
                 break;
             default:
                 $dname = '(unnamed)';
                 $message = $command;
                 if (preg_match('/@ (.+)$/', $command, $name)) {
                     $dname = preg_replace('/[^a-zA-Z0-9!?_ -]+/', '', $name[1]);
                     if ($name[1] != $dname) {
                         $this->say('Invalid note name. Names can contain the characters A-Z, a-z, 0-9, !, ?, _ and - only.');
                         return;
                     }
                     // Cut it off the message.
                     $message = preg_replace('/ @ ' . preg_quote($dname) . '/', '', $message);
                 }
                 // Add the note.
                 $note = array('name' => $dname, 'note' => $message);
                 // Count it.
                 $count = !empty($this->notes[$user]) ? end(array_keys($this->notes[$user])) + 1 : 1;
                 $this->notes[$user][$count] = $note;
                 $this->say('Note ' . $dname . ' set with ID ' . $count . '. You can use "' . $this->bot->commandPrefix . 'note list" to view your saved notes, or "' . $this->bot->commandPrefix . 'note show ' . $count . '" to show this specific note.');
         }
     }
 }
Exemplo n.º 3
0
 /**
  * This is the workhorse function, grabs the data from the server and displays on the browser
  *
  * @author Super3 <*****@*****.**>
  * @author Daniel Siepmann <*****@*****.**>
  */
 private function main()
 {
     // And fire up a connection.
     $this->log('Main loop ignited! GO GO GO!', 'STARTUP');
     do {
         foreach ($this->reminders as $time => $reminder) {
             if (time() >= $time) {
                 $this->sendDataToServer('PRIVMSG #wildphp :' . $this->reminders[$time]);
                 unset($this->reminders[$time]);
             }
         }
         $command = '';
         $arguments = array();
         $data = $this->connection->getData();
         // Check for some special situations and react:
         // The nickname is in use, create a now one using a counter and try again.
         if (stripos($data, 'Nickname is already in use.') !== false && \Library\FunctionCollection::getUserNickName($data) == $this->nickserv) {
             $this->nickToUse = $this->nick . ++$this->nickCounter;
             $this->sendDataToServer('NICK ' . $this->nickToUse);
         }
         // We're welcome without password or identified with password. Lets join.
         if (empty($this->password) && stripos($data, 'Welcome') !== false || !empty($this->password) && stripos($data, 'You are now identified') && \Library\FunctionCollection::getUserNickName($data) == $this->nickserv) {
             $this->join_channel($this->channel);
         }
         // Something realy went wrong.
         if (stripos($data, 'Registration Timeout') !== false || stripos($data, 'Erroneous Nickname') !== false || stripos($data, 'Closing Link') !== false) {
             // If the error occurs to often, create a log entry and exit.
             if ($this->numberOfReconnects >= (int) $this->maxReconnects) {
                 $this->log('Closing Link after "' . $this->numberOfReconnects . '" reconnects.', 'EXIT');
                 exit;
             }
             // Notice the error.
             $this->log($data, 'CONNECTION LOST');
             // Wait before reconnect ...
             sleep(60 * 1);
             ++$this->numberOfReconnects;
             // ... and reconnect.
             $this->connection->connect();
             return;
         }
         // Get the response from irc:
         $args = explode(' ', $data);
         if (!empty($data)) {
             $this->log($data);
         }
         // Play ping pong with server, to stay connected:
         if ($args[0] == 'PING') {
             $this->sendDataToServer('PONG ' . $args[1]);
         }
         // Try to flush log buffers, if needed.
         $this->log->intervalFlush();
         // Nothing new from the server, step over.
         if ($args[0] == 'PING' || !isset($args[1])) {
             unset($data, $args);
             continue;
         }
         if (isset($args[3])) {
             // Explode the server response and get the command.
             // $source finds the channel or user that the command originated.
             $source = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[2])), 0);
             $command = substr(trim(\Library\FunctionCollection::removeLineBreaks($args[3])), 1);
             // Someone PMed me? Oh noes.
             if ($source == $this->nickToUse && $args[1] == 'PRIVMSG') {
                 $source = \Library\FunctionCollection::getUserNickName($args[0]);
             }
             $this->source = $source;
             $arguments = array_slice($args, 4);
             // Check if the response was a command.
             if (stripos($command, $this->commandPrefix) === 0) {
                 $command = ucfirst(substr($command, strlen($this->commandPrefix)));
                 // Command does not exist:
                 if (!$this->commandManager->commandExists($command)) {
                     $this->log('The following, not existing, command was called: "' . $command . '".', 'MISSING');
                     continue;
                 }
                 $this->commandManager->executeCommand($source, $command, $arguments, $data);
             }
         }
         // Call the listeners!
         $this->listenerManager->listenerHook($args, $data);
         unset($data, $args);
     } while (true);
 }