1+ const { EmbedBuilder } = require ( "discord.js" ) ;
2+ const { Database } = require ( "st.db" ) ;
3+ const ytsr = require ( "@distube/ytsr" ) ;
4+
5+ const SStats = new Database ( "./settings/models/chart.json" , { databaseInObject : true } ) ;
6+
7+ module . exports = {
8+ name : [ "topchart" ] ,
9+ description : "Display top song most recent playable." ,
10+ category : "Utilities" ,
11+ run : async ( client , interaction ) => {
12+ await interaction . deferReply ( { ephemeral : false } ) ;
13+
14+ const all = SStats . all ( ) . slice ( 0 , 10 ) ;
15+
16+ all . sort ( ( a , b ) => {
17+ return b . data - a . data ;
18+ } ) ;
19+
20+ var index = 0 ;
21+
22+ for ( let i = 0 ; i < all . length ; i ++ ) {
23+ const total = all [ i ] . data ;
24+ index = ( index + total )
25+ }
26+
27+ const TopChart = [ ] ;
28+ for ( let i = 0 ; i < all . length ; i ++ ) {
29+ const format = `https://youtu.be/${ all [ i ] . ID } ` ;
30+ const search = await ytsr ( format ) ;
31+ const track = search . items [ 0 ] ;
32+
33+ TopChart . push (
34+ `**${ i + 1 } .** [${ track . name } ](${ track . url } ) | **Playable:** \`${ all [ i ] . data } \`
35+ ` )
36+ }
37+
38+ const str = TopChart . join ( '' ) ;
39+
40+ const embed = new EmbedBuilder ( )
41+ . setColor ( client . color )
42+ . setAuthor ( { name : `Top Charts` , iconURL : interaction . guild . iconURL ( { dynamic : true } ) } )
43+ . setThumbnail ( client . user . displayAvatarURL ( { dynamic : true , size : 2048 } ) )
44+ . setDescription ( `${ str == '' ? ' No Playable' : '\n' + str } ` )
45+ . setFooter ( { text : `Total Song • ${ SStats . all ( ) . length } | Total Playable • ${ index } ` } )
46+
47+
48+ return interaction . editReply ( { embeds : [ embed ] } )
49+ }
50+ }
0 commit comments