/** * PRIVMSG event * * @param Kokx_Event $event * * @return void */ public function privmsg(Kokx_Event $event) { $this->_client = $event->getSubject(); $matches = array(); if (preg_match('/^!check (?<nick>' . self::NICK_REGEX . ')/i', $event['message'], $matches)) { // check if a certain nick is confirmed if ($this->_isAuthed($matches['nick'])) { $this->_client->send($matches['nick'] . ' is authed!', $event['target']); // and now check if this user is in the DB too if (null !== $this->_getUserId($matches['nick'])) { $this->_client->send('And of course I know who ' . $matches['nick'] . ' is.', $event['target']); } else { $this->_client->send('But I don\'t actually know who the f*****g f**k ' . $matches['nick'] . ' is.', $event['target']); } } else { $this->_client->send($matches['nick'] . ' fails!', $event['target']); } } else { if (preg_match('/^!add (?<nick>' . self::NICK_REGEX . ') (?<desc>.{10,})/i', $event['message'], $matches)) { // validate, then use the method if ($this->_checkUser($event['nick'], $event['target'], true) && $this->_checkUser($matches['nick'], $event['target'], true)) { // the user is checked, now add its new achievement $user = $this->_getUserId($matches['nick']); $this->_db->getAdapter()->insert('achievements', array('user_id' => $user, 'achievement' => $matches['desc'])); $this->_client->send('New achievement added!', $event['target']); } } else { if (preg_match('/!list( (?<nick>' . self::NICK_REGEX . '))?/i', $event['message'], $matches)) { if (empty($matches['nick'])) { $matches['nick'] = $event['nick']; } // show all the achievements of a user if (null !== ($user = $this->_getUserId($matches['nick']))) { $this->_client->send('The achievements of ' . $matches['nick'] . ':', $event['target']); foreach ($this->_getAchievements($user) as $achievement) { $this->_client->send($achievement['id'] . ': ' . $achievement['achievement'] . ' [' . ($achievement['achieved'] == 'true' ? 'achieved' : 'in progress') . ']', $event['target']); } } else { $this->_client->send('I dunno who the f**k ' . $matches['nick'] . ' is.', $event['target']); } } else { if (preg_match('/^!achieved (?<nick>' . self::NICK_REGEX . ') (?<id>[0-9]+)/i', $event['message'], $matches)) { // first check if this nick is a user if ($matches['nick'] != $event['nick'] && $this->_checkUser($event['nick'], $event['target'], true) && null !== ($user = $this->_getUserId($matches['nick']))) { // the user is checked, now check if he can unlock the achievement $user = $this->_getUserId($matches['nick']); $stmt = $this->_db->getAdapter()->prepare($this->_db->getAdapter()->select()->from('achievements', 'user_id')->where('id=:id')); $stmt->bindParam('id', $matches['id'], Zend_Db::PARAM_INT); $stmt->execute(); // check the achievement if (($achievement = $stmt->fetch(Zend_Db::FETCH_ASSOC)) && $achievement['user_id'] == $user) { $this->_db->getAdapter()->update('achievements', array('achieved' => 'true'), array('id=?' => $matches['id'])); $this->_client->send('ACHIEVEMENT UNLOCKED!!!!!!!!!!!!!!!', $event['target']); } else { $this->_client->send('Someone should unlock the achievement \'EPIC FAIL\' for ' . $event['nick'] . '!', $event['target']); } } } else { if (preg_match('/^!refresh/i', $event['message'])) { $this->_refresh(); $this->_client->send('Finished refreshing the confirmed users list.', $event['target']); } } } } } }
/** * Timer * * @param Kokx_Event $event * * @return void */ public function timer(Kokx_Event $event) { // only run this every 2 secons so we don't overload the server too much if ($this->_lastRun + 2 < time()) { // check if there are new messagesk $this->_lastRun = time(); // check the file $data = trim(file_get_contents($this->_inputFile)); if (empty($data)) { // nothing to see, move along ma'am return; } $data = Zend_Json::decode($data); $client = $event->getSubject(); if (count($data['commits']) == 1) { // Firal: kokx pushed one commit on master ∆ Updated Zend Framework submodule. ∆ http://github.com/kokx/Firal/commit/5b32449e567dbf4d4bb9f8e81954bab0d9640a92 $message = $data['repository']['name'] . ': ' . $data['repository']['owner']['name'] . ' pushed one commit on ' . $this->_getBranch($data) . ' ∆ ' . str_replace(array("\r", "\n"), ' | ', $data['commits'][0]['message']) . ' ∆ ' . $data['commits'][0]['url']; } else { // Firal: kokx pushed 2 commits on master ∆ http://github.com/kokx/Firal/compare/816fee7544eda668...452768c13c94af75e67 $message = $data['repository']['name'] . ': ' . $data['repository']['owner']['name'] . ' pushed ' . count($data['commits']) . ' commits on ' . $this->_getBranch($data) . ' ∆ ' . $data['repository']['url'] . '/compare/' . substr($data['before'], 0, 12) . '...' . substr($data['after'], 0, 12); } $client->send($message, $this->_target); file_put_contents($this->_inputFile, ''); } }
/** * End of the MOTD event * * @param Kokx_Event $event * * @return void */ public function motd(Kokx_Event $event) { $event->getSubject()->send('IDENTIFY ' . $this->_config['password'], $this->_config['nick']); $event->getSubject()->send('op all', $this->_config['csnick']); }