|
|
@ -0,0 +1,70 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Listeners; |
|
|
|
|
|
|
|
use App\Events\TweetAcceptedEvent; |
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
|
|
use Log; |
|
|
|
use Twitter; |
|
|
|
use App\Tweet; |
|
|
|
|
|
|
|
class TweetAcceptedListener implements ShouldQueue |
|
|
|
{ |
|
|
|
/** |
|
|
|
* Create the event listener. |
|
|
|
* |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function __construct() |
|
|
|
{ |
|
|
|
//
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle the event. |
|
|
|
* |
|
|
|
* @param Event $event |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function handle(TweetAcceptedEvent $event) |
|
|
|
{ |
|
|
|
$tweet = $event->tweet; |
|
|
|
|
|
|
|
// Tweet out when missions are completed
|
|
|
|
$newMissionStatus = $tweet->mission->complete($tweet->team); |
|
|
|
if($event->previousMissionStatus == false && $newMissionStatus == true) { |
|
|
|
|
|
|
|
$text = 'Team '.$tweet->team->name.' completed mission '.$tweet->mission_id.'! '.$tweet->mission->hashtag; |
|
|
|
Log::info("Tweeting: $text"); |
|
|
|
|
|
|
|
$params = [ |
|
|
|
'attachment_url' => 'https://twitter.com/'.$tweet->player->twitter.'/status/'.$tweet->tweet_id, |
|
|
|
'status' => $text |
|
|
|
]; |
|
|
|
Twitter::postTweet($params); |
|
|
|
} |
|
|
|
|
|
|
|
// Tweet about bonus points when a team visits a TC nobody else has been to
|
|
|
|
if($tweet->mission_id == 2 && $tweet->transit_center) { |
|
|
|
|
|
|
|
$this_tc = $tweet->m2_transit_center_id; |
|
|
|
|
|
|
|
$other_teams = Tweet::where('team_id', '!=', $tweet->team_id) |
|
|
|
->where('m2_complete', 1) |
|
|
|
->where('m2_transit_center_id', $this_tc) |
|
|
|
->count(); |
|
|
|
if($other_teams == 0) { |
|
|
|
$text = 'Team '.$tweet->team->name.' is currently the only team to have visited '.$tweet->transit_center->name.'!'; |
|
|
|
Log::info("Tweeting: $text"); |
|
|
|
$params = [ |
|
|
|
'attachment_url' => 'https://twitter.com/'.$tweet->player->twitter.'/status/'.$tweet->tweet_id, |
|
|
|
'status' => $text |
|
|
|
]; |
|
|
|
Twitter::postTweet($params); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |