diff --git a/src/client/classes/Datastore.ts b/src/client/classes/Datastore.ts index 9f4f1fe..1a5f65e 100644 --- a/src/client/classes/Datastore.ts +++ b/src/client/classes/Datastore.ts @@ -76,7 +76,7 @@ export default class Datastore { return this.map.get(id); } - updateEntry(guild: Guild | { id: string, name: string }, newData: datastore) { + updateEntry(guild: Guild | { id: string, name?: string }, newData: datastore) { newData.guild.name = guild.name; let date = new Date(); diff --git a/src/client/classes/Radio.ts b/src/client/classes/Radio.ts index 64c9743..6de5d49 100644 --- a/src/client/classes/Radio.ts +++ b/src/client/classes/Radio.ts @@ -1,20 +1,20 @@ -import { Collection, GuildMember, Message, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js"; -import { getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice"; +import { Collection, GuildMember, Message, Guild, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js"; +import { DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice"; import RadioClient from "../../Client"; import { station } from "./Stations"; import { datastore } from "./Datastore"; export interface radio { - textChannel: TextBasedChannel | undefined | null, - voiceChannel: VoiceBasedChannel | undefined, - connection: VoiceConnection | null, + textChannel: TextBasedChannel | null, + voiceChannel: VoiceBasedChannel | null, + connection: VoiceConnection | undefined, message: Message | null, station: station, datastore?: datastore, currentTime?: number, startTime: number, playTime?: number, - guild?: any + guild?: Guild | { id: string, name?: string } } export interface state { @@ -78,10 +78,11 @@ export default class Radio extends Map { const construct: radio = { textChannel: client.channels.cache.get(state.channels.text) as TextBasedChannel, voiceChannel: client.channels.cache.get(state.channels.voice) as VoiceBasedChannel, - connection: null, + connection: undefined, message: null, station: station, - startTime: date.getTime() + startTime: date.getTime(), + guild: guild }; this.set(guild.id, construct); @@ -91,7 +92,7 @@ export default class Radio extends Map { joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, - adapterCreator: voiceChannel.guild.voiceAdapterCreator + adapterCreator: voiceChannel.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator }); construct.connection = connection; diff --git a/src/client/classes/Statistics.ts b/src/client/classes/Statistics.ts index 78ea997..130b749 100644 --- a/src/client/classes/Statistics.ts +++ b/src/client/classes/Statistics.ts @@ -1,4 +1,4 @@ -import { Guild } from "discord.js"; +import { Guild, OAuth2Guild } from "discord.js"; import RadioClient from "../../Client"; import { radio } from "./Radio"; @@ -18,7 +18,7 @@ export default class Statistics { this.map = new Map(); } - update(client: RadioClient, guild: Guild | null, radio: radio) { + update(client: RadioClient, guild: Guild | { id: string, name?: string } | undefined, radio: radio) { if(!guild) return; client.datastore?.checkEntry(guild.id); diff --git a/src/client/commands/play.ts b/src/client/commands/play.ts index 3b4545e..a3b6082 100644 --- a/src/client/commands/play.ts +++ b/src/client/commands/play.ts @@ -1,5 +1,5 @@ import { ApplicationCommandOptionType, ChatInputCommandInteraction, GuildMember, PermissionFlagsBits, StringSelectMenuInteraction } from "discord.js"; -import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; +import { DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; import RadioClient from "../../Client"; import { radio } from "../classes/Radio" @@ -129,10 +129,11 @@ export default { const construct: radio = { textChannel: interaction.channel, voiceChannel: voiceChannel, - connection: null, + connection: undefined, message: null, station: station, - startTime: date.getTime() + startTime: date.getTime(), + guild: interaction.guild }; client.radio?.set(interaction.guild?.id, construct); @@ -142,7 +143,7 @@ export default { joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, - adapterCreator: voiceChannel.guild.voiceAdapterCreator + adapterCreator: voiceChannel.guild?.voiceAdapterCreator as DiscordGatewayAdapterCreator }); construct.connection = connection; let date = new Date(); diff --git a/src/client/commands/stop.ts b/src/client/commands/stop.ts index 3b405a3..2a6df58 100644 --- a/src/client/commands/stop.ts +++ b/src/client/commands/stop.ts @@ -1,4 +1,4 @@ -import { ButtonInteraction, ChatInputCommandInteraction, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; +import { ButtonInteraction, ChannelType, ChatInputCommandInteraction, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; import RadioClient from "../../Client"; import { command } from "../commands"; @@ -11,6 +11,7 @@ export default { if(!interaction.guild) return; const radio = client.radio?.get(interaction.guild?.id); if(!radio) return; + if(radio.textChannel?.type == ChannelType.DM || radio.textChannel?.type == ChannelType.GroupDM) return; client.statistics?.update(client, interaction.guild, radio); radio.connection?.destroy(); client.funcs.logger('Radio', interaction.guild?.id + " / " + 'Stop'); diff --git a/src/client/events/interactionCreate.ts b/src/client/events/interactionCreate.ts index 8a5986d..484d932 100644 --- a/src/client/events/interactionCreate.ts +++ b/src/client/events/interactionCreate.ts @@ -3,16 +3,15 @@ import RadioClient from "../../Client"; export default function interactionCreate(client: RadioClient, interaction: Interaction) { if(!(interaction.isButton()) && !(interaction.isChatInputCommand()) && !(interaction.isStringSelectMenu())) return; + if(interaction.channel?.type == ChannelType.DM || interaction.channel?.type == ChannelType.GroupDM) return; - if(interaction.channel?.type != ChannelType.DM){ - const permissions = interaction.channel?.permissionsFor(interaction.client.user); - if (!permissions?.has(PermissionFlagsBits.ViewChannel)) return; + const permissions = interaction.channel?.permissionsFor(interaction.client.user); + if (!permissions?.has(PermissionFlagsBits.ViewChannel)) return; - if (!permissions?.has(PermissionFlagsBits.EmbedLinks)) return interaction.reply({ - content: client.messages.emojis["error"] + client.messages.noPermsEmbed, - ephemeral: true - }); - } + if (!permissions?.has(PermissionFlagsBits.EmbedLinks)) return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.noPermsEmbed, + ephemeral: true + }); if(interaction.isChatInputCommand()){ const commandName = interaction.commandName; diff --git a/src/client/events/voiceStateUpdate.ts b/src/client/events/voiceStateUpdate.ts index b848eec..95dceed 100644 --- a/src/client/events/voiceStateUpdate.ts +++ b/src/client/events/voiceStateUpdate.ts @@ -1,9 +1,6 @@ import { GuildMember, PermissionFlagsBits, VoiceState } from "discord.js"; import RadioClient from "../../Client"; -const { - getVoiceConnection, - joinVoiceChannel -} = require("@discordjs/voice"); +import { DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; export default async function voiceStateUpdate(client: RadioClient, oldState: VoiceState, newState: VoiceState) { if (oldState.channel === null) return; @@ -27,9 +24,9 @@ export default async function voiceStateUpdate(client: RadioClient, oldState: Vo setTimeout( async () => ( radio.connection = joinVoiceChannel({ - channelId: oldState.channel?.id, - guildId: oldState.channel?.guild.id, - adapterCreator: oldState.channel?.guild.voiceAdapterCreator + channelId: oldState.channel?.id as string, + guildId: oldState.channel?.guild.id as string, + adapterCreator: oldState.channel?.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator }) ), 1000 diff --git a/src/client/funcs/play.ts b/src/client/funcs/play.ts index 1b8cab0..7ce8707 100644 --- a/src/client/funcs/play.ts +++ b/src/client/funcs/play.ts @@ -1,4 +1,4 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, EmbedBuilder, Guild, OAuth2Guild, StringSelectMenuInteraction } from "discord.js"; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, ChatInputCommandInteraction, EmbedBuilder, Guild, OAuth2Guild, StringSelectMenuInteraction } from "discord.js"; import RadioClient from "../../Client"; import { station } from "../classes/Stations"; @@ -7,6 +7,7 @@ export default async function play(client: RadioClient, interaction: ChatInputCo const radio = client.radio?.get(guild.id); if(!radio) return; + if(radio.textChannel?.type == ChannelType.DM || radio.textChannel?.type == ChannelType.GroupDM) return; const audioPlayer = client.streamer?.listen(station); if(!audioPlayer) return; radio.connection?.subscribe(audioPlayer); @@ -123,7 +124,7 @@ export default async function play(client: RadioClient, interaction: ChatInputCo let timer : NodeJS.Timeout = setInterval(async function(){ const radio = client.radio?.get(guild.id); - if(!radio || !oldRadio || radio.station.name != oldRadio.station.name) { + if(!radio || !oldRadio || radio.station.name != oldRadio.station.name || radio.textChannel?.type == ChannelType.DM || radio.textChannel?.type == ChannelType.GroupDM) { return clearInterval(timer); } diff --git a/src/client/funcs/saveState.ts b/src/client/funcs/saveState.ts index 63a6dd5..73f9177 100644 --- a/src/client/funcs/saveState.ts +++ b/src/client/funcs/saveState.ts @@ -2,8 +2,8 @@ import { Guild } from "discord.js"; import RadioClient from "../../Client"; import { radio } from "../classes/Radio"; -export default function saveState(client: RadioClient, guild: Guild, radio: radio){ - if(!client.datastore) return; +export default function saveState(client: RadioClient, guild: Guild | { id: string, name?: string } | undefined, radio: radio){ + if(!client.datastore || !guild) return; client.datastore.checkEntry(guild.id); let date = new Date();