Adds FM Radio Stations

```
!tune => This will play default radio station
!tune next => Next Radio Station
!tune prev => Previous Radio Station
```
This commit is contained in:
Indrajith K L
2021-06-22 21:52:15 +05:30
parent 0ef3c83f40
commit 07d768cc40
4 changed files with 106 additions and 6 deletions

View File

@@ -1,6 +1,5 @@
const { VoiceChannel, TextChannel, MessageEmbed } = require("discord.js"); const { VoiceChannel, TextChannel, MessageEmbed } = require("discord.js");
const axios = require('axios').default; const axios = require('axios').default;
const instance = axios.create({ const instance = axios.create({
baseURL: 'http://retrowave.ru/api/v1' baseURL: 'http://retrowave.ru/api/v1'
}); });
@@ -10,15 +9,15 @@ const resourceUrl = 'http://retrowave.ru'
async function broadcastRadio(client, args, message, voiceChannel, textChannel) { async function broadcastRadio(client, args, message, voiceChannel, textChannel) {
const connection = await voiceChannel.join(); const connection = await voiceChannel.join();
try { try {
playRadio(connection, textChannel); playRadioRetroWave(connection, textChannel);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
textChannel.send('Something went wrong. RADIO MON got ill...😱😱'); textChannel.send('Something went wrong. RADIO MON got ill...😱😱');
} }
} }
async function playRadio(connection,textChannel) {
async function playRadioRetroWave(connection, textChannel) {
const nextMusic = await getNextMusic(); const nextMusic = await getNextMusic();
const { id, title, streamUrl, artworkUrl } = nextMusic; const { id, title, streamUrl, artworkUrl } = nextMusic;
const nowPlayingMessage = new MessageEmbed() const nowPlayingMessage = new MessageEmbed()
@@ -26,10 +25,10 @@ async function playRadio(connection,textChannel) {
.setDescription(title) .setDescription(title)
.setColor('LUMINOUS_VIVID_PINK') .setColor('LUMINOUS_VIVID_PINK')
.setThumbnail(`${resourceUrl}${artworkUrl}`); .setThumbnail(`${resourceUrl}${artworkUrl}`);
textChannel.send(nowPlayingMessage) textChannel.send(nowPlayingMessage);
connection.play(`${resourceUrl}${streamUrl}`, { seek: 0, volume: 1 }) connection.play(`${resourceUrl}${streamUrl}`, { seek: 0, volume: 1 })
.on('finish', () => { .on('finish', () => {
playRadio(connection,textChannel); playRadio(connection, textChannel);
}); });
} }

64
src/commands/tune.js Normal file
View File

@@ -0,0 +1,64 @@
const { VoiceChannel, TextChannel, MessageEmbed } = require('discord.js');
const fs = require('fs');
const readFile = fs.promises.readFile;
let radioIndex = 0;
async function broadcastRadio(client, args, message, voiceChannel, textChannel) {
const connection = await voiceChannel.join();
try {
playRadio(connection, textChannel, args);
} catch (error) {
console.log(error);
textChannel.send('Something went wrong. RADIO MON got ill...😱😱');
}
}
async function playRadio(connection, textChannel, args) {
try {
const [radioCommand] = args;
const radioConfig = await readFile('src/configs/radio.json', 'utf8');
const radioStations = JSON.parse(radioConfig);
const totalRadioStations = radioStations.length;
let currentRadioStation;
if (!radioCommand) {
radioIndex = 0;
currentRadioStation = radioStations[radioIndex];
} else {
switch (radioCommand) {
case 'next':
radioIndex++;
if (radioIndex >= totalRadioStations) radioIndex = 0;
break;
case 'prev':
radioIndex--;
if (radioIndex < 0) radioIndex = totalRadioStations - 1;
currentRadioStation = radioStations[radioIndex];
break;
}
}
currentRadioStation = radioStations[radioIndex];
connection.play(`${currentRadioStation.url}`, { seek: 0, volume: 1 });
const nowPlayingMessage = new MessageEmbed()
.setTitle("Now Playing")
.setDescription(currentRadioStation.name)
.setColor('LUMINOUS_VIVID_PINK');
textChannel.send(nowPlayingMessage)
} catch (error) {
console.log(error);
};
};
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);
}
}

View File

@@ -9,6 +9,11 @@
"name": "radioStop", "name": "radioStop",
"description": "Stop Radio", "description": "Stop Radio",
"file": "./commands/radioStop.js" "file": "./commands/radioStop.js"
},
{
"name": "tune",
"description": "FM Radio Tune IN",
"file": "./commands/tune.js"
} }
] ]
} }

32
src/configs/radio.json Normal file
View File

@@ -0,0 +1,32 @@
[
{
"id": "ananthapuriFM",
"name": "Ananthapuri FM",
"url": "https://air.pc.cdn.bitgravity.com/air/live/pbaudio229/playlist.m3u8"
},
{
"id": "clubFM",
"name": "Club FM 99.6",
"url": "https://22243.live.streamtheworld.com/CLUBFMUAEAAC.aac"
},
{
"id": "nigthRide",
"name": "Nightride FM",
"url": "https://stream.nightride.fm/nightride.m4a"
},
{
"id": "recordSynthwave",
"name": "Record Synthwave",
"url": "http://air.radiorecord.ru:805/synth_320"
},
{
"id": "radioMango",
"name": "Radio Mango 91.9",
"url": "https://bcovlive-a.akamaihd.net/19b535b7499a4719a5c19e043063f5d9/ap-southeast-1/6034685947001/playlist.m3u8"
},
{
"id": "oneFM",
"name": "One FM 91.3 Singapore",
"url": "https://22253.live.streamtheworld.com/ONE_FM_913AAC.aac?dist=sphradio-web"
}
]