mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 12:23:38 +00:00
Search Stations and large update
This commit is contained in:
@ -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 })
|
||||
|
36
struct/funcs/searchStation.js
Normal file
36
struct/funcs/searchStation.js
Normal 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;
|
||||
};
|
Reference in New Issue
Block a user