Search Stations and large update

This commit is contained in:
MatteZ02 2020-03-09 13:17:47 +02:00
parent ecb23c8550
commit bdf2025558
7 changed files with 80 additions and 49 deletions

View File

@ -6,22 +6,10 @@ module.exports = {
permission: 'none',
category: 'info',
async execute(msg, args, client, Discord, prefix) {
let developers = "";
let user = "";
for(i = 0; i < client.config.devId.length; i++){
user = await client.users.fetch(client.config.devId[i]);
if(i == client.config.devId.length-1){
developers += user.tag;
} else {
developers += user.tag + " & ";
}
}
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}`)
.setDescription(`${client.developers}\nOr join the support server: ${client.config.supportGuild}`)
.setFooter('EximiaBots by Warén Media');
msg.channel.send(embed);
},

View File

@ -7,15 +7,14 @@ module.exports = {
category: 'music',
async execute(msg, args, client, Discord, prefix) {
const radio = client.radio.get(msg.guild.id);
if (!radio) return msg.channel.send('<:redx:674263474704220182> There is nothing playing.');
if (!radio.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing.');
if (!radio || !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 embed = new Discord.MessageEmbed()
.setTitle("<a:aNotes:674602408105476106> Now Playing")
.setColor(client.config.embedColor)
.setDescription(`**${client.stations[radio.station].name}** \n Owner: ${client.stations[radio.station].owner} \n\`${client.funcs.msToTime(completed, "hh:mm:ss")}\``)
.setDescription(`**${radio.station.name}** \n Owner: ${radio.station.owner} \n\`${client.funcs.msToTime(completed, "hh:mm:ss")}\``)
.setFooter('EximiaBots by Warén Media');
return msg.channel.send(embed);
}

View File

@ -6,7 +6,7 @@ module.exports = {
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, prefix) {
const station = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
let url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const radio = client.radio.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!radio) {
@ -22,29 +22,46 @@ module.exports = {
if (!permissions.has('SPEAK')) {
return msg.channel.send('<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!');
}
let station;
const number = parseInt(args[1] - 1);
if (url.startsWith('http')) {
return;
} else if (!isNaN(number)) {
if (number > client.stations.length - 1) {
return radio.textChannel.send('<:redx:674263474704220182> no such station!');
} else {
url = client.stations[number].stream[client.stations[number].stream.default];
station = client.stations[number];
}
} else {
const sstation = await client.funcs.searchStation(args.slice(1).join(' '), client);
if (sstation === false) return msg.channel.send('No stations found!');
url = sstation.stream[sstation.stream.default];
station = sstation
}
if (radio) {
radio.connection.dispatcher.destroy();
radio.station = station;
client.funcs.play(msg.guild, client, station);
radio.station = station;
client.funcs.play(msg.guild, client, url);
return;
}
const construct = {
const construct = {
textChannel: msg.channel,
voiceChannel: voiceChannel,
connection: null,
playing: false,
station: station-1,
name: null,
station: station,
volume: client.config.volume,
time: null
};
client.radio.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, client, station);
client.funcs.play(msg.guild, client, url);
} catch (error) {
client.radio.delete(msg.guild.id);
client.debug_channel.send("Error with connecting to voice channel: " + error);

View File

@ -3,17 +3,27 @@ const fetch = require('node-fetch');
module.exports = {
name: 'ready',
async execute(client, Discord) {
console.log('RadioX');
console.log('We will bring you finnish radio to your discord server');
console.log('(c)2020 EximiaBots by Warén Media / Christer Warén & MatteZ02');
let user = "";
for (i = 0; i < client.config.devId.length; i++) {
user = await client.users.fetch(client.config.devId[i]);
if (i == client.config.devId.length - 1) {
client.developers += user.tag;
} else {
client.developers += user.tag + " & ";
}
}
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
.then(res => res.json());
setInterval(async () => {
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
.then(res => res.json());
}, 3600);
}, 3600000);
}
}

View File

@ -8,7 +8,6 @@ module.exports = {
if (newState.member.voice.channel === null) {
radio.songs = [];
radio.looping = false;
radio.endReason = "manual disconnect";
return client.radio.delete(newState.guild.id);
}
if (newState.member.voice.channel !== radio.voiceChannel) {

View File

@ -1,24 +1,6 @@
module.exports = async function (guild, client, station) {
module.exports = async function (guild, client, url) {
const radio = client.radio.get(guild.id);
let url = "";
if (isNaN(station)) {
radio.voiceChannel.leave();
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
}
if (station - 1 > client.stations.length - 1) {
radio.voiceChannel.leave();
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
}
url = client.stations[station - 1].stream[client.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 })

View File

@ -0,0 +1,36 @@
module.exports = function (key, client) {
let foundStations = [];
if (!key) return false;
const probabilityIncrement = 100 / key.split(' ').length / 2;
for (let i = 0; i < key.split(' ').length; i++) {
client.stations.filter(x => x.name.toUpperCase().includes(key.split(' ')[i].toUpperCase()) || x === key).forEach(x => foundStations.push({ station: x, name: x.name, probability: probabilityIncrement }));
}
if (foundStations.length === 0) return false;
for (let i = 0; i < foundStations.length; i++) {
for (let j = 0; j < foundStations.length; j++) {
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
}
}
for (let i = 0; i < foundStations.length; i++) {
if (foundStations[i].name.length > key.length) {
foundStations[i].probability -= (foundStations[i].name.split(' ').length - key.split(' ').length) * (probabilityIncrement * 0.5);
} else if (foundStations[i].name.length === key.length) {
foundStations[i].probability += (probabilityIncrement * 0.9);
}
for (let j = 0; j < key.split(' ').length; j++) {
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(' ')[j])) {
foundStations[i].probability -= (probabilityIncrement * 0.5);
}
}
}
let highestProbabilityStation;
console.log('Stations found: ', foundStations);
for (let i = 0; i < foundStations.length; i++) {
if (!highestProbabilityStation || highestProbabilityStation.probability < foundStations[i].probability) highestProbabilityStation = foundStations[i];
if (highestProbabilityStation && highestProbabilityStation.probability === foundStations[i].probability) {
highestProbabilityStation = foundStations[i].station;
}
}
return highestProbabilityStation;
};