Skip to content

Commit 90c8bed

Browse files
committed
raido dropdowns and stuff
1 parent ef21d75 commit 90c8bed

9 files changed

Lines changed: 331 additions & 91 deletions

File tree

src/buttons/cancel.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
name: 'cancel',
3+
run: async (interaction) => {
4+
if (!interaction.message.interaction) return;
5+
6+
interaction.deferUpdate();
7+
8+
if (Date.now() > interaction.message.createdAt.getTime() + 120000) {
9+
interaction.reply({ ephemeral: true, content: '⛔ **This interaction has timed out**' });
10+
interaction.message.edit({ content: ':x: **Timed out**', components: [], embeds: [] });
11+
return;
12+
}
13+
14+
if (interaction.user.id != interaction.message.interaction.user.id) return interaction.reply({ ephemeral: true, content: '⛔ Only the person who initiated this command can cancel it.' });
15+
16+
await interaction.message.edit({ content: ':x: **Command cancelled**', components: [] });
17+
},
18+
};

src/buttons/changeradiostation.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const Discord = require('discord.js');
2+
const stations = require('../utility/stations.json');
3+
4+
module.exports = {
5+
name: 'changeradiostation',
6+
run: async (interaction) => {
7+
if (!interaction.message) return;
8+
9+
interaction.deferUpdate();
10+
11+
if (Date.now() > interaction.message.createdAt.getTime() + 120000) {
12+
interaction.reply({ ephemeral: true, content: '⛔ **This interaction has timed out**' });
13+
interaction.message.edit({ content: ':x: **Timed out**', components: [], embeds: [] });
14+
return;
15+
}
16+
17+
if (interaction.user.id != interaction.message.interaction.user.id) return interaction.reply({ ephemeral: true, content: '⛔ Only the person who initiated this command can interact with the dropdown.' });
18+
19+
const connection = interaction.client.connections.get(interaction.guildId);
20+
21+
if (!connection) {
22+
return interaction.message.edit({ content: ':x: **No music connection found**', components: [] });
23+
}
24+
25+
if (connection.mode != 'radio') {
26+
return interaction.message.edit({ content: ':x: **Not in radio mode**', components: [] });
27+
}
28+
29+
await interaction.message.edit({ content: '**Please wait...**', components: [] });
30+
31+
const items = stations.length;
32+
const divided = (items / 15);
33+
const pageNumber = ((divided % 1 == 0) ? divided : Math.ceil(divided));
34+
35+
await interaction.message.edit({
36+
content: '⬇️ **Select a radio station:**',
37+
components: [
38+
new Discord.MessageActionRow()
39+
.addComponents(
40+
new Discord.MessageSelectMenu({
41+
customId: 'station_1',
42+
options: stations.map(x => x[0]).sort().map(x => {
43+
return {
44+
label: x,
45+
value: (x.toLowerCase().split(' ').join('_')),
46+
emoji: '📻',
47+
};
48+
}),
49+
minValues: 1,
50+
maxValues: 1,
51+
disabled: false,
52+
placeholder: `Select a radio station (page 1 of ${pageNumber})`,
53+
}),
54+
),
55+
new Discord.MessageActionRow()
56+
.addComponents(
57+
new Discord.MessageButton()
58+
.setCustomId('back')
59+
.setStyle('PRIMARY')
60+
.setEmoji('◀️')
61+
.setDisabled(true),
62+
new Discord.MessageButton()
63+
.setCustomId('forward')
64+
.setStyle('PRIMARY')
65+
.setEmoji('▶️')
66+
.setDisabled(pageNumber <= 1),
67+
new Discord.MessageButton()
68+
.setCustomId('cancel')
69+
.setStyle('DANGER')
70+
.setLabel('Cancel')
71+
.setDisabled(false),
72+
),
73+
],
74+
});
75+
},
76+
};

src/buttons/exitradiomode.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
name: 'exitradiomode',
3+
run: async (interaction) => {
4+
if (!interaction.message) return;
5+
6+
interaction.deferUpdate();
7+
8+
if (Date.now() > interaction.message.createdAt.getTime() + 120000) {
9+
interaction.reply({ ephemeral: true, content: '⛔ **This interaction has timed out**' });
10+
interaction.message.edit({ content: ':x: **Timed out**', components: [], embeds: [] });
11+
return;
12+
}
13+
14+
if (interaction.user.id != interaction.message.interaction.user.id) return interaction.reply({ ephemeral: true, content: '⛔ Only the person who initiated this command can interact with the dropdown.' });
15+
16+
const connection = interaction.client.connections.get(interaction.guildId);
17+
18+
if (!connection) {
19+
return interaction.message.edit({ content: ':x: **No music connection found**', components: [] });
20+
}
21+
22+
if (connection.mode != 'radio') {
23+
return interaction.message.edit({ content: ':x: **Not in radio mode**', components: [] });
24+
}
25+
26+
await interaction.message.edit({ content: '**Please wait...**', components: [] });
27+
28+
connection.changeMode('queue');
29+
return interaction.message.edit(':asterisk: **Switched to queue mode**');
30+
},
31+
};

src/commands/radio.js

Lines changed: 57 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { SlashCommandBuilder } = require('@discordjs/builders');
22
const { constructEmbed } = require('../utility/embedConstructor');
3-
const { joinVoiceChannel, createAudioResource } = require('@discordjs/voice');
3+
const { joinVoiceChannel } = require('@discordjs/voice');
44
const { canPerformAction } = require('../utility/permissions');
55
const MusicConnection = require('../utility/musicConnection');
66
const 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
};

src/contextmenus/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)