public function handleDevansHelpCommand(Event $event, Queue $queue)
 {
     $messages = ['Usage: devans'];
     foreach ($messages as $message) {
         $queue->ircPrivmsg($event->getSource(), $message);
     }
 }
 public function queryExpressHelp(Event $event, Queue $queue)
 {
     $msg = "Usage: [ ";
     foreach ($this->commands as $command) {
         $msg .= $command . ' ';
     }
     $msg .= '] [Express ID] -- Query the express status for given ID.';
     $queue->ircPrivmsg($event->getSource(), $msg);
 }
 /**
  * Responds with a magic eight ball phrase when asked questions
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleEvent(Event $event, Queue $queue)
 {
     if ($event instanceof UserEvent) {
         $nick = $event->getNick();
         $channel = $event->getSource();
         $params = $event->getParams();
         $text = $params['text'];
         $matched = stripos($text, '8 ball') !== false;
         if ($matched) {
             $msg = $nick . ', the magic 8 ball says "' . $this->getMagicEightBallAnswer() . '"';
             $queue->ircPrivmsg($channel, $msg);
         }
     }
 }
 /**
  * Handles a failed fetch of tweet data.
  *
  * @param \Exception $error
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleError(\Exception $error, Event $event, Queue $queue)
 {
     $this->logger->debug('Received error', array('error' => $error));
     $message = 'Error fetching tweet: ' . get_class($error) . ': ' . $error->getMessage();
     $queue->ircPrivmsg($event->getSource(), $message);
 }
 /**
  * Handles a successful request for video data.
  *
  * @param string $url URL of the request
  * @param \GuzzleHttp\Message\Response $data Response body
  * @param \Phergie\Irc\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function resolve($url, \GuzzleHttp\Message\Response $data, Event $event, Queue $queue)
 {
     $logger = $this->getLogger();
     $json = json_decode($data->getBody());
     $logger->info('resolve', array('url' => $url, 'json' => $json));
     if (isset($json->error)) {
         return $logger->warning('Query response contained an error', array('url' => $url, 'error' => $json->error));
     }
     $entries = $json->items;
     if (!is_array($entries) || !$entries) {
         return $logger->warning('Query returned no results', array('url' => $url));
     }
     $entry = reset($entries);
     $replacements = $this->getReplacements($entry);
     $message = str_replace(array_keys($replacements), array_values($replacements), $this->responseFormat);
     $queue->ircPrivmsg($event->getSource(), $message);
 }
 /**
  * Bigstock Command Help
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleBigstockHelp(Event $event, Queue $queue)
 {
     $messages = ['Usage: bigstock queryString', 'queryString - the search query (all words are assumed to be part of message)', 'Searches Bigstock for an image based on the provided query string.'];
     foreach ($messages as $message) {
         $queue->ircPrivmsg($event->getSource(), $message);
     }
 }
 /**
  * Terminates the connection to a server from which a quit command is
  * received.
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleQuitCommand(CommandEvent $event, EventQueueInterface $queue)
 {
     $message = sprintf($this->message, $event->getNick());
     $queue->ircQuit($message);
 }
 /**
  * Handles a successful request for video data.
  *
  * @param string $url URL of the request
  * @param \GuzzleHttp\Message\Response $data Response body
  * @param \Phergie\Irc\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function resolve($url, \GuzzleHttp\Message\Response $data, Event $event, Queue $queue)
 {
     $logger = $this->getLogger();
     $json = json_decode($data->getBody());
     $logger->info('resolve', ['url' => $url, 'json', $json]);
     if (isset($json->error)) {
         return $logger->warning('Twitch response error', ['url' => $url, 'error' => $json->error, 'message' => $json->message]);
     }
     if (null === $json->stream) {
         return $queue->ircPrivmsg($event->getSource(), "Stream is offline");
     }
     $replacements = $this->getReplacements($json);
     $message = str_replace(array_keys($replacements), array_values($replacements), $this->responseFormat);
     $queue->ircPrivmsg($event->getSource(), $message);
 }
 /**
  * Responds to server ping events.
  *
  * @param \Phergie\Irc\Event\EventInterface $event Ping event to respond to 
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function pong(EventInterface $event, EventQueueInterface $queue)
 {
     $params = $event->getParams();
     $queue->ircPong($params['server1']);
 }
 /**
  * Joins the provided list of channels.
  *
  * @param mixed $dummy Unused, as it only matters that one of the
  *        subscribed events has occurred, not what it is
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function joinChannels($dummy, EventQueueInterface $queue)
 {
     $queue->ircJoin($this->channels, $this->keys);
 }
 /**
  * Completes the ghost process.
  *
  * @param \Phergie\Irc\Event\ServerEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleGhost(ServerEvent $event, Queue $queue)
 {
     if ($this->ghostNick === null) {
         return;
     }
     // Attempt to kill the ghost connection
     $queue->ircPrivmsg($this->botNick, 'GHOST ' . $this->ghostNick . ' ' . $this->password);
 }
 /**
  * Handle the help command
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleCommandHelp(Event $event, Queue $queue)
 {
     foreach ($this->getHelpLines() as $helpLine) {
         $queue->ircPrivmsg($event->getSource(), $helpLine);
     }
 }
Exemple #13
0
 /**
  * @param CommandEventInterface $event
  * @param EventQueueInterface $queue
  *
  * @throws \BadMethodCallException
  */
 public function handleDnsCommand(CommandEventInterface $event, EventQueueInterface $queue)
 {
     if (get_class($event) !== '\\Phergie\\Irc\\Plugin\\React\\Command\\CommandEvent' && get_class($event) !== 'Phergie\\Irc\\Plugin\\React\\Command\\CommandEvent' && !is_subclass_of($event, '\\Phergie\\Irc\\Plugin\\React\\Command\\CommandEvent')) {
         throw new \BadMethodCallException(get_class($event) . ' given, expected: Phergie\\Irc\\Plugin\\React\\Command\\CommandEvent');
     }
     foreach ($event->getCustomParams() as $hostname) {
         $this->logDebug('Looking up: ' . $hostname);
         $this->resolveDnsQuery(new Query($hostname, function ($ip, $hostname) use($event, $queue) {
             $message = $hostname . ': ' . $ip;
             $this->logDebug($message);
             foreach ($event->getTargets() as $target) {
                 $queue->ircPrivmsg($target, $message);
             }
         }, function ($error, $hostname) use($event, $queue) {
             $message = $hostname . ': error looking up hostname: ' . $error->getMessage();
             $this->logDebug($message);
             foreach ($event->getTargets() as $target) {
                 $queue->ircPrivmsg($target, $message);
             }
         }));
     }
 }
 /**
  * Handle primary nick recovery.
  *
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleQuit(UserEvent $event, Queue $queue)
 {
     $nick = $event->getNick();
     if ($this->primaryNick !== null && $nick == $this->primaryNick) {
         $this->logger->debug("[AltNick] '{$nick}' disconnected, switching to primary nick");
         $queue->ircNick($this->primaryNick);
         $this->primaryNick = null;
     }
 }
 /**
  * Modifies a term's karma.
  *
  * @param string $term   Term to modify
  * @param string $action Karma action (either ++ or --)
  * @param \Phergie\Irc\Event\UserEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  * @return bool|\React\Promise\Promise
  */
 protected function modifyKarma($term, $action, UserEvent $event, Queue $queue)
 {
     $nick = $event->getNick();
     $canonicalTerm = $this->getCanonicalTerm($term, $nick);
     if ($canonicalTerm == strtolower($nick)) {
         $message = 'You can\'t give yourself karma.';
         $queue->ircPrivmsg($event->getSource(), $message);
         return false;
     }
     $karma = 0;
     return $this->messenger->rpc(MessageFactory::rpc('fetchKarma', ['term' => $canonicalTerm]))->then(function ($payload) use($event, $queue, $action, $term, $canonicalTerm, &$karma) {
         $this->logDebug('payload: ' . var_export($payload, true));
         $karma = $payload['karma'] + ($action == '++' ? 1 : -1);
         return MessageFactory::rpc('modifyKarma', ['term' => $canonicalTerm, 'karma' => $karma]);
     })->then([$this->messenger, 'rpc'])->then(function ($payload) use($event, $queue, $action, $term) {
         $this->logDebug('payload: ' . var_export($payload, true));
         $queue->ircPrivmsg($event->getSource(), $this->getUserMessage('karma' . $action, $term));
         return $payload['karma'];
     });
 }
 /**
  * Handles help for the seen command.
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleCommandHelp(CommandEvent $event, Queue $queue)
 {
     $queue->ircPrivmsg($event->getSource(), "Usage: seen <nickname>");
 }
 /**
  * Handles a failed request for weather information.
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function reject(Event $event, Queue $queue)
 {
     $target = $event->getSource();
     $nick = $event->getNick();
     $response = 'I CAN\'T GET THE FUCKING WEATHER.';
     if ($target != $nick) {
         $response = $nick . ': ' . $response;
     }
     $queue->ircPrivmsg($target, $response);
 }
 /**
  * Handles command calls
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleCommand(CommandEventInterface $event, EventQueueInterface $queue)
 {
     $params = $event->getCustomParams();
     if (count($params) < 2) {
         $queue->ircNotice($event->getNick(), 'Can\'t identify nickname or message.');
         $this->helpMessages([$queue, 'ircNotice'], $event->getNick(), $event->getCustomCommand());
     } else {
         $message = implode(' ', array_slice($params, 1));
         if ($this->database->postMessage($event->getNick(), $params[0], $message)) {
             $queue->ircNotice($event->getNick(), 'Ok, I\'ll tell him/her.');
         } else {
             $queue->ircNotice($event->getNick(), 'Sry, There\'s so many things to tell him/her.');
         }
     }
 }
 /**
  * Joins a channel if nickname and channel matches the own nickname
  * and a channel in 'channels' configuration respectively.
  *
  * @param string $nickname
  * @param \Phergie\Irc\Event\UserEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function joinOnMatch($nickname, UserEventInterface $event, EventQueueInterface $queue)
 {
     if ($nickname == $event->getConnection()->getNickname() && ($index = array_search($event->getSource(), $this->channels)) !== false) {
         $queue->ircJoin($this->channels[$index], $this->keys ? $this->keys[$index] : null);
     }
 }
 /**
  * Nick is in use, pick another.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function handleEvent(Event $event, Queue $queue)
 {
     $iterator = $this->getIterator($event->getConnection());
     if (!$iterator->valid()) {
         $queue->ircQuit('All specified alternate nicks are in use');
         return;
     }
     $nick = $iterator->current();
     $iterator->next();
     $this->logger->debug("[AltNick] Switching nick to '{$nick}'");
     $queue->ircNick($nick);
     $event->getConnection()->setNickname($nick);
 }
 /**
  * Send a single response line back to IRC
  *
  * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  * @param string $ircResponseLine
  */
 protected function sendIrcResponseLine(Event $event, Queue $queue, $ircResponseLine)
 {
     $queue->ircPrivmsg($event->getSource(), $ircResponseLine);
 }
 /**
  * Generates the chanmode/prefix maps and enables NAMESX if supported.
  *
  * @param \Phergie\Irc\Event\ServerEventInterface $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  */
 public function processCapabilities(ServerEventInterface $event, EventQueueInterface $queue)
 {
     $connection = $event->getConnection();
     $logger = $this->getLogger();
     $store = $this->connectionStore;
     if (!$store->contains($connection)) {
         $store->attach($connection, new \ArrayObject());
     }
     foreach ($event->getParams()['iterable'] as $param) {
         if ($param == 'NAMESX') {
             $queue->ircProtoctl('NAMESX');
         } elseif (preg_match('/^CHANMODES=([^,]*),((?1)),((?1)),((?1))$/', $param, $matches)) {
             $logger->debug('Parsing chanmode types from RPL_ISUPPORT');
             $chanModeTypes = [];
             foreach (array(1 => self::CHANMODE_TYPE_LIST, 2 => self::CHANMODE_TYPE_PARAM_ALWAYS, 3 => self::CHANMODE_TYPE_PARAM_SETONLY, 4 => self::CHANMODE_TYPE_NOPARAM) as $index => $type) {
                 if (!empty($matches[$index])) {
                     $chanModeTypes += array_fill_keys(str_split($matches[$index]), $type);
                 }
             }
             if (!empty($store[$connection]['modes'])) {
                 $chanModeTypes += $store[$connection]['modes'];
             }
             $store[$connection]['modes'] = $chanModeTypes;
         } elseif (preg_match('/^PREFIX=\\((\\S+)\\)(\\S+)$/', $param, $matches) && strlen($matches[1]) == strlen($matches[2])) {
             $logger->debug('Parsing prefixes from RPL_ISUPPORT');
             $prefixModes = str_split($matches[1]);
             $store[$connection]['prefixes'] = array_combine(str_split($matches[2]), $prefixModes);
             $chanModeTypes = array_fill_keys($prefixModes, self::CHANMODE_TYPE_PARAM_ALWAYS);
             if (!empty($store[$connection]['modes'])) {
                 $chanModeTypes += $store[$connection]['modes'];
             }
             $store[$connection]['modes'] = $chanModeTypes;
         }
     }
 }