11const { SlashCommandBuilder } = require ( '@discordjs/builders' ) ;
22const { constructEmbed } = require ( '../utility/embedConstructor' ) ;
3- const { joinVoiceChannel, createAudioResource } = require ( '@discordjs/voice' ) ;
3+ const { joinVoiceChannel } = require ( '@discordjs/voice' ) ;
44const { canPerformAction } = require ( '../utility/permissions' ) ;
55const MusicConnection = require ( '../utility/musicConnection' ) ;
66const Discord = require ( 'discord.js' ) ;
@@ -12,7 +12,7 @@ module.exports = {
1212 . setName ( 'radio' )
1313 . setDescription ( 'radio test thing' ) ,
1414 // array of guild ids, null for global command
15- guilds : [ '953064066576949348' ] ,
15+ guilds : null ,
1616 // method to run the command
1717 async run ( interaction ) {
1818 const member = interaction . member ;
@@ -46,19 +46,60 @@ module.exports = {
4646 }
4747
4848 if ( connection . mode == 'radio' ) {
49- // ask if they want to change radio station OR switch to queue mode via buttons
50-
51- connection . changeMode ( 'queue' ) ;
52- return interaction . editReply ( ':asterisk: **Switched to queue mode.**' ) ;
49+ return await interaction . editReply ( {
50+ content : '**Would you like to change the radio station or exit radio mode?**' ,
51+ components : [
52+ new Discord . MessageActionRow ( )
53+ . addComponents (
54+ new Discord . MessageButton ( )
55+ . setCustomId ( 'changeradiostation' )
56+ . setStyle ( 'PRIMARY' )
57+ . setLabel ( 'Change Station' )
58+ . setDisabled ( false ) ,
59+ new Discord . MessageButton ( )
60+ . setCustomId ( 'exitradiomode' )
61+ . setStyle ( 'DANGER' )
62+ . setLabel ( 'Exit Radio Mode' )
63+ . setDisabled ( false ) ,
64+ new Discord . MessageButton ( )
65+ . setCustomId ( 'cancel' )
66+ . setStyle ( 'DANGER' )
67+ . setLabel ( 'Cancel' )
68+ . setDisabled ( false ) ,
69+ ) ,
70+ ] ,
71+ } ) ;
5372 }
5473 else {
5574 connection . changeMode ( 'radio' ) ;
56- await interaction . editReply ( 'Please wait...' ) ;
75+ await interaction . editReply ( '**Please wait...**' ) ;
76+
77+ const items = stations . length ;
78+ const divided = ( items / 15 ) ;
79+ const pageNumber = ( ( divided % 1 == 0 ) ? divided : Math . ceil ( divided ) ) ;
5780
58- const message = await interaction . editReply ( {
59- content : '-' ,
60- embeds : constructEmbed ( { color : 'BLUE' , title : 'Select radio station' , description : stations [ 0 ] . map ( x => x [ 0 ] + ' ' + x [ 1 ] ) . join ( '\n' ) , footer : `Viewing page 1 of ${ stations . length } ` } ) . embeds ,
81+ await interaction . editReply ( {
82+ content : '⬇️ **Select a radio station:**' ,
6183 components : [
84+ new Discord . MessageActionRow ( )
85+ . addComponents (
86+ new Discord . MessageSelectMenu ( {
87+ customId : 'station_1' ,
88+ // station_pagenumber
89+ options : stations . map ( x => x [ 0 ] ) . sort ( ) . map ( x => {
90+ return {
91+ label : x ,
92+ value : ( x . toLowerCase ( ) . split ( ' ' ) . join ( '_' ) ) ,
93+ emoji : '📻' ,
94+ } ;
95+ } ) ,
96+ // max of 25 options
97+ minValues : 1 ,
98+ maxValues : 1 ,
99+ disabled : false ,
100+ placeholder : `Select a radio station (page 1 of ${ pageNumber } )` ,
101+ } ) ,
102+ ) ,
62103 new Discord . MessageActionRow ( )
63104 . addComponents (
64105 new Discord . MessageButton ( )
@@ -70,66 +111,15 @@ module.exports = {
70111 . setCustomId ( 'forward' )
71112 . setStyle ( 'PRIMARY' )
72113 . setEmoji ( '▶️' )
73- . setDisabled ( stations . length <= 1 ) ,
114+ . setDisabled ( pageNumber <= 1 ) ,
115+ new Discord . MessageButton ( )
116+ . setCustomId ( 'cancel' )
117+ . setStyle ( 'DANGER' )
118+ . setLabel ( 'Cancel' )
119+ . setDisabled ( false ) ,
74120 ) ,
75121 ] ,
76122 } ) ;
77-
78- const reactions = [ '1️⃣' , '2️⃣' , '3️⃣' , '4️⃣' , '5️⃣' , '6️⃣' , '7️⃣' , '8️⃣' , '9️⃣' ] ;
79-
80- const getPage = ( reaction ) => {
81- return 1 ;
82- } ;
83-
84- const filter = ( reaction , user ) => {
85- if ( user . id != member . id ) return false ;
86-
87- const index = reactions . indexOf ( reaction . emoji . name ) ;
88-
89- if ( index < 0 ) return false ;
90-
91- const page = getPage ( reaction ) ;
92-
93- if ( ( index + 1 ) > stations [ page - 1 ] . length ) return false ;
94-
95- return true ;
96- } ;
97-
98- const collector = message . createReactionCollector ( { filter, time : 60000 , max : 1 } ) ;
99-
100- collector . on ( 'end' , collected => {
101- if ( collected . size == 0 ) {
102- interaction . followUp ( ':x: **Timed out.**' ) ;
103- }
104- else {
105- const reaction = collected . first ( ) ;
106- const page = getPage ( reaction ) ;
107- const index = reactions . indexOf ( reaction . emoji . name ) ;
108-
109- const data = stations [ page - 1 ] [ index ] ;
110-
111- if ( data ) {
112- const resource = createAudioResource ( data [ 2 ] ) ;
113- connection . audioPlayer . play ( resource ) ;
114-
115- message . reactions . removeAll ( ) ;
116- return interaction . editReply ( {
117- content : `📻 **Now playing: ${ data [ 1 ] } **` ,
118- embeds : [ ] ,
119- components : [ ] ,
120- } ) ;
121- }
122- else {
123- return interaction . editReply ( constructEmbed ( { color : 'RED' , description : 'Failed to getch resource.' } ) ) ;
124- }
125- }
126- } ) ;
127-
128- for ( let i = 0 ; ( ( i < reactions . length ) && ( i < stations [ 0 ] . length ) ) ; i ++ ) {
129- if ( reactions [ i ] ) {
130- await message . react ( reactions [ i ] ) ;
131- }
132- }
133123 }
134124 } ,
135125} ;
0 commit comments