From 32fabe63ffa55f8ae8f83ab3c30d1579137a11e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Tue, 28 Nov 2023 22:55:11 +0200 Subject: [PATCH] Typings --- src/client/classes/Radio.ts | 15 ++++++++------- src/client/commands/next.ts | 2 ++ src/client/commands/prev.ts | 2 ++ src/client/commands/stop.ts | 8 +++++--- src/client/events/voiceStateUpdate.ts | 2 +- src/client/funcs/check.ts | 1 + 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/client/classes/Radio.ts b/src/client/classes/Radio.ts index 357c120..64c9743 100644 --- a/src/client/classes/Radio.ts +++ b/src/client/classes/Radio.ts @@ -1,19 +1,20 @@ -import { Channel, Collection, GuildMember, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js"; +import { Collection, GuildMember, Message, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js"; import { getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice"; import RadioClient from "../../Client"; import { station } from "./Stations"; import { datastore } from "./Datastore"; export interface radio { - textChannel: Channel | TextBasedChannel | undefined | null, - voiceChannel: Channel | VoiceBasedChannel | undefined, + textChannel: TextBasedChannel | undefined | null, + voiceChannel: VoiceBasedChannel | undefined, connection: VoiceConnection | null, - message: null, + message: Message | null, station: station, datastore?: datastore, currentTime?: number, startTime: number, playTime?: number, + guild?: any } export interface state { @@ -28,7 +29,7 @@ export interface state { } } -export default class Radio extends Map { +export default class Radio extends Map { constructor() { super(); @@ -75,8 +76,8 @@ export default class Radio extends Map { let date = new Date(); const construct: radio = { - textChannel: client.channels.cache.get(state.channels.text), - voiceChannel: client.channels.cache.get(state.channels.voice), + textChannel: client.channels.cache.get(state.channels.text) as TextBasedChannel, + voiceChannel: client.channels.cache.get(state.channels.voice) as VoiceBasedChannel, connection: null, message: null, station: station, diff --git a/src/client/commands/next.ts b/src/client/commands/next.ts index 60dfd46..9841603 100644 --- a/src/client/commands/next.ts +++ b/src/client/commands/next.ts @@ -9,7 +9,9 @@ export default { category: 'radio', async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { if (client.funcs.check(client, interaction, command)) { + if(!interaction.guild) return; const radio = client.radio?.get(interaction.guild?.id); + if(!radio) return; if(client.config.maintenanceMode){ return interaction.reply({ diff --git a/src/client/commands/prev.ts b/src/client/commands/prev.ts index fa8e39c..05191a6 100644 --- a/src/client/commands/prev.ts +++ b/src/client/commands/prev.ts @@ -9,7 +9,9 @@ export default { category: 'radio', async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { if (client.funcs.check(client, interaction, command)) { + if(!interaction.guild) return; const radio = client.radio?.get(interaction.guild?.id); + if(!radio) return; if(client.config.maintenanceMode){ return interaction.reply({ diff --git a/src/client/commands/stop.ts b/src/client/commands/stop.ts index 18276be..3b405a3 100644 --- a/src/client/commands/stop.ts +++ b/src/client/commands/stop.ts @@ -8,7 +8,9 @@ export default { category: 'radio', async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { if (client.funcs.check(client, interaction, command)) { + if(!interaction.guild) return; const radio = client.radio?.get(interaction.guild?.id); + if(!radio) return; client.statistics?.update(client, interaction.guild, radio); radio.connection?.destroy(); client.funcs.logger('Radio', interaction.guild?.id + " / " + 'Stop'); @@ -28,9 +30,9 @@ export default { }); if(!radio.message){ - radio.message = radio.textChannel.send({ embeds: [embed], components: [] }); + radio.message = await radio.textChannel?.send({ embeds: [embed], components: [] }) ?? null; } else { - if(radio.textChannel.id == radio.message.channel.id){ + if(radio.textChannel?.id == radio.message.channel.id){ radio.message.edit({ embeds: [embed], components: [] }); } else { radio.message?.delete(); @@ -41,7 +43,7 @@ export default { await radio.message?.delete(); }, 5000); - client.radio?.delete(interaction.guild?.id); + client.radio?.delete(interaction.guild.id); interaction.reply({ content: client.messages.emojis["stop"] + client.messages.stop, diff --git a/src/client/events/voiceStateUpdate.ts b/src/client/events/voiceStateUpdate.ts index 8caad08..b848eec 100644 --- a/src/client/events/voiceStateUpdate.ts +++ b/src/client/events/voiceStateUpdate.ts @@ -53,7 +53,7 @@ export default async function voiceStateUpdate(client: RadioClient, oldState: Vo if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && oldState.channel === radio.voiceChannel) || change) { setTimeout(() => { if (!radio || !radio.connection || !radio.connection === null) return; - if (radio.voiceChannel.members.filter((member: GuildMember) => !member.user.bot).size === 0) { + if (radio.voiceChannel?.members.filter((member: GuildMember) => !member.user.bot).size === 0) { client.statistics?.update(client, newState.guild, radio); radio.connection?.destroy(); radio.message?.delete(); diff --git a/src/client/funcs/check.ts b/src/client/funcs/check.ts index 63b6252..2659599 100644 --- a/src/client/funcs/check.ts +++ b/src/client/funcs/check.ts @@ -4,6 +4,7 @@ import { command } from "../commands"; export default function check(client: RadioClient, interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, command: command) { + if(!interaction.guild) return; const radio = client.radio?.get(interaction.guild?.id); if(!client.stations) { interaction.reply({