/** * @return Response */ public function voteCmd() { $stores = $this->getStores(); if (empty($stores)) { // init the vote automatically $this->sendRoomMsg($this->initCmd()); } $votes = $this->getRequest()->getArgs(); // remove cmd array_shift($votes); $userMention = $this->getRequest()->getUser()->getMentionName(); $userVotes = $this->getVotes() ?: []; if (empty($votes)) { if (isset($userVotes[$userMention])) { unset($userVotes[$userMention]); $this->saveVotes($userVotes); $this->sendRoomMsg(Response::createSuccess('Successfully removed your vote!')); } $this->addAbstain($userMention); return !empty($userVotes) ? $this->statusCmd() : null; } $defaultStores = $this->getStores(); foreach ($votes as $key => $vote) { if (!isset($defaultStores[$vote])) { $closestMatch = $this->autoCorrectStore($vote); if (null === $closestMatch) { return Response::createError(sprintf('Invalid store: `%s` - Check the available stores using the `stores` command!', $vote)); } // replace the unknown store with the closest match $votes[$key] = $closestMatch; } } $userVotes[$userMention] = $votes; $this->saveVotes($userVotes); $this->removeAbstain($userMention); return $this->statusCmd(); }
public function testCreateSuccess() { $response = Api\Response::createSuccess('msg', Api\Response::FORMAT_HTML); $this->assertSame(['color' => Api\Response::COLOR_GREEN, 'message' => '(successful) msg', 'message_format' => Api\Response::FORMAT_HTML, 'notify' => false], $response->toArray()); }