/** * @return Response */ public function sayCmd() { $emoticons = ['sap', 'rebeccablack', 'shrug', 'yey', 'zoidberg', 'yuno', 'wat']; shuffle($emoticons); $message = sprintf('(%s) Hello %s and World! (%s)', $emoticons[0], $this->getRequest()->getUser()->getName(), $emoticons[1]); $this->sendRoomMsg(Response::create('(fry)(giggity)(haha) Addon Response! (fry)(giggity)(haha)')); return Response::create($message, null, Response::COLOR_RANDOM); }
/** * @return Response */ public function cryptCmd() { $command = $this->getRequest()->getPackage(); $args = $this->getRequest()->getArgs(); $type = strtolower(array_shift($args)); $method = $command . ucfirst($type); if (!method_exists($this, $method)) { return Response::createError('Operation not supported!'); } try { $result = $this->{$method}(implode('', $args)); } catch (Exception\CorruptDataException $e) { return Response::createError(sprintf('Could not %s the %s data.', $command, $type)); } return Response::create(sprintf('%s: %s', strtoupper($type), $result)); }
/** * @return Response */ public function wikiCmd() { $language = $this->getRequest()->getArg(1) ?: $this->getOption('default_wiki_language', 'en'); if (strlen($language) !== 2) { return Response::createError('The language must be 2 characters.'); } $url = sprintf('https://%s.wikipedia.org/w/api.php?action=query&generator=random&grnnamespace=0&prop=info&inprop=url&formatversion=2&format=json', $language); $response = $this->getHttpClient()->get($url); if ($response->getStatusCode() !== 200) { return Response::createError('There was an error while talking to Wikipedia. Please try again.'); } $json = $response->json(); $title = $json['query']['pages'][0]['title']; $fullUrl = $json['query']['pages'][0]['fullurl']; return Response::create(sprintf('%s - %s', $title, $fullUrl), null, Response::COLOR_RANDOM); }
/** * @param Api\Response $response */ public function sendRoomMsg(Api\Response $response) { $uri = sprintf('room/%d/notification', $this->request->getRoom()->getId()); $this->client->send($uri, $response->toArray()); }
/** * @return Response */ public function statusCmd() { $stores = $this->getStores(); $userVotes = $this->getVotes(); $abstains = $this->getAbstains(); if (empty($userVotes) && empty($abstains)) { return Response::create('Nobody voted yet!'); } $matrix = [[null]]; foreach ($stores as $storeKey => $store) { $matrix[] = [$storeKey => $store]; } $i = 0; foreach ($userVotes as $user => $votes) { $matrix[0][$i + 1] = $user; $uvi = 1; foreach ($stores as $storeKey => $store) { $matrix[$uvi][$i + 1] = in_array($storeKey, $votes, true); $uvi++; } $i++; } return Response::create($this->renderMatrix($matrix), Response::FORMAT_HTML); }
/** * @return Response */ public function doCmd() { return Response::create('Dummy!'); }
public function testCreateError() { $response = Api\Response::createError('msg', Api\Response::FORMAT_TEXT); $this->assertSame(['color' => Api\Response::COLOR_RED, 'message' => '(failed) msg', 'message_format' => Api\Response::FORMAT_TEXT, 'notify' => false], $response->toArray()); }