@@ -54,8 +54,45 @@ var onDeckIntent = function(request, response) {
5454 . card ( "TV Shows Ready to Watch" , "On Deck in your TV library: \n\n" + showListCard )
5555 . send ( ) ;
5656 } ) . catch ( function ( err ) {
57- app . skill . error ( err , request , response ) ;
58- } ) ;
57+ app . skill . error ( err , request , response ) ;
58+ } ) ;
59+
60+ return false ;
61+ } ;
62+
63+ var recentlyAddedIntent = function ( request , response ) {
64+ function titleCase ( string ) {
65+ return string ? string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) : string ;
66+ }
67+
68+ var app = request . data . _plex_app ;
69+ var libraryType = request . slot ( 'libraryType' , null ) ;
70+ var library ;
71+
72+ if ( libraryType === 'tv shows' || libraryType === 'shows' ) {
73+ library = app . user . TVLibrary ;
74+ } else if ( libraryType === 'movies' || libraryType === 'films' ) {
75+ library = app . user . MovieLibrary ;
76+ }
77+
78+ plexutils . getRecentlyAdded ( app , library )
79+ . then ( plexutils . getShowNamesFromList )
80+ . then ( function ( mediaList ) {
81+ if ( mediaList . length === 0 ) {
82+ return response . say ( "You have not added any media recently!" ) . send ( ) ;
83+ }
84+
85+ var showListCard = mediaList . join ( '\n' ) ;
86+ var showSpokenListHyphenated = utils . buildNaturalLangList ( mediaList , 'and' , true ) ;
87+ var libraryTypeTitle = ( "Recently Added " + ( titleCase ( libraryType ) || '' ) ) . trim ( ) ;
88+
89+ return response . say ( libraryTypeTitle + ": " + showSpokenListHyphenated + '.' )
90+ . card ( libraryTypeTitle , showListCard )
91+ . send ( ) ;
92+ } )
93+ . catch ( function ( err ) {
94+ app . skill . error ( err , request , response ) ;
95+ } ) ;
5996
6097 return false ;
6198} ;
@@ -220,6 +257,7 @@ var noIntent = function(request,response) {
220257module . exports = {
221258 intents : {
222259 'OnDeckIntent' : onDeckIntent ,
260+ 'RecentlyAddedIntent' : recentlyAddedIntent ,
223261 'StartShowIntent' : startShowIntent ,
224262 'StartRandomShowIntent' : startRandomShowIntent ,
225263 'StartSpecificEpisodeIntent' : startSpecificEpisodeIntent ,
0 commit comments