Remove few functions

This commit is contained in:
Christer Warén 2021-09-16 04:48:58 +03:00
parent 330c33b3d7
commit 348b540c06
5 changed files with 0 additions and 170 deletions

View File

@ -1,7 +0,0 @@
module.exports = function checkFetchStatus(response) {
if (response.ok) { // res.status >= 200 && res.status < 300
return response;
} else {
throw new Error(response.status + " " + response.statusText);
}
}

View File

@ -1,59 +0,0 @@
import Discord from "discord.js";
const {
getVoiceConnection,
joinVoiceChannel
} = require("@discordjs/voice");
module.exports = async function restoreRadios(client, guilds) {
if(!client.stations) return;
guilds.forEach(async guild => {
let state = client.funcs.loadState(client, guild);
if(!state) return;
if(!state.station || !state.channels.voice || !state.channels.text) return;
let voiceChannel = client.channels.cache.get(state.channels.voice);
if(!voiceChannel) return;
if(voiceChannel.members.size === 0) return;
const sstation = await client.funcs.searchStation(state.station.name, client);
let station = sstation;
const construct = {
textChannel: client.channels.cache.get(state.channels.text),
voiceChannel: client.channels.cache.get(state.channels.voice),
connection: null,
message: null,
station: station
};
client.radio.set(guild.id, construct);
try {
const connection =
getVoiceConnection(guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
client.funcs.play(client, null, guild, station);
client.datastore.checkEntry(guild.id);
construct.datastore = client.datastore.getEntry(guild.id);
if (!construct.datastore.statistics[construct.station.name]) {
construct.datastore.statistics[construct.station.name] = {};
construct.datastore.statistics[construct.station.name].time = 0;
construct.datastore.statistics[construct.station.name].used = 0;
client.datastore.updateEntry(guild, construct.datastore);
}
} catch (error) {
console.log(error);
}
});
}

View File

@ -1,20 +0,0 @@
module.exports = function saveRadios(client) {
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
while (!radio.done) {
let currentRadio = client.radio.get(radio.value);
if (currentRadio) {
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.message?.delete();
client.radio.delete(radio.value);
}
radio = currentRadios.next();
}
}

View File

@ -1,62 +0,0 @@
module.exports = function searchStation(key, client) {
if (client.stations === null) return false;
let foundStations = [];
if (!key) return false;
if (key == "radio") return false;
client.stations
.filter(
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: 100 })
);
if (key.startsWith("radio ")) key = key.slice(6);
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;
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;
}

View File

@ -1,22 +0,0 @@
module.exports = function statisticsUpdate(client, guild, radio) {
client.datastore.checkEntry(guild.id);
radio.datastore = client.datastore.getEntry(guild.id);
if(!radio.datastore.statistics[radio.station.name]){
radio.datastore.statistics[radio.station.name] = {};
radio.datastore.statistics[radio.station.name].time = 0;
radio.datastore.statistics[radio.station.name].used = 0;
client.datastore.updateEntry(guild, radio.datastore);
}
let date = new Date();
radio.currentTime = date.getTime();
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime);
radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1;
client.datastore.updateEntry(guild, radio.datastore);
client.datastore.calculateGlobal(client);
}