mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 12:23:38 +00:00
Radio Stations from JSON file
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
const { Client, Collection } = require('discord.js');
|
||||
const Discord = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path')
|
||||
const path = require('path');
|
||||
const events = '../events/';
|
||||
|
||||
module.exports = class extends Client {
|
||||
@ -29,10 +29,6 @@ module.exports = class extends Client {
|
||||
this.commandAliases.set(command.alias, command);
|
||||
}
|
||||
|
||||
if (this.config.devMode) {
|
||||
this.config.token = this.config.devToken;
|
||||
}
|
||||
|
||||
this.on('ready', () => {
|
||||
require(`${events}ready`).execute(this, Discord);
|
||||
});
|
||||
|
@ -1,6 +1,26 @@
|
||||
module.exports = async function (guild, client, url) {
|
||||
module.exports = async function (guild, client, station) {
|
||||
|
||||
const radio = client.radio.get(guild.id);
|
||||
const stations = await client.funcs.radiostations();
|
||||
let url = "";
|
||||
|
||||
if(isNaN(station)){
|
||||
radio.voiceChannel.leave();
|
||||
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
|
||||
}
|
||||
|
||||
if(station-1 > stations.length-1){
|
||||
radio.voiceChannel.leave();
|
||||
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
|
||||
}
|
||||
|
||||
url = stations[station-1].stream[stations[station-1].stream.default];
|
||||
|
||||
if(!url) {
|
||||
radio.voiceChannel.leave();
|
||||
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
|
||||
}
|
||||
|
||||
const dispatcher = radio.connection
|
||||
.play(url, { bitrate: 1024, passes: 10, volume: 1, highWaterMark: 1 << 25 })
|
||||
.on("finish", () => {
|
||||
@ -8,16 +28,21 @@ module.exports = async function (guild, client, url) {
|
||||
client.radio.delete(guild.id);
|
||||
return;
|
||||
});
|
||||
|
||||
dispatcher.on('start', () => {
|
||||
dispatcher.player.streamingData.pausedTime = 0;
|
||||
});
|
||||
|
||||
dispatcher.on('error', error => {
|
||||
console.error(error);
|
||||
radio.voiceChannel.leave();
|
||||
client.radio.delete(guild.id);
|
||||
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
|
||||
});
|
||||
|
||||
dispatcher.setVolume(radio.volume / 10);
|
||||
|
||||
radio.textChannel.send('Start playing');
|
||||
radio.playing = true;
|
||||
|
||||
}
|
||||
|
9
struct/funcs/radiostations.js
Normal file
9
struct/funcs/radiostations.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = async function () {
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
let data = fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||
.then(res => res.json());
|
||||
|
||||
return data;
|
||||
}
|
Reference in New Issue
Block a user