/** * Store a newly created resource in storage. * * @return Response */ public function store() { $s3 = AWS::get('s3'); $s3Bucket = 'buildbrighton-bbms'; if (Request::hasFile('image')) { $file = Request::file('image'); $event = Request::get('textevent'); $time = Request::get('time'); $fileData = Image::make($file)->encode('jpg', 80); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; try { $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256')); } catch (\Exception $e) { \Log::exception($e); } //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); } if (Request::get('eventend') == 'true') { $event = Request::get('textevent'); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName)); $images = []; $imageDurations = []; foreach ($iterator as $object) { $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key']; $imageDurations[] = 35; } if (count($images) <= 2) { //only two images, probably two bad frames //delete them foreach ($iterator as $object) { Log::debug("Deleting small event image " . $object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } return; } $gc = new GifCreator(); $gc->create($images, $imageDurations, 0); $gifBinary = $gc->getGif(); //Delete the individual frames now we have the gif foreach ($iterator as $object) { //Log::debug("Processed gif, deleting frame, ".$object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } //Save the gif $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256')); //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected'); } }
/** * Handle the event. * * @param NewMemberNotification $event * @return void */ public function handle(NewMemberNotification $event) { if (\App::environment('production')) { //If the user doesn't have a slack username registered there is nothing we can do if (empty($event->notification->user()->slack_username)) { return; } \Slack::to($event->notification->user()->slack_username)->send($event->notification->message); $event->notification->update(['notified_method' => 'slack', 'notified_at' => Carbon::now()]); } }
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/', function () { return View::make('hello'); }); Route::any('/inbound/slack/notshinyunicorn/general', function () { $x = Input::all(); $strText = str_replace("<http://", "", $x["text"]); $strText = str_replace("<https://", "", $strText); if (substr($strText, 0, 23) == "open.spotify.com/track/") { $strText = str_replace("open.spotify.com/track/", "", $strText); $strText = str_replace(">", "", $strText); $strTest = file_get_contents("https://api.spotify.com/v1/tracks/" . $strText); $json = $objJSON = json_decode($strTest); $youtube = new \Madcoda\Youtube(array('key' => $_ENV["YOUTUBE_KEY"])); $videoList = $youtube->searchVideos($json->artists[0]->name . " " . $json->name); if (isset($videoList[0]->id->videoId)) { Slack::to('#' . $x["channel_name"])->send("https://www.youtube.com/watch?v=" . $videoList[0]->id->videoId); } else { Slack::to('#' . $x["channel_name"])->send("No match found for Spotify track."); } } });
/** * Send a notification to slack * * @param string $channel * @param string $message */ private function sendSlackNotification($channel, $message) { if (\App::environment('production')) { \Slack::to($channel)->send($message); } }
/** * Slack message * * @param string $message */ protected function slack($message) { \Slack::to(env('SLACK_CHANNEL'))->send('@theviking @simon @nikolajlovenhardt ' . $message); }