Typescript Continuum

This commit is contained in:
Christer Warén
2023-06-05 00:13:15 +03:00
parent 0e62861e33
commit c584e3632e
33 changed files with 152 additions and 94 deletions

View File

@ -1,4 +1,6 @@
import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
import { VoiceChannel } from "discord.js";
import RadioClient from "../../Client";
export default class Radio extends Map {
@ -6,7 +8,7 @@ export default class Radio extends Map {
super();
}
save(client: any) {
save(client: RadioClient) {
let currentRadios = this.keys();
let radio = currentRadios.next();
@ -14,9 +16,9 @@ export default class Radio extends Map {
let currentRadio = this.get(radio.value);
if (currentRadio) {
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
currentRadio.guild = client.datastore?.getEntry(radio.value).guild;
client.statistics.update(client, currentRadio.guild, currentRadio);
client.statistics?.update(client, currentRadio.guild, currentRadio);
client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.message?.delete();
@ -27,7 +29,7 @@ export default class Radio extends Map {
}
}
restore(client: any, guilds: any) {
restore(client: RadioClient, guilds: any) {
if(!client.stations) return;
guilds.forEach(async (guild: { id: any; }) => {
@ -39,7 +41,7 @@ export default class Radio extends Map {
if(voiceChannel.members.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) return;
const sstation = await client.stations.search(state.station.name, "direct");
const sstation = await client.stations?.search(state.station.name, "direct");
let station = sstation;
if(!station) return;
@ -65,7 +67,7 @@ export default class Radio extends Map {
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
client.datastore.checkEntry(guild.id);
client.datastore?.checkEntry(guild.id);
client.funcs.play(client, null, guild, station);
} catch (error) {
console.log(error);

View File

@ -1,4 +1,5 @@
import { Guild } from "discord.js";
import RadioClient from "../../Client";
export default class Statistics {
map: any;
@ -7,17 +8,17 @@ export default class Statistics {
this.map = new Map();
}
update(client: any, guild: Guild, radio: any) {
update(client: RadioClient, guild: Guild, radio: any) {
client.datastore.checkEntry(guild.id);
client.datastore?.checkEntry(guild.id);
radio.datastore = client.datastore.getEntry(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);
client.datastore?.updateEntry(guild, radio.datastore);
}
let date = new Date();
@ -26,13 +27,13 @@ export default class Statistics {
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?.updateEntry(guild, radio.datastore);
this.calculateGlobal(client);
}
calculateGlobal(client: any){
calculateGlobal(client: RadioClient){
if(!client.stations) return;
if(!client.datastore.map) return;
if(!client.datastore?.map) return;
let guilds = client.datastore.map.keys();
let stations = client.stations;

View File

@ -1,5 +1,6 @@
import logger from "../funcs/logger";
import { createAudioPlayer, createAudioResource, NoSubscriberBehavior } from "@discordjs/voice";
import RadioClient from "../../Client";
export default class Streamer {
map: any;
@ -12,7 +13,7 @@ export default class Streamer {
this.logger = logger;
}
init(client: any){
init(client: RadioClient){
if(!client.config.streamerMode) return;
switch(client.config.streamerMode){
@ -35,12 +36,12 @@ export default class Streamer {
}
}
refresh(client: any){
refresh(client: RadioClient){
this.init(client);
let streamers = this.map.keys();
streamers.forEach((streamer: any) => {
if(client.stations.findIndex((station: { name: any; }) => station.name == streamer) == -1){
if(client.stations?.findIndex((station: { name: any; }) => station.name == streamer) == -1){
this.stop(streamer);
}
});
@ -111,7 +112,7 @@ export default class Streamer {
return audioPlayer;
}
leave(client: any) {
leave(client: RadioClient) {
if(!client.stations) return;
client.stations.forEach((station: any) => {
this.stop(station);