diff --git a/commands/bug.js b/commands/bug.js index 62a2969..cd0a0a7 100644 --- a/commands/bug.js +++ b/commands/bug.js @@ -20,8 +20,9 @@ module.exports = { const embed = new Discord.MessageEmbed() .setTitle(`Found a bug with ${client.user.username}?\nDM the core developer:`) + .setColor(client.config.embedColor) .setDescription(`${developers}\nOr join the support server: ${client.config.supportGuild}`) - .setColor(client.config.embedColor); + .setFooter('EximiaBots by Warén Media'); msg.channel.send(embed); }, }; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 786221a..7232b9e 100644 --- a/commands/help.js +++ b/commands/help.js @@ -11,9 +11,9 @@ module.exports = { const command = client.commands.get(args[1]); const embed = new Discord.MessageEmbed() .setTitle(`${client.global.db.guilds[msg.guild.id].prefix}${command.name} ${command.usage}`) - .setDescription(command.description) - .setFooter(`Command Alias: \`${command.alias}\``) .setColor(client.config.embedColor) + .setDescription(command.description + `\n Command Alias: \`${command.alias}\``) + .setFooter('EximiaBots by Warén Media') msg.channel.send(embed); } else { const categories = []; @@ -26,9 +26,9 @@ module.exports = { } const embed = new Discord.MessageEmbed() .setTitle(`${client.user.username} help:`) - .setDescription(commands) - .setFooter(`"${client.config.prefix}help " to see more information about a command.`) .setColor(client.config.embedColor) + .setDescription(commands + `\n "${client.config.prefix}help " to see more information about a command.`) + .setFooter('EximiaBots by Warén Media'); msg.channel.send(embed); } } diff --git a/commands/invite.js b/commands/invite.js index 5288b64..15b898a 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -8,8 +8,9 @@ module.exports = { execute(msg, args, client, Discord, prefix) { const embed = new Discord.MessageEmbed() .setTitle(`Invite ${client.user.username} to your Discord server!`) - .setURL(client.config.invite) .setColor(client.config.embedColor) + .setURL(client.config.invite) + .setFooter('EximiaBots by Warén Media'); return msg.channel.send(embed); } }; \ No newline at end of file diff --git a/commands/nowplaying.js b/commands/nowplaying.js index 9339a85..715e92b 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -11,11 +11,14 @@ module.exports = { if (!radio.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing.'); radio.time = radio.connection.dispatcher.streamTime; const completed = (radio.time.toFixed(0)); + + const stations = await client.funcs.radiostations(); + const embed = new Discord.MessageEmbed() - .setTitle("__Now playing__") - .setDescription(`**Now playing:** ${radio.url}\n\`${client.funcs.msToTime(completed, "hh:mm:ss")}\``) + .setTitle(" Now Playing") .setColor(client.config.embedColor) + .setDescription(`**${stations[radio.station].name}** \n Owner: ${stations[radio.station].owner} \n\`${client.funcs.msToTime(completed, "hh:mm:ss")}\``) + .setFooter('EximiaBots by Warén Media'); return msg.channel.send(embed); } -}; - +}; \ No newline at end of file diff --git a/commands/play.js b/commands/play.js index c5dd665..6ab6874 100644 --- a/commands/play.js +++ b/commands/play.js @@ -6,7 +6,7 @@ module.exports = { permission: 'none', category: 'music', async execute(msg, args, client, Discord, prefix) { - const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; + const station = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const radio = client.radio.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; if (!radio) { @@ -25,25 +25,26 @@ module.exports = { if (radio) { radio.connection.dispatcher.destroy(); - client.funcs.play(msg.guild, client, url); + radio.station = station; + client.funcs.play(msg.guild, client, station); return; } - - const construct = { + + const construct = { textChannel: msg.channel, voiceChannel: voiceChannel, connection: null, playing: false, - url: url, + station: station-1, name: null, volume: client.config.volume, }; client.radio.set(msg.guild.id, construct); - + try { const connection = await voiceChannel.join(); construct.connection = connection; - client.funcs.play(msg.guild, client, url); + client.funcs.play(msg.guild, client, station); } catch (error) { client.radio.delete(msg.guild.id); client.debug_channel.send("Error with connecting to voice channel: " + error); diff --git a/package.json b/package.json index d480c6e..3f543ef 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "discord.js": "^12.0.1", "dotenv": "^8.2.0", "fs": "0.0.1-security", + "node-fetch": "^2.6.0", "path": "^0.12.7" } } diff --git a/struct/client.js b/struct/client.js index 475702f..8a364e5 100644 --- a/struct/client.js +++ b/struct/client.js @@ -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); }); diff --git a/struct/funcs/play.js b/struct/funcs/play.js index e7ba917..e2ac3fe 100644 --- a/struct/funcs/play.js +++ b/struct/funcs/play.js @@ -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; + } diff --git a/struct/funcs/radiostations.js b/struct/funcs/radiostations.js new file mode 100644 index 0000000..8cff920 --- /dev/null +++ b/struct/funcs/radiostations.js @@ -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; +} \ No newline at end of file