Ejemplo n.º 1
0
 /**
  * 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();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function validateEventExists($attribute, $value, $parameters)
 {
     try {
         $event = GameEvent::where('id', $value)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     date_default_timezone_set('America/Chicago');
     if (\App::environment() != 'production') {
         DB::table('game_events')->truncate();
         DB::table('attendees')->truncate();
     }
     \Onyx\Destiny\Objects\GameEvent::create(['title' => 'Trials Run', 'type' => 'ToO', 'start' => \Carbon\Carbon::now()->addDay()]);
     \Onyx\Destiny\Objects\GameEvent::create(['title' => 'Crota Normal', 'type' => 'Raid', 'start' => \Carbon\Carbon::now()->addDay(4)]);
 }
Ejemplo n.º 4
0
 public function postAddEvent()
 {
     $all = $this->request->all();
     if (isset($all['google_id'])) {
         try {
             $user = User::where('google_id', $all['google_id'])->where('admin', true)->firstOrFail();
             $gameEvent = new GameEvent();
             $gameEvent->fill($all);
             $gameEvent->save();
             // now lets set max_players
             $gameEvent->max_players = $gameEvent->getPlayerDefaultSize($gameEvent->type);
             $gameEvent->save();
             $msg = 'This event was created. There are <strong>' . $gameEvent->max_players . '</strong> spots left. You may apply online <a href="' . \URL::action('CalendarController@getEvent', [$gameEvent->id]) . '">here</a>.';
             $msg .= ' or you can apply via the bot via <strong>/bot rsvp ' . $gameEvent->id . '</strong>';
             return Response::json(['error' => false, 'msg' => $msg], 200);
         } catch (ModelNotFoundException $e) {
             return $this->_error('User does not have permission to make events.');
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @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;
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 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.');
     }
 }