/** * Execute the console command. * * @return mixed */ public function handle() { $events = GameEvent::where('start', '>=', Carbon::now('America/Chicago'))->orderBy('start', 'ASC')->get(); $messenger = new Messages(); if (count($events) > 0) { foreach ($events as $event) { $this->info('Checking event: ' . $event->title); $diff = $event->start->diffInSeconds(Carbon::now('America/Chicago')); $this->info('Event happens in ' . $diff . ' seconds.'); if (!$event->alert_15) { if ($diff <= $this->seconds_in_15minutes) { $this->info('Alerting members of fireteam, that its 15 minutes before event'); foreach ($event->attendees as $attendee) { $user = $attendee->user; $messenger->sendMessage($user, '<strong>The Event: <i> (' . $event->getHumanType() . ') ' . $event->title . '</i></strong> starts in about 15 minutes.<br /><br /><i>You RSVP`d to this Event, which is why you are being alerted</i>.'); } $event->alert_15 = true; $event->save(); } } if (!$event->alert_5) { if ($diff <= $this->seconds_in_5minutes) { $this->info('Alerting members of fireteam, that its 5 minutes before event.'); foreach ($event->attendees as $attendee) { $user = $attendee->user; $messenger->sendMessage($user, '<strong>The Event: <i> (' . $event->getHumanType() . ') ' . $event->title . '</i></strong> starts in about 5 minutes.<br /><br /><i>You RSVP`d to this Event, which is why you are being alerted</i>.'); } $event->alert_5 = true; $event->save(); } } } } }
public function validateEventExists($attribute, $value, $parameters) { try { $event = GameEvent::where('id', $value)->firstOrFail(); } catch (ModelNotFoundException $e) { return false; } return true; }
public function getEvent($id) { try { $event = GameEvent::where('id', intval($id))->firstOrFail(); $msg = MessageGenerator::buildSingleEventResponse($event); return Response::json(['error' => false, 'msg' => $msg]); } catch (ModelNotFoundException $e) { return $this->_error('This game could not be found.'); } }
/** * @param $user * @param $all * @return string */ public static function buildRSVPResponse($user, $all) { $msg = ''; // Lets check if char_id is 0, if so. Let the user know of their chars with numbers to pick one. if (intval($all['char_id']) == 0) { $count = 0; $msg = 'I need to know which character you want to be <strong>' . $user->account->gamertag . '</strong> for this event. Below are your characters with a number next to them. <br /><br />'; foreach ($user->account->destiny->characters as $char) { $msg .= ++$count . ". - " . $char->name() . " " . $char->highest_light . "/" . $char->light . "<br />"; } $msg .= '<br />Your new command will be <strong>/bot rsvp ' . $all['game_id'] . ' #</strong> Where # is one of the numbers above.'; } else { // does this char even exist $char = $user->account->destiny->characterAtPosition($all['char_id']); if ($char instanceof Character) { try { $event = GameEvent::where('id', intval($all['game_id']))->firstOrFail(); if ($event->isFull()) { $msg = 'Ouch sorry man. This event is Full. No more RSVPs allowed'; } else { if ($event->isAttending($user)) { $msg = 'O think your slick eh? You are already attending this event. There is nothing you need to do.'; } else { if ($event->isOver()) { $msg = 'Sorry this event is over. No more RSVPs are allowed.'; } else { $attendee = new Attendee(); $attendee->game_id = $event->id; $attendee->membershipId = $user->account->destiny_membershipId; $attendee->characterId = $char->characterId; $attendee->account_id = $user->account->id; $attendee->user_id = $user->id; $attendee->save(); $msg = 'Congrats <strong> ' . $user->account->gamertag . '</strong> you have sealed a spot in this '; $msg .= '<a href="' . \URL::action('CalendarController@getEvent', [$event->id]) . '">event</a>. There are <strong>' . ($event->spotsRemaining() - 1) . '</strong> spots remaining.'; } } } } catch (ModelNotFoundException $e) { $msg = 'Sorry to break the news to you, but this event does not exist. Please try a different gameId.'; } } else { $count = 0; $msg = 'Trying to be funny I see. That character does not exist for you. I guess I have to remind you. <br /><br />'; foreach ($user->account->destiny->characters as $char) { $msg .= ++$count . ". - " . $char->name() . " " . $char->highest_light . "/" . $char->light . "<br />"; } $msg .= '<br />Your new command will be <strong>/bot rsvp ' . $all['game_id'] . ' #</strong> Where # is one of the numbers above.'; } } return $msg; }
public function postRsvpEvent(AddRSVP $request) { $game_id = $request->get('game_id'); try { $event = GameEvent::where('id', intval($game_id))->firstOrFail(); $attendee = new Attendee(); $attendee->game_id = $event->id; $attendee->membershipId = $this->user->account->destiny_membershipId; $attendee->characterId = $request->get('character'); $attendee->account_id = $this->user->account->id; $attendee->user_id = $this->user->id; $attendee->save(); // hit bot if (app()->environment() == "production") { $messenger = new Messages(); $messenger->sendGroupMessage('<strong>' . $this->user->account->gamertag . '</strong> confirmed RSVP to event: <strong>' . $event->title . '</strong>'); } return \Redirect::action('CalendarController@getEvent', [$event->id])->with('flash_message', ['type' => 'success', 'header' => 'RSVP Confirmed!']); } catch (ModelNotFoundException $e) { return false; } }