@@ -41,8 +41,10 @@ module.exports = {
4141
4242 switch ( subcommand ) {
4343 case "view" :
44- if ( library . length === 0 ) return client . sendErrorNotification ( interaction , `${ lang . ERROR_LIBRARY_NO_ITEM } ` ) ;
45- if ( ! client . handleCooldown ( "libraryCommand" , user . id , 4000 ) ) return client . sendErrorNotification ( interaction , `${ lang . ERROR_ACTION_NOT_POSSIBLE } ` ) ;
44+ if ( library . length === 0 )
45+ return client . sendErrorNotification ( interaction , `${ lang . ERROR_LIBRARY_NO_ITEM } ` ) ;
46+ if ( ! client . handleCooldown ( "libraryCommand" , user . id , 4000 ) )
47+ return client . sendErrorNotification ( interaction , `${ lang . ERROR_ACTION_NOT_POSSIBLE } ` ) ;
4648 await interaction . deferReply ( { ephemeral : true } ) . catch ( ( error ) => { } ) ;
4749 try {
4850 // Update response
@@ -66,9 +68,12 @@ module.exports = {
6668 const type = options . getString ( "type" ) || "video" ;
6769 const isPlaylist = type === "playlist" ;
6870 const currentItem = isPlaylist ? queue ?. songs [ 0 ] ?. playlist : queue ?. songs [ 0 ] ?. stream ?. song || queue ?. songs [ 0 ] ;
69- if ( ! currentItem ) return client . sendErrorNotification ( interaction , `${ isPlaylist ? lang . ERROR_PLAYLIST_NO_PLAYING : lang . ERROR_SONG_NO_PLAYING } ` ) ;
70- if ( library . find ( ( item ) => item . url === currentItem . url ) ) return client . sendErrorNotification ( interaction , `${ isPlaylist ? lang . ERROR_LIBRARY_PLAYLIST_ALREADY_ADDED : lang . ERROR_LIBRARY_SONG_ALREADY_ADDED } ` ) ;
71- if ( library . length >= config . LIBRARY_MAX_LENGTH ) return client . sendErrorNotification ( interaction , `${ lang . ERROR_LIBRARY_LIMIT_REACHED } ` ) ;
71+ if ( ! currentItem )
72+ return client . sendErrorNotification ( interaction , `${ isPlaylist ? lang . ERROR_PLAYLIST_NO_PLAYING : lang . ERROR_SONG_NO_PLAYING } ` ) ;
73+ if ( library . find ( ( item ) => item . url === currentItem . url ) )
74+ return client . sendErrorNotification ( interaction , `${ isPlaylist ? lang . ERROR_LIBRARY_PLAYLIST_ALREADY_ADDED : lang . ERROR_LIBRARY_SONG_ALREADY_ADDED } ` ) ;
75+ if ( library . length >= config . LIBRARY_MAX_LENGTH )
76+ return client . sendErrorNotification ( interaction , `${ lang . ERROR_LIBRARY_LIMIT_REACHED } ` ) ;
7277 // Add item to library
7378 library . push ( { name : currentItem . name , author : currentItem . uploader ?. name , thumbnail : currentItem . thumbnail , url : currentItem . url , isPlaylist : isPlaylist } ) ;
7479 await interaction . deferReply ( { ephemeral : true } ) . catch ( ( error ) => { } ) ;
@@ -107,9 +112,12 @@ module.exports = {
107112 }
108113 break ;
109114 case "play" :
110- if ( ! member . voice . channel ) return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_MEMBER_MUST_JOIN_VOICE_CHANNEL } ` ) ;
111- if ( ! client . checkMemberIsInMyVoiceChannel ( guild , member ) && queue ) return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_MEMBER_MUST_JOIN_MY_VOICE_CHANNEL } ` ) ;
112- if ( ! client . handleCooldown ( "playQuery" , member . id , 2000 ) ) return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_ACTION_NOT_POSSIBLE } ` ) ;
115+ if ( ! member . voice . channel )
116+ return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_MEMBER_MUST_JOIN_VOICE_CHANNEL } ` ) ;
117+ if ( ! client . checkMemberIsInMyVoiceChannel ( guild , member ) && queue )
118+ return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_MEMBER_MUST_JOIN_MY_VOICE_CHANNEL } ` ) ;
119+ if ( ! client . handleCooldown ( "playQuery" , member . id , 2000 ) )
120+ return client . sendErrorNotification ( subinteraction , `${ lang . ERROR_ACTION_NOT_POSSIBLE } ` ) ;
113121 await subinteraction . deferReply ( ) . catch ( ( error ) => { } ) ;
114122 try {
115123 // Play or add item to the queue using selected item url
@@ -121,13 +129,15 @@ module.exports = {
121129 break ;
122130 case "remove" :
123131 const position = library . findIndex ( ( item ) => item . url === selectedItem . url ) ;
124- if ( position === - 1 ) return client . sendErrorNotification ( subinteraction , `${ selectedItem . isPlaylist ? lang . ERROR_LIBRARY_PLAYLIST_NOT_FOUND : lang . ERROR_LIBRARY_SONG_NOT_FOUND } ` ) ;
132+ if ( position === - 1 )
133+ return client . sendErrorNotification ( subinteraction , `${ selectedItem . isPlaylist ? lang . ERROR_LIBRARY_PLAYLIST_NOT_FOUND : lang . ERROR_LIBRARY_SONG_NOT_FOUND } ` ) ;
125134 // Remove item from library
126135 library . splice ( position , 1 ) ;
127136 try {
128137 // Update user data in database
129138 await client . updateUserData ( member , { library : library } ) ;
130- if ( library . length === 0 ) return interaction . deleteReply ( ) . catch ( ( error ) => { } ) ;
139+ if ( library . length === 0 )
140+ return interaction . deleteReply ( ) . catch ( ( error ) => { } ) ;
131141 // Update response
132142 await module . exports . updateResponse ( interaction , lang , library , library [ 0 ] ) ;
133143 selections [ message . id ] = library [ 0 ] ;
@@ -142,9 +152,28 @@ module.exports = {
142152 updateResponse : async ( interaction , lang , items , selectedItem ) => {
143153 // Update library embed, menu and buttons
144154 const options = items . map ( ( item , i ) => { return { label : `${ i + 1 } . ${ item . name . length > config . ITEM_NAME_MAX_LENGTH_DISPLAY ? item . name . substr ( 0 , config . ITEM_NAME_MAX_LENGTH_DISPLAY ) . concat ( "..." ) : item . name } ` , description : `${ item . author || "-" } ` , emoji : item . isPlaylist ? elements . EMOJI_PLAYLIST : elements . EMOJI_SONG , value : `${ i } ` , default : item === selectedItem } } ) ;
145- const libraryEmbed = new EmbedBuilder ( ) . setAuthor ( { name : `${ lang . MESSAGE_LIBRARY_TITLE } (${ items . length } /${ config . LIBRARY_MAX_LENGTH } )` , iconURL : interaction . user . displayAvatarURL ( { forceStatic : true } ) } ) . addFields ( { name : `**${ lang . MESSAGE_ITEM_TITLE } **` , value : `[${ selectedItem . name } ](${ selectedItem . url } )` } , { name : `**${ lang . MESSAGE_ITEM_AUTHOR } **` , value : `${ selectedItem . author || "-" } ` , inline : true } , { name : `**${ lang . MESSAGE_ITEM_TYPE } **` , value : `${ selectedItem . isPlaylist ? lang . ITEM_PLAYLIST : lang . ITEM_SONG } ` , inline : true } ) . setThumbnail ( selectedItem . thumbnail ) . setColor ( elements . COLOR_FLOPY ) ;
146- const libraryMenu = new ActionRowBuilder ( ) . addComponents ( new StringSelectMenuBuilder ( ) . setCustomId ( "select" ) . setOptions ( options ) ) ;
147- const libraryButtons = new ActionRowBuilder ( ) . addComponents ( new ButtonBuilder ( ) . setCustomId ( "play" ) . setStyle ( ButtonStyle . Primary ) . setLabel ( `${ lang . BUTTON_PLAY } ` ) , new ButtonBuilder ( ) . setCustomId ( "remove" ) . setStyle ( ButtonStyle . Danger ) . setLabel ( `${ lang . BUTTON_LIBRARY_REMOVE } ` ) ) ;
155+ const libraryEmbed = new EmbedBuilder ( )
156+ . setAuthor ( { name : `${ lang . MESSAGE_LIBRARY_TITLE } (${ items . length } /${ config . LIBRARY_MAX_LENGTH } )` , iconURL : interaction . user . displayAvatarURL ( { forceStatic : true } ) } )
157+ . addFields ( { name : `**${ lang . MESSAGE_ITEM_TITLE } **` , value : `[${ selectedItem . name } ](${ selectedItem . url } )` } , { name : `**${ lang . MESSAGE_ITEM_AUTHOR } **` , value : `${ selectedItem . author || "-" } ` , inline : true } , { name : `**${ lang . MESSAGE_ITEM_TYPE } **` , value : `${ selectedItem . isPlaylist ? lang . ITEM_PLAYLIST : lang . ITEM_SONG } ` , inline : true } )
158+ . setThumbnail ( selectedItem . thumbnail )
159+ . setColor ( elements . COLOR_FLOPY ) ;
160+ const libraryMenu = new ActionRowBuilder ( )
161+ . addComponents (
162+ new StringSelectMenuBuilder ( )
163+ . setCustomId ( "select" )
164+ . setOptions ( options )
165+ ) ;
166+ const libraryButtons = new ActionRowBuilder ( )
167+ . addComponents (
168+ new ButtonBuilder ( )
169+ . setCustomId ( "play" )
170+ . setStyle ( ButtonStyle . Primary )
171+ . setLabel ( `${ lang . BUTTON_PLAY } ` ) ,
172+ new ButtonBuilder ( )
173+ . setCustomId ( "remove" )
174+ . setStyle ( ButtonStyle . Danger )
175+ . setLabel ( `${ lang . BUTTON_LIBRARY_REMOVE } ` )
176+ ) ;
148177 await interaction . editReply ( { embeds : [ libraryEmbed ] , components : [ libraryMenu , libraryButtons ] } ) ;
149178 }
150179}
0 commit comments