aboutsummaryrefslogtreecommitdiff
path: root/src/commands/radioStart.js
diff options
context:
space:
mode:
authorIndrajith K L2021-06-19 18:30:58 +0530
committerIndrajith K L2021-06-19 18:30:58 +0530
commit0ef3c83f4049227c08731e3f31e53c38e1da5957 (patch)
tree349b423111db5a8730864b8c555bb15564622377 /src/commands/radioStart.js
parentcaebd6b3e5315d3002107464b33ae7b6bf006800 (diff)
downloadradio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.tar.gz
radio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.tar.bz2
radio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.zip
* Radio Bot Implementation
Diffstat (limited to 'src/commands/radioStart.js')
-rw-r--r--src/commands/radioStart.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/commands/radioStart.js b/src/commands/radioStart.js
new file mode 100644
index 0000000..d9c4ac1
--- /dev/null
+++ b/src/commands/radioStart.js
@@ -0,0 +1,54 @@
+const { VoiceChannel, TextChannel, MessageEmbed } = require("discord.js");
+const axios = require('axios').default;
+
+const instance = axios.create({
+ baseURL: 'http://retrowave.ru/api/v1'
+});
+
+const resourceUrl = 'http://retrowave.ru'
+
+async function broadcastRadio(client, args, message, voiceChannel, textChannel) {
+ const connection = await voiceChannel.join();
+ try {
+ playRadio(connection, textChannel);
+ } catch (error) {
+ console.log(error);
+ textChannel.send('Something went wrong. RADIO MON got ill...😱😱');
+ }
+
+}
+
+async function playRadio(connection,textChannel) {
+ const nextMusic = await getNextMusic();
+ const { id, title, streamUrl, artworkUrl } = nextMusic;
+ const nowPlayingMessage = new MessageEmbed()
+ .setTitle("Now Playing")
+ .setDescription(title)
+ .setColor('LUMINOUS_VIVID_PINK')
+ .setThumbnail(`${resourceUrl}${artworkUrl}`);
+ textChannel.send(nowPlayingMessage)
+ connection.play(`${resourceUrl}${streamUrl}`, { seek: 0, volume: 1 })
+ .on('finish', () => {
+ playRadio(connection,textChannel);
+ });
+}
+
+async function getNextMusic() {
+ const result = await instance.get('/tracks?cursor=1&limit=1');
+ return result.data.body.tracks[0];
+}
+
+module.exports = {
+ async execute(client, message, args) {
+ const { RADIO_CHANNEL, NOW_PLAYING_CHANNEL } = process.env;
+ if (!RADIO_CHANNEL) return message.reply(`Please add RADIO_CHANNEL to .env with a Voice Channel ID`);
+ if (!NOW_PLAYING_CHANNEL) return message.reply(`Please add NOW_PLAYING_CHANNEL to .env with a Text Channel ID`);
+
+ const voiceChannel = await client.channels.fetch(process.env.RADIO_CHANNEL);
+ const nowPlayingChannel = await client.channels.fetch(process.env.NOW_PLAYING_CHANNEL);
+ if (!(voiceChannel instanceof VoiceChannel)) return message.reply(`Please provice a Voice Channel ID to the RADIO_CHANNEL`);
+ if (!(nowPlayingChannel instanceof TextChannel)) return message.reply(`Please provice a Text Channel ID to the NOW_PLAYING_CHANNEL`);
+
+ broadcastRadio(client, args, message, voiceChannel, nowPlayingChannel);
+ }
+} \ No newline at end of file