public function actionGetBots(Request $request, $botId) { $response = array('status' => false); try { $brainPath = __DIR__ . '/../../../app/brains/'; $files = glob($brainPath . (empty($botId) ? '*' : $botId), GLOB_ONLYDIR); if (empty($files)) { return $this->render(array('status' => true, 'data' => '', 'message' => 'No bot available')); } $response = array('status' => true); $data = array(); foreach ($files as $file) { $bot = array(); $identityFile = $file . '/identity.json'; if (is_file($identityFile) && null != ($identity = loadJsonFile($identityFile, 'UTF-8'))) { $bot['id'] = $identity->id; $bot['name'] = $identity->name; $bot['pseudo'] = !empty($identity->pseudo) ? $identity->pseudo : ucfirst($identity->name); $bot['conceptorName'] = !empty($identity->conceptorName) ? $identity->conceptorName : 'the Ancients'; $bot['birth'] = new \DateTime($identity->birthday); $bot['timezone'] = @$identity->timezone; $bot['desc'] = $bot['name'] . (!empty($identity->pseudo) ? ' alias ' . $identity->pseudo : '') . ': made the ' . $bot['birth']->format('jS \\o\\f F Y') . ' by ' . $bot['conceptorName']; } else { $bot['name'] = $file; $bot['message'] = 'No identity description for this bot...'; } $data[] = $bot; } $response['data'] = $data; } catch (\Exception $e) { $response['message'] = 'Error during process: ' . $e->getMessage(); } return $this->render($response); }
private function loadIdentity($identityPath) { if (!is_file($identityPath)) { return false; } $identity = loadJsonFile($identityPath); if (key_exists('name', $identity)) { $this->name = $identity->name; } if (key_exists('pseudo', $identity)) { $this->pseudo = $identity->pseudo; } if (key_exists('avatar', $identity)) { $this->avatar = $identity->avatar; } if (key_exists('conceptorName', $identity)) { $this->conceptorName = $identity->conceptorName; } if (key_exists('birthday', $identity)) { $this->setBirthday($identity->birthday); } if (key_exists('timezone', $identity)) { $this->setTimezone($identity->timezone); } if (key_exists('charset', $identity)) { $this->charset = $identity->charset; } if (key_exists('outputDecoration', $identity)) { $this->outputDecoration = $identity->outputDecoration; } if (key_exists('triggers', $identity)) { $this->triggers = $identity->triggers; } if (key_exists('positrons', $identity)) { $this->positrons = $identity->positrons; } return true; }