mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-02 03:03:37 +00:00
Typescript Continue
This commit is contained in:
@ -28,7 +28,8 @@ export default class {
|
||||
//console.log("");
|
||||
}
|
||||
|
||||
checkEntry(id: string){
|
||||
checkEntry(id: string | undefined){
|
||||
if(!id) return;
|
||||
this.loadEntry(id);
|
||||
if(!this.map.has(id)){
|
||||
this.createEntry(id);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
|
||||
import { VoiceChannel } from "discord.js";
|
||||
import { Guild, GuildMember, VoiceChannel } from "discord.js";
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default class Radio extends Map {
|
||||
@ -32,13 +32,13 @@ export default class Radio extends Map {
|
||||
restore(client: RadioClient, guilds: any) {
|
||||
if(!client.stations) return;
|
||||
|
||||
guilds.forEach(async (guild: { id: any; }) => {
|
||||
guilds.forEach(async (guild: 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.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) return;
|
||||
if(!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
||||
if(voiceChannel.members.filter((member: GuildMember) => !member.user.bot).size === 0) return;
|
||||
|
||||
|
||||
const sstation = await client.stations?.search(state.station.name, "direct");
|
||||
|
@ -3,17 +3,23 @@ const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||
const fetch = (...args: any) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
import logger from "../funcs/logger";
|
||||
|
||||
export interface station {
|
||||
name: string,
|
||||
owner: string,
|
||||
logo: string,
|
||||
stream: []
|
||||
}
|
||||
|
||||
export default class Stations extends Array {
|
||||
logger: any;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async fetch(options: any){
|
||||
try {
|
||||
this.logger('Stations', 'Started fetching list - ' + options.url);
|
||||
logger('Stations', 'Started fetching list - ' + options.url);
|
||||
let list = await fetch(options.url)
|
||||
.then(this.checkFetchStatus)
|
||||
.then((response: { json: () => any; }) => response.json());
|
||||
@ -30,7 +36,7 @@ export default class Stations extends Array {
|
||||
|
||||
if(options.show){
|
||||
list.forEach((station: { name: any; }) => {
|
||||
this.logger('Stations', station.name);
|
||||
logger('Stations', station.name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -45,9 +51,9 @@ export default class Stations extends Array {
|
||||
});
|
||||
}
|
||||
|
||||
this.logger('Stations', 'Successfully fetched list');
|
||||
logger('Stations', 'Successfully fetched list');
|
||||
} catch (error) {
|
||||
this.logger('Stations', 'Fetching list failed');
|
||||
logger('Stations', 'Fetching list failed');
|
||||
console.error(error + "\n");
|
||||
|
||||
if(this.length == 0) this.fetch(options);
|
||||
|
@ -8,7 +8,8 @@ export default class Statistics {
|
||||
this.map = new Map();
|
||||
}
|
||||
|
||||
update(client: RadioClient, guild: Guild, radio: any) {
|
||||
update(client: RadioClient, guild: Guild | null, radio: any) {
|
||||
if(!guild) return;
|
||||
|
||||
client.datastore?.checkEntry(guild.id);
|
||||
|
||||
@ -47,18 +48,18 @@ export default class Statistics {
|
||||
let currentGuild = client.datastore.getEntry(calculation.value);
|
||||
if(calculation.value != 'global'){
|
||||
if(stations){
|
||||
Object.keys(stations).forEach(function(station) {
|
||||
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) != 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) != 0){
|
||||
if(!statistics[stations[station].name]){
|
||||
statistics[stations[station].name] = {};
|
||||
statistics[stations[station].name].time = 0;
|
||||
statistics[stations[station].name].used = 0;
|
||||
for(const station of stations) {
|
||||
if(currentGuild.statistics[station.name] && currentGuild.statistics[station.name].time && parseInt(currentGuild.statistics[station.name].time) != 0 && currentGuild.statistics[station.name].used && parseInt(currentGuild.statistics[station.name].used) != 0){
|
||||
if(!statistics[station.name]){
|
||||
statistics[station.name] = {};
|
||||
statistics[station.name].time = 0;
|
||||
statistics[station.name].used = 0;
|
||||
}
|
||||
|
||||
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
||||
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
||||
statistics[station.name].time = parseInt(statistics[station.name].time)+parseInt(currentGuild.statistics[station.name].time);
|
||||
statistics[station.name].used = parseInt(statistics[station.name].used)+parseInt(currentGuild.statistics[station.name].used);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
calculation = guilds.next();
|
||||
|
@ -10,7 +10,6 @@ export default class Streamer {
|
||||
constructor() {
|
||||
this.map = new Map();
|
||||
this.mode = null;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
init(client: RadioClient){
|
||||
@ -73,25 +72,25 @@ export default class Streamer {
|
||||
audioPlayer.play(resource);
|
||||
audioPlayer
|
||||
.on('playing', () => {
|
||||
this.logger('Streamer', station.name + " / " + "Playing");
|
||||
logger('Streamer', station.name + " / " + "Playing");
|
||||
})
|
||||
.on('idle', () => {
|
||||
this.logger('Streamer', station.name + " / " + "Idle");
|
||||
logger('Streamer', station.name + " / " + "Idle");
|
||||
audioPlayer.removeAllListeners();
|
||||
if(this.mode == "manual" && audioPlayer.subscribers.length == 0) return;
|
||||
this.play(station);
|
||||
})
|
||||
.on('paused', () => {
|
||||
this.logger('Streamer', station.name + " / " + "Paused");
|
||||
logger('Streamer', station.name + " / " + "Paused");
|
||||
})
|
||||
.on('buffering', () => {
|
||||
this.logger('Streamer', station.name + " / " + "Buffering");
|
||||
logger('Streamer', station.name + " / " + "Buffering");
|
||||
})
|
||||
.on('autopaused', () => {
|
||||
this.logger('Streamer', station.name + " / " + "AutoPaused");
|
||||
logger('Streamer', station.name + " / " + "AutoPaused");
|
||||
})
|
||||
.on('error', (error: string) => {
|
||||
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
|
||||
logger('Streamer', station.name + " / " + "Error" + "\n" + error);
|
||||
});
|
||||
return audioPlayer;
|
||||
}
|
||||
@ -99,7 +98,7 @@ export default class Streamer {
|
||||
stop(station: any){
|
||||
let audioPlayer = this.map.get(station.name);
|
||||
if(audioPlayer){
|
||||
this.logger('Streamer', station.name + " / " + "Stop");
|
||||
logger('Streamer', station.name + " / " + "Stop");
|
||||
audioPlayer.removeAllListeners();
|
||||
audioPlayer.stop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user