/** * Get the url for the API request * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @return string */ public function getApiRequestUrl(Event $event) { $params = $event->getCustomParams(); $query = trim(implode(" ", $params)); $querystringParams = ['v' => '1.0', 'q' => $query]; return sprintf("%s?%s", $this->apiUrl, http_build_query($querystringParams)); }
/** * Return the url for the API request * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * * @return string */ public function getApiRequestUrl(Event $event) { $params = $event->getCustomParams(); $query = trim(implode(" ", $params)); $querystringParams = array('q' => $query, 'appid' => $this->appId); return sprintf("%s?%s", $this->apiUrl, http_build_query($querystringParams)); }
/** * Responds to a help command. * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue * @param array $messages */ protected function sendHelpReply(Event $event, Queue $queue, array $messages) { $method = 'irc' . $event->getCommand(); $target = $event->getSource(); foreach ($messages as $message) { $queue->{$method}($target, $message); } }
/** * Displays help information for the quit command. * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleQuitHelp(CommandEvent $event, EventQueueInterface $queue) { $messages = array('Usage: quit', 'Requests that the bot terminate its connection to the current server.', 'See https://tools.ietf.org/html/rfc2812#section-3.1.7'); $method = 'irc' . $event->getCommand(); $target = $event->getSource(); foreach ($messages as $message) { $queue->{$method}($target, $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); }
/** * Return the url for the API request * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @return string */ public function getApiRequestUrl(Event $event) { $params = $event->getCustomParams(); // Final parameter should be the country $country = $params[count($params) - 1]; // Remove the final paramater unset($params[count($params) - 1]); // Merge the remainder of the supplied params and remove disallowed punctuation $place = trim(implode("_", preg_replace('/[^\\da-z\\ ]/i', '', $params))); return sprintf("%s/%s/conditions/q/%s/%s.json", $this->apiUrl, $this->appId, $country, $place); }
/** * Tests fromEvent(). */ public function testFromEvent() { $event = Phake::mock('\\Phergie\\Irc\\Event\\UserEventInterface'); // EventInterface $message = 'message'; $connection = Phake::mock('\\Phergie\\Irc\\ConnectionInterface'); $params = array('param1', 'param2'); $command = 'command'; Phake::when($event)->getMessage()->thenReturn($message); Phake::when($event)->getConnection()->thenReturn($connection); Phake::when($event)->getParams()->thenReturn($params); Phake::when($event)->getCommand()->thenReturn($command); // UserEventInterface $prefix = 'prefix'; $nick = 'nick'; $username = '******'; $host = 'host'; $targets = array('target1', 'target2'); Phake::when($event)->getPrefix()->thenReturn($prefix); Phake::when($event)->getNick()->thenReturn($nick); Phake::when($event)->getUsername()->thenReturn($username); Phake::when($event)->getHost()->thenReturn($host); Phake::when($event)->getTargets()->thenReturn($targets); $this->event->fromEvent($event); // EventInterface $this->assertSame($message, $this->event->getMessage()); $this->assertSame($connection, $this->event->getConnection()); $this->assertSame($params, $this->event->getParams()); $this->assertSame($command, $this->event->getCommand()); // UserEventInterface $this->assertSame($prefix, $this->event->getPrefix()); $this->assertSame($nick, $this->event->getNick()); $this->assertSame($username, $this->event->getUsername()); $this->assertSame($host, $this->event->getHost()); $this->assertSame($targets, $this->event->getTargets()); }
/** * 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); }
/** * Returns an array of lines to send back to IRC when there are no results * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @return array */ public function getNoResultsLines(Event $event) { return array(sprintf('%s does not exist on libre.fm', $event->getCustomParams()[0])); }
/** * Returns usage information for the command. * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function handleHelp(Event $event, Queue $queue) { $method = 'irc' . $event->getCommand(); $target = $event->getSource(); $messages = array('Usage: thefuckingweather location', 'Returns weather information for the specified location from thefuckingweather.com'); foreach ($messages as $message) { $queue->{$method}($target, $message); } }
/** * 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>"); }
protected function parseReminder(Event $event) { $params = $event->getCustomParams(); $nick = $event->getNick(); if (isset($params[1])) { $name = $params[1]; } else { $name = null; } $source = $event->getSource(); if ($this->forcePMs) { $source = $nick; } $command = 'irc' . $event->getCommand(); unset($params[0]); unset($params[1]); $time = join(" ", $params); return ['nick' => $nick, 'name' => $name, 'source' => $source, 'command' => $command, 'time' => $time]; }
public function handleMessage(UserEvent $event, Queue $queue) { // make sure we don't react twice when the nfo command gets triggered if (strpos($event->getMessage(), 'nfo ') === false) { if (preg_match_all("/[a-z0-9._]{4,}-[a-z0-9]{3,}/i", $event->getMessage(), $matches)) { $matches = array_slice($matches[0], 0, $this->limit); foreach ($matches as $dirname) { $commandEvent = new CommandEvent(); $commandEvent->fromEvent($event); $commandEvent->setCustomParams(array($dirname)); $this->handleNfoCommand($commandEvent, $queue, false); } } } }
/** * Responds to a parameter-less help command with a list of available * commands. * * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ protected function listCommands(CommandEvent $event, EventQueueInterface $queue) { $targets = $event->getTargets(); $target = reset($targets); $nick = $event->getNick(); if ($target === $event->getConnection()->getNickname()) { $target = $nick; $address = ''; } else { $address = $nick . ': '; } $method = 'irc' . $event->getCommand(); $message = $address . $this->listText . implode(' ', $this->commands); $queue->{$method}($target, $message); }
/** * Forwards events for command aliases to handlers for their corresponding * commands. * * @param string $alias * @param string $command * @param string $eventName * @param array $customParameters * @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ public function forwardEvent($alias, $command, $eventName, $customParameters, Event $event, Queue $queue) { if (is_array($customParameters)) { $eventCustomParams = $event->getCustomParams(); if (is_array($eventCustomParams)) { $event->setCustomParams(array_merge($customParameters, $eventCustomParams)); } else { $event->setCustomParams($customParameters); } } $logger = $this->getLogger(); $emitter = $this->getEventEmitter(); $listeners = $emitter->listeners($eventName); if (!$listeners) { $logger->warning('Alias references unknown command', array('alias' => $alias, 'command' => $command)); return; } $logger->debug('Forwarding event', array('event_name' => $eventName, 'alias' => $alias, 'command' => $command)); // Set the event customCommand to match the command being aliased $event->setCustomCommand($command); $emitter->emit($eventName, array($event, $queue)); }