/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Rerender content
     $templatedOutput = view('templates.livethreadcontents')->with(['updates' => collect(Redis::lrange('live:updates', 0, -1))->reverse()->map(function ($update) {
         return json_decode($update);
     })])->render();
     // Connect to Reddit
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent('ElongatedMuskrat bot by u/EchoLogic. Runs various /r/SpaceX-related tasks.');
     // Update Thread
     $reddit->thing(Redis::hget('live:reddit', 'thing'))->edit($templatedOutput);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $questions = new Collection();
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent("/u/ElongatedMuskrat by /u/EchoLogic. Runs various /r/SpaceX-related tasks.");
     // Delete all current FAQs
     Question::truncate();
     foreach ($this->faqPages as $faqPage) {
         $wikipage = $reddit->subreddit('spacex')->wikiPage('/faq/' . $faqPage);
         $contents = $wikipage->data->content_md;
         $rawQuestions = explode('###', $contents);
         $i = 0;
         foreach ($rawQuestions as $rawQuestion) {
             if ($i != 0) {
                 $questionParts = explode('?', $rawQuestion, 2);
                 Question::create(array('question' => $questionParts[0] . '?', 'answer' => $questionParts[1], 'type' => $faqPage));
             }
             $i++;
         }
     }
 }
 /**
  * Create a SpaceXStats Live event. Set all the necessary Redis parameters, render a Reddit Thread template,
  * publish it, then broadcast a LiveStartedEvent to notify websocket listeners.
  *
  * @return mixed
  */
 public function create()
 {
     // Turn on SpaceXStats Live
     Redis::set('live:active', true);
     // Set the streams available
     Redis::hmset('live:streams', ['spacex' => json_encode(Input::get('streams.spacex')), 'spacexClean' => json_encode(Input::get('streams.spacexClean')), 'nasa' => json_encode(Input::get('streams.nasa'))]);
     // Set the countdown
     Redis::hmset('live:countdown', ['to' => Input::get('countdown.to'), 'isPaused' => false]);
     // Set the details
     Redis::set('live:title', Input::get('title'));
     Redis::hmset('live:description', ['raw' => Input::get('description.raw'), 'markdown' => Parsedown::instance()->parse(Input::get('description.raw'))]);
     Redis::set('live:isForLaunch', Input::get('isForLaunch'));
     Redis::set('live:resources', json_encode(Input::get('resources')));
     Redis::set('live:sections', json_encode(Input::get('sections')));
     Redis::set('live:status', 'Upcoming');
     // Set the Reddit parameters
     Redis::hmset('live:reddit', ['title' => Input::get('reddit.title')]);
     // Create the canned responses
     Redis::hmset('live:cannedResponses', ['holdAbort' => 'HOLD HOLD HOLD. The countdown has been aborted.', 'terminalCount' => 'Terminal count has now begun. From this point forward, any scrubs will result in a recycle to T-10 minutes.', 'inProgress' => 'Liftoff of ' . Mission::future()->first()->name . '!', 'maxQ' => 'MaxQ, at this point in flight, the vehicle is flying through maximum aerodynamic pressure.', 'MECO' => "MECO! The vehicle's first stage engines have shutdown in preparation for stage separation.", 'stageSep' => 'Stage separation confirmed.', 'mVacIgnition' => "Falcon's upper stage Merlin Vacuum engine has ignited for the ride to orbit.", 'SECO' => 'SECO! Falcon is now in orbit!', 'missionSuccess' => 'Success! SpaceX has completed another successful mission!', 'missionFailure' => 'We appear to have had a failure. We will bring more information to you as it is made available.']);
     // Render the Reddit thread template
     $templatedOutput = view('templates.livethreadcontents')->with(array())->render();
     // Create the Reddit thread (create a service for this)
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent('/u/ElongatedMuskrat by /u/EchoLogic. Runs various /r/SpaceX-related tasks.');
     // Create a post
     $subreddit = App::environment('production') ? 'spacex' : 'echocss';
     $response = $reddit->subreddit($subreddit)->submit(['kind' => 'self', 'sendreplies' => true, 'text' => $templatedOutput, 'title' => Input::get('reddit.title')]);
     Redis::hmset('live:reddit', ['thing' => $response->data->name]);
     // Broadcast event to turn on spacexstats live
     event(new LiveStartedEvent(['active' => true, 'streams' => ['spacex' => Input::get('streams.spacex'), 'spacexClean' => Input::get('streams.spacexClean'), 'nasa' => Input::get('streams.nasa')], 'countdown' => ['to' => Input::get('countdown.to'), 'isPaused' => false], 'title' => Input::get('title'), 'reddit' => ['title' => Input::get('reddit.title'), 'thing' => $response->data->name], 'description' => Redis::hgetall('live:description'), 'isForLaunch' => Input::get('isForLaunch'), 'resources' => Input::get('resources'), 'sections' => Input::get('sections'), 'status' => 'Upcoming', 'cannedResponses' => Redis::hgetall('live:cannedResponses')]));
     // Respond
     return response()->json(null, 204);
 }
 public function retrieveRedditComment()
 {
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent('/u/ElongatedMuskrat by /u/EchoLogic. Runs various /r/SpaceX-related tasks.');
     $comment = $reddit->getComment(Input::get('url'));
     return response()->json($comment);
 }