Replace any types to more strict types

This commit is contained in:
Christer Warén 2023-06-06 04:58:01 +03:00
parent bc238d919d
commit 3686cd1b0e
7 changed files with 29 additions and 27 deletions

View File

@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
export default class { export default class {
map: Map<any, any>; map: Map<string, any>;
constructor() { constructor() {
this.map = new Map(); this.map = new Map();
this.loadData(); this.loadData();
@ -49,7 +49,7 @@ export default class {
this.saveEntry(id, newData); this.saveEntry(id, newData);
} }
loadEntry(id: any){ loadEntry(id: string){
try { try {
const json = require(`../../../datastore/` + id + '.json'); const json = require(`../../../datastore/` + id + '.json');
this.map.set(id, json); this.map.set(id, json);

View File

@ -7,7 +7,7 @@ export interface station {
name: string, name: string,
owner: string, owner: string,
logo: string, logo: string,
stream: [] stream: any
} }
export default class Stations extends Array { export default class Stations extends Array {
@ -22,11 +22,11 @@ export default class Stations extends Array {
logger('Stations', 'Started fetching list - ' + options.url); logger('Stations', 'Started fetching list - ' + options.url);
let list = await fetch(options.url) let list = await fetch(options.url)
.then(this.checkFetchStatus) .then(this.checkFetchStatus)
.then((response: { json: () => any; }) => response.json()); .then((response: { json: () => station; }) => response.json());
if(list){ if(list){
this.length = 0; this.length = 0;
list.forEach((station: any) => { list.forEach((station: station) => {
try { try {
this.push(station); this.push(station);
} catch (error) { } catch (error) {
@ -61,7 +61,7 @@ export default class Stations extends Array {
} }
checkFetchStatus(response: any) { checkFetchStatus(response: any) {
if (response.ok) { // res.status >= 200 && res.status < 300 if (response.ok) {
return response; return response;
} else { } else {
throw new Error(response.status + " " + response.statusText); throw new Error(response.status + " " + response.statusText);

View File

@ -1,6 +1,7 @@
import logger from "../funcs/logger"; import logger from "../funcs/logger";
import { createAudioPlayer, createAudioResource, NoSubscriberBehavior } from "@discordjs/voice"; import { createAudioPlayer, createAudioResource, NoSubscriberBehavior } from "@discordjs/voice";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { station } from "./Stations";
export default class Streamer { export default class Streamer {
map: any; map: any;
@ -29,7 +30,7 @@ export default class Streamer {
if(this.mode == "auto"){ if(this.mode == "auto"){
if(!client.stations) return; if(!client.stations) return;
client.stations.forEach((station: any) => { client.stations.forEach((station: station) => {
this.play(station); this.play(station);
}); });
} }
@ -40,13 +41,13 @@ export default class Streamer {
let streamers = this.map.keys(); let streamers = this.map.keys();
streamers.forEach((streamer: any) => { streamers.forEach((streamer: any) => {
if(client.stations?.findIndex((station: { name: any; }) => station.name == streamer) == -1){ if(client.stations?.findIndex((station: station) => station.name == streamer) == -1){
this.stop(streamer); this.stop(streamer);
} }
}); });
} }
play(station: any) { play(station: station) {
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(!audioPlayer) { if(!audioPlayer) {
if(this.mode == "auto"){ if(this.mode == "auto"){
@ -95,7 +96,7 @@ export default class Streamer {
return audioPlayer; return audioPlayer;
} }
stop(station: any){ stop(station: station){
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(audioPlayer){ if(audioPlayer){
logger('Streamer', station.name + " / " + "Stop"); logger('Streamer', station.name + " / " + "Stop");
@ -105,7 +106,7 @@ export default class Streamer {
this.map.delete(station.name); this.map.delete(station.name);
} }
listen(station: any) { listen(station: station) {
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(!audioPlayer || this.mode == "manual" && audioPlayer.subscribers.length == 0) audioPlayer = this.play(station); if(!audioPlayer || this.mode == "manual" && audioPlayer.subscribers.length == 0) audioPlayer = this.play(station);
return audioPlayer; return audioPlayer;
@ -113,7 +114,7 @@ export default class Streamer {
leave(client: RadioClient) { leave(client: RadioClient) {
if(!client.stations) return; if(!client.stations) return;
client.stations.forEach((station: any) => { client.stations.forEach((station: station) => {
this.stop(station); this.stop(station);
}); });
} }

View File

@ -1,12 +1,13 @@
import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js"; import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { station } from "../classes/Stations" import { station } from "../classes/Stations"
import { command } from "../commands";
export default { export default {
name: 'next', name: 'next',
description: 'Next Station', description: 'Next Station',
category: 'radio', category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) { async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);

View File

@ -1,20 +1,19 @@
import { ActionRowBuilder, StringSelectMenuBuilder } from "discord.js"; import { ActionRowBuilder, SelectMenuComponentOptionData, StringSelectMenuBuilder } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { station } from "../classes/Stations";
export default function listStations(client: RadioClient, interaction: any){ export default function listStations(client: RadioClient, interaction: any){
let stations: any = new Array();
let options: any = new Array();
if(!client.stations) return; if(!client.stations) return;
stations = client.stations.forEach((station: { name?: any; owner?: any; label?: any; description?: any; value?: any; }) => { let options : SelectMenuComponentOptionData[] = new Array();
client.stations.forEach((station: station) => {
if(station.name == "GrooveFM") return; if(station.name == "GrooveFM") return;
station = { options.push({
label: station.name, label: station.name,
description: station.owner, description: station.owner,
value: station.name value: station.name
}; });
options.push(station);
}); });
const menu = new ActionRowBuilder() const menu = new ActionRowBuilder()
@ -25,9 +24,6 @@ export default function listStations(client: RadioClient, interaction: any){
.addOptions(options) .addOptions(options)
); );
stations = null;
options = null;
return interaction.reply({ return interaction.reply({
content: '**Select station:**', content: '**Select station:**',
components: [menu], components: [menu],

View File

@ -1,8 +1,11 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ColorResolvable, EmbedBuilder } from "discord.js"; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, Guild, StringSelectMenuInteraction } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { station } from "../classes/Stations";
export default async function play(client: RadioClient, interaction: any, guild: any, station: any) { export default async function play(client: RadioClient, interaction: ChatInputCommandInteraction | StringSelectMenuInteraction | null, guild: Guild | null, station: station) {
if(!guild) return;
let message: any = {}; let message: any = {};
const radio = client.radio?.get(guild.id); const radio = client.radio?.get(guild.id);
const audioPlayer = client.streamer?.listen(station); const audioPlayer = client.streamer?.listen(station);
radio.connection.subscribe(audioPlayer); radio.connection.subscribe(audioPlayer);

View File

@ -1,6 +1,7 @@
import { Guild } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
export default function saveState(client: RadioClient, guild: any, radio: any){ export default function saveState(client: RadioClient, guild: Guild, radio: any){
if(!client.datastore) return; if(!client.datastore) return;
client.datastore.checkEntry(guild.id); client.datastore.checkEntry(guild.id);