File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -47,18 +47,28 @@ module.exports = {
4747 )
4848 let dir = '../servers/' + args [ 0 ]
4949 let dirData = fs . readdirSync ( dir ) // add in all file names that end with .zip
50- dirData = bubbleSort ( dirData ) ;
50+
51+ //sort dirData by date last modified
52+ dirData = dirData . map ( function ( fileName ) {
53+ return {
54+ name : fileName ,
55+ time : fs . statSync ( dir + '/' + fileName ) . mtime . getTime ( )
56+ } ;
57+ } )
58+ . sort ( function ( a , b ) {
59+ return a . time - b . time ; } )
60+ . map ( function ( v ) {
61+ return v . name ; } ) ;
62+
63+
5164 for ( let i = 0 ; i < 25 ; i ++ ) { // max number of fields in a Discord Embed is 25
5265 if ( ! dirData [ i ] ) break ;
5366 if ( dirData [ i ] && dirData [ i ] . endsWith ( '.zip' ) ) {
5467 let data = fs . statSync ( dir + '/' + dirData [ i ] )
5568 let date = new Date ( data . birthtimeMs )
56- dataDic [ dirData [ i ] ] = date . toUTCString ( ) ;
5769 }
5870 }
5971
60- // somehow sort dirData and date pairs by the newest date
61-
6272 choiceEmbed . addField ( `\`${ dirData [ i ] } \`` , `Save created on: ${ date . toUTCString ( ) } ` ) ;
6373
6474 return message . channel . send ( choiceEmbed )
You can’t perform that action at this time.
0 commit comments