Fix typings

This commit is contained in:
Christer Warén 2024-09-30 13:22:31 +03:00
parent a1403d7047
commit 973cd00c82
9 changed files with 36 additions and 36 deletions

View File

@ -76,7 +76,7 @@ export default class Datastore {
return this.map.get(id); 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; newData.guild.name = guild.name;
let date = new Date(); let date = new Date();

View File

@ -1,20 +1,20 @@
import { Collection, GuildMember, Message, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js"; import { Collection, GuildMember, Message, Guild, OAuth2Guild, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js";
import { getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice"; import { DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { station } from "./Stations"; import { station } from "./Stations";
import { datastore } from "./Datastore"; import { datastore } from "./Datastore";
export interface radio { export interface radio {
textChannel: TextBasedChannel | undefined | null, textChannel: TextBasedChannel | null,
voiceChannel: VoiceBasedChannel | undefined, voiceChannel: VoiceBasedChannel | null,
connection: VoiceConnection | null, connection: VoiceConnection | undefined,
message: Message | null, message: Message | null,
station: station, station: station,
datastore?: datastore, datastore?: datastore,
currentTime?: number, currentTime?: number,
startTime: number, startTime: number,
playTime?: number, playTime?: number,
guild?: any guild?: Guild | { id: string, name?: string }
} }
export interface state { export interface state {
@ -78,10 +78,11 @@ export default class Radio extends Map<string, radio> {
const construct: radio = { const construct: radio = {
textChannel: client.channels.cache.get(state.channels.text) as TextBasedChannel, textChannel: client.channels.cache.get(state.channels.text) as TextBasedChannel,
voiceChannel: client.channels.cache.get(state.channels.voice) as VoiceBasedChannel, voiceChannel: client.channels.cache.get(state.channels.voice) as VoiceBasedChannel,
connection: null, connection: undefined,
message: null, message: null,
station: station, station: station,
startTime: date.getTime() startTime: date.getTime(),
guild: guild
}; };
this.set(guild.id, construct); this.set(guild.id, construct);
@ -91,7 +92,7 @@ export default class Radio extends Map<string, radio> {
joinVoiceChannel({ joinVoiceChannel({
channelId: voiceChannel.id, channelId: voiceChannel.id,
guildId: voiceChannel.guild.id, guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator adapterCreator: voiceChannel.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator
}); });
construct.connection = connection; construct.connection = connection;

View File

@ -1,4 +1,4 @@
import { Guild } from "discord.js"; import { Guild, OAuth2Guild } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { radio } from "./Radio"; import { radio } from "./Radio";
@ -18,7 +18,7 @@ export default class Statistics {
this.map = new Map(); 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; if(!guild) return;
client.datastore?.checkEntry(guild.id); client.datastore?.checkEntry(guild.id);

View File

@ -1,5 +1,5 @@
import { ApplicationCommandOptionType, ChatInputCommandInteraction, GuildMember, PermissionFlagsBits, StringSelectMenuInteraction } from "discord.js"; 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 RadioClient from "../../Client";
import { radio } from "../classes/Radio" import { radio } from "../classes/Radio"
@ -129,10 +129,11 @@ export default {
const construct: radio = { const construct: radio = {
textChannel: interaction.channel, textChannel: interaction.channel,
voiceChannel: voiceChannel, voiceChannel: voiceChannel,
connection: null, connection: undefined,
message: null, message: null,
station: station, station: station,
startTime: date.getTime() startTime: date.getTime(),
guild: interaction.guild
}; };
client.radio?.set(interaction.guild?.id, construct); client.radio?.set(interaction.guild?.id, construct);
@ -142,7 +143,7 @@ export default {
joinVoiceChannel({ joinVoiceChannel({
channelId: voiceChannel.id, channelId: voiceChannel.id,
guildId: voiceChannel.guild.id, guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator adapterCreator: voiceChannel.guild?.voiceAdapterCreator as DiscordGatewayAdapterCreator
}); });
construct.connection = connection; construct.connection = connection;
let date = new Date(); let date = new Date();

View File

@ -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 RadioClient from "../../Client";
import { command } from "../commands"; import { command } from "../commands";
@ -11,6 +11,7 @@ export default {
if(!interaction.guild) return; if(!interaction.guild) return;
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!radio) return; if(!radio) return;
if(radio.textChannel?.type == ChannelType.DM || radio.textChannel?.type == ChannelType.GroupDM) return;
client.statistics?.update(client, interaction.guild, radio); client.statistics?.update(client, interaction.guild, radio);
radio.connection?.destroy(); radio.connection?.destroy();
client.funcs.logger('Radio', interaction.guild?.id + " / " + 'Stop'); client.funcs.logger('Radio', interaction.guild?.id + " / " + 'Stop');

View File

@ -3,8 +3,8 @@ import RadioClient from "../../Client";
export default function interactionCreate(client: RadioClient, interaction: Interaction) { export default function interactionCreate(client: RadioClient, interaction: Interaction) {
if(!(interaction.isButton()) && !(interaction.isChatInputCommand()) && !(interaction.isStringSelectMenu())) return; 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); const permissions = interaction.channel?.permissionsFor(interaction.client.user);
if (!permissions?.has(PermissionFlagsBits.ViewChannel)) return; if (!permissions?.has(PermissionFlagsBits.ViewChannel)) return;
@ -12,7 +12,6 @@ export default function interactionCreate(client: RadioClient, interaction: Inte
content: client.messages.emojis["error"] + client.messages.noPermsEmbed, content: client.messages.emojis["error"] + client.messages.noPermsEmbed,
ephemeral: true ephemeral: true
}); });
}
if(interaction.isChatInputCommand()){ if(interaction.isChatInputCommand()){
const commandName = interaction.commandName; const commandName = interaction.commandName;

View File

@ -1,9 +1,6 @@
import { GuildMember, PermissionFlagsBits, VoiceState } from "discord.js"; import { GuildMember, PermissionFlagsBits, VoiceState } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
const { import { DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
getVoiceConnection,
joinVoiceChannel
} = require("@discordjs/voice");
export default async function voiceStateUpdate(client: RadioClient, oldState: VoiceState, newState: VoiceState) { export default async function voiceStateUpdate(client: RadioClient, oldState: VoiceState, newState: VoiceState) {
if (oldState.channel === null) return; if (oldState.channel === null) return;
@ -27,9 +24,9 @@ export default async function voiceStateUpdate(client: RadioClient, oldState: Vo
setTimeout( setTimeout(
async () => ( async () => (
radio.connection = joinVoiceChannel({ radio.connection = joinVoiceChannel({
channelId: oldState.channel?.id, channelId: oldState.channel?.id as string,
guildId: oldState.channel?.guild.id, guildId: oldState.channel?.guild.id as string,
adapterCreator: oldState.channel?.guild.voiceAdapterCreator adapterCreator: oldState.channel?.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator
}) })
), ),
1000 1000

View File

@ -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 RadioClient from "../../Client";
import { station } from "../classes/Stations"; 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); const radio = client.radio?.get(guild.id);
if(!radio) return; if(!radio) return;
if(radio.textChannel?.type == ChannelType.DM || radio.textChannel?.type == ChannelType.GroupDM) return;
const audioPlayer = client.streamer?.listen(station); const audioPlayer = client.streamer?.listen(station);
if(!audioPlayer) return; if(!audioPlayer) return;
radio.connection?.subscribe(audioPlayer); radio.connection?.subscribe(audioPlayer);
@ -123,7 +124,7 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
let timer : NodeJS.Timeout = setInterval(async function(){ let timer : NodeJS.Timeout = setInterval(async function(){
const radio = client.radio?.get(guild.id); 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); return clearInterval(timer);
} }

View File

@ -2,8 +2,8 @@ import { Guild } from "discord.js";
import RadioClient from "../../Client"; import RadioClient from "../../Client";
import { radio } from "../classes/Radio"; import { radio } from "../classes/Radio";
export default function saveState(client: RadioClient, guild: Guild, radio: radio){ export default function saveState(client: RadioClient, guild: Guild | { id: string, name?: string } | undefined, radio: radio){
if(!client.datastore) return; if(!client.datastore || !guild) return;
client.datastore.checkEntry(guild.id); client.datastore.checkEntry(guild.id);
let date = new Date(); let date = new Date();