diff --git a/src/Client.ts b/src/Client.ts index 4208f17..29840f9 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -4,7 +4,7 @@ import Radio from "./client/classes/Radio"; import Stations from "./client/classes/Stations"; import Streamer from "./client/classes/Streamer"; import Statistics from "./client/classes/Statistics"; -import { command } from "./client/utils/typings"; +import { command } from "./client/commands"; import config from "./config"; import messages from "./client/messages"; import events from "./client/events" @@ -28,6 +28,8 @@ export default class RadioClient extends Client { public streamer: Streamer | null; public statistics: Statistics | null; public radio: Radio | null; + public messageEmojis: any | null; + public developers: string | undefined; constructor() { super({ @@ -39,6 +41,7 @@ export default class RadioClient extends Client { this.streamer = null; this.statistics = null; this.radio = null; + this.messageEmojis = null; this.events = events; this.funcs = funcs; diff --git a/src/client/classes/Radio.ts b/src/client/classes/Radio.ts index 21d7f4d..690979d 100644 --- a/src/client/classes/Radio.ts +++ b/src/client/classes/Radio.ts @@ -1,4 +1,6 @@ import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; +import { VoiceChannel } from "discord.js"; +import RadioClient from "../../Client"; export default class Radio extends Map { @@ -6,7 +8,7 @@ export default class Radio extends Map { super(); } - save(client: any) { + save(client: RadioClient) { let currentRadios = this.keys(); let radio = currentRadios.next(); @@ -14,9 +16,9 @@ export default class Radio extends Map { let currentRadio = this.get(radio.value); if (currentRadio) { - currentRadio.guild = client.datastore.getEntry(radio.value).guild; + currentRadio.guild = client.datastore?.getEntry(radio.value).guild; - client.statistics.update(client, currentRadio.guild, currentRadio); + client.statistics?.update(client, currentRadio.guild, currentRadio); client.funcs.saveState(client, currentRadio.guild, currentRadio); currentRadio.connection?.destroy(); currentRadio.message?.delete(); @@ -27,7 +29,7 @@ export default class Radio extends Map { } } - restore(client: any, guilds: any) { + restore(client: RadioClient, guilds: any) { if(!client.stations) return; guilds.forEach(async (guild: { id: any; }) => { @@ -39,7 +41,7 @@ export default class Radio extends Map { if(voiceChannel.members.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) return; - const sstation = await client.stations.search(state.station.name, "direct"); + const sstation = await client.stations?.search(state.station.name, "direct"); let station = sstation; if(!station) return; @@ -65,7 +67,7 @@ export default class Radio extends Map { construct.connection = connection; let date = new Date(); construct.startTime = date.getTime(); - client.datastore.checkEntry(guild.id); + client.datastore?.checkEntry(guild.id); client.funcs.play(client, null, guild, station); } catch (error) { console.log(error); diff --git a/src/client/classes/Statistics.ts b/src/client/classes/Statistics.ts index 25e264c..d2dc52f 100644 --- a/src/client/classes/Statistics.ts +++ b/src/client/classes/Statistics.ts @@ -1,4 +1,5 @@ import { Guild } from "discord.js"; +import RadioClient from "../../Client"; export default class Statistics { map: any; @@ -7,17 +8,17 @@ export default class Statistics { this.map = new Map(); } - update(client: any, guild: Guild, radio: any) { + update(client: RadioClient, guild: Guild, radio: any) { - client.datastore.checkEntry(guild.id); + client.datastore?.checkEntry(guild.id); - radio.datastore = client.datastore.getEntry(guild.id); + radio.datastore = client.datastore?.getEntry(guild.id); if(!radio.datastore.statistics[radio.station.name]){ radio.datastore.statistics[radio.station.name] = {}; radio.datastore.statistics[radio.station.name].time = 0; radio.datastore.statistics[radio.station.name].used = 0; - client.datastore.updateEntry(guild, radio.datastore); + client.datastore?.updateEntry(guild, radio.datastore); } let date = new Date(); @@ -26,13 +27,13 @@ export default class Statistics { radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime); radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1; - client.datastore.updateEntry(guild, radio.datastore); + client.datastore?.updateEntry(guild, radio.datastore); this.calculateGlobal(client); } - calculateGlobal(client: any){ + calculateGlobal(client: RadioClient){ if(!client.stations) return; - if(!client.datastore.map) return; + if(!client.datastore?.map) return; let guilds = client.datastore.map.keys(); let stations = client.stations; diff --git a/src/client/classes/Streamer.ts b/src/client/classes/Streamer.ts index a5b2896..14c0da2 100644 --- a/src/client/classes/Streamer.ts +++ b/src/client/classes/Streamer.ts @@ -1,5 +1,6 @@ import logger from "../funcs/logger"; import { createAudioPlayer, createAudioResource, NoSubscriberBehavior } from "@discordjs/voice"; +import RadioClient from "../../Client"; export default class Streamer { map: any; @@ -12,7 +13,7 @@ export default class Streamer { this.logger = logger; } - init(client: any){ + init(client: RadioClient){ if(!client.config.streamerMode) return; switch(client.config.streamerMode){ @@ -35,12 +36,12 @@ export default class Streamer { } } - refresh(client: any){ + refresh(client: RadioClient){ this.init(client); let streamers = this.map.keys(); streamers.forEach((streamer: any) => { - if(client.stations.findIndex((station: { name: any; }) => station.name == streamer) == -1){ + if(client.stations?.findIndex((station: { name: any; }) => station.name == streamer) == -1){ this.stop(streamer); } }); @@ -111,7 +112,7 @@ export default class Streamer { return audioPlayer; } - leave(client: any) { + leave(client: RadioClient) { if(!client.stations) return; client.stations.forEach((station: any) => { this.stop(station); diff --git a/src/client/commands.ts b/src/client/commands.ts index f53ba00..997c7da 100644 --- a/src/client/commands.ts +++ b/src/client/commands.ts @@ -1,4 +1,5 @@ import { Snowflake } from "discord.js"; +import RadioClient from "../Client"; import bug from "./commands/bug"; import help from "./commands/help"; import invite from "./commands/invite"; @@ -12,20 +13,30 @@ import statistics from "./commands/statistics"; import status from "./commands/status"; import stop from "./commands/stop"; +export interface command { + name: string, + description: string, + category: string, + options?: [], + execute: any +} + export default { - async execute(client: any) { - const commands : any = [ bug, help, invite, list, maintenance, next, nowplaying, play, prev, statistics, status, stop ]; + async execute(client: RadioClient) { + const commands : command[] = [ bug, help, invite, list, maintenance, next, nowplaying, play, prev, statistics, status, stop ]; for(const command of commands){ client.commands.set(command.name, command); } + if(!client.application) return; client.funcs.logger('Application Commands', 'Started refreshing application (/) commands.'); if(client.config.devMode){ client.application.commands.set([]); for(const command of commands){ let guilds = await client.guilds.fetch(); guilds.forEach(async (guild: { id: Snowflake; name: string; }) => { + if(!client.application) return; client.application.commands.create({ name: command.name, description: command.description, @@ -47,6 +58,7 @@ export default { let guilds = await client.guilds.fetch(); guilds.forEach(async (guild: { id: Snowflake; }) => { + if(!client.application) return; client.application.commands.set([], guild.id); }); } diff --git a/src/client/commands/bug.ts b/src/client/commands/bug.ts index 598f94b..2819fc5 100644 --- a/src/client/commands/bug.ts +++ b/src/client/commands/bug.ts @@ -1,10 +1,11 @@ -import { EmbedBuilder } from "discord.js"; +import { ChatInputCommandInteraction, ColorResolvable, EmbedBuilder } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'bug', description: 'Report a bug', category: 'info', - async execute(interaction: any, client: any) { + async execute(interaction: ChatInputCommandInteraction, client: RadioClient) { let message : any = {}; message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username); @@ -13,7 +14,7 @@ export default { const embed = new EmbedBuilder() .setTitle(message.bugTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(message.bugDescription) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/help.ts b/src/client/commands/help.ts index d9af02b..8541041 100644 --- a/src/client/commands/help.ts +++ b/src/client/commands/help.ts @@ -1,10 +1,11 @@ -import { EmbedBuilder } from "discord.js"; +import { ChatInputCommandInteraction, ColorResolvable, EmbedBuilder } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'help', description: 'Get help using bot', category: 'info', - execute(interaction: any, client: any) { + execute(interaction: ChatInputCommandInteraction, client: RadioClient) { let message: any = {}; const categories : any= []; @@ -22,7 +23,7 @@ export default { const embed = new EmbedBuilder() .setTitle(message.helpTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(message.helpDescription) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/invite.ts b/src/client/commands/invite.ts index dc3b847..a879e8e 100644 --- a/src/client/commands/invite.ts +++ b/src/client/commands/invite.ts @@ -1,15 +1,16 @@ -import { EmbedBuilder } from "discord.js"; +import { ChatInputCommandInteraction, ColorResolvable, EmbedBuilder } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'invite', description: 'Invite Bot', category: 'info', - execute(interaction: any, client: any) { + execute(interaction: ChatInputCommandInteraction, client: RadioClient) { let message: any = {}; message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username); const embed = new EmbedBuilder() .setTitle(message.inviteTitle) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setURL("https://discord.com/api/oauth2/authorize?client_id=" + client.user.id + "&permissions=2184465408&scope=applications.commands%20bot") //View Channels, Send Messages, Embed Links, Use External Emojis, Use Slash Commands, Connect, Speak, Use Voice Activity .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/list.ts b/src/client/commands/list.ts index ea31a02..e90066b 100644 --- a/src/client/commands/list.ts +++ b/src/client/commands/list.ts @@ -1,10 +1,11 @@ -import { EmbedBuilder } from "discord.js"; +import { ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'list', description: 'List radio stations', category: 'radio', - execute(interaction: any, client: any) { + execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) { let message: any = {}; if(!client.stations) { @@ -15,7 +16,7 @@ export default { }); } - const radio = client.radio.get(interaction.guild.id); + const radio = client.radio?.get(interaction.guild.id); if(radio && !client.config.maintenanceMode){ client.funcs.listStations(client, interaction); @@ -29,7 +30,7 @@ export default { let embed = new EmbedBuilder() .setTitle(client.messages.listTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(stations) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/maintenance.ts b/src/client/commands/maintenance.ts index 7d325c5..da61e74 100644 --- a/src/client/commands/maintenance.ts +++ b/src/client/commands/maintenance.ts @@ -1,4 +1,5 @@ -import { ActionRowBuilder, EmbedBuilder, StringSelectMenuBuilder } from "discord.js"; +import { ActionRowBuilder, ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; import Streamer from "../classes/Streamer"; import commands from "../commands"; const _importDynamic = new Function('modulePath', 'return import(modulePath)'); @@ -9,7 +10,7 @@ export default { name: 'maintenance', description: 'Bot Maintenance', category: 'info', - async execute(interaction: any, client: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) { let message: any = {}; if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({ @@ -55,12 +56,12 @@ export default { }, { emoji: "💤", - label: "Streamer Mode – Manual", + label: "Streamer Mode - Manual", value: "10" }, { emoji: "📡", - label: "Streamer Mode – Auto", + label: "Streamer Mode - Auto", value: "11" } ); @@ -85,7 +86,7 @@ export default { const embed = new EmbedBuilder() .setTitle(client.messages.maintenanceTitle) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(options.find((option: { value: any; }) => option.value == action).label) .setFooter({ text: client.messages.footerText, diff --git a/src/client/commands/next.ts b/src/client/commands/next.ts index a4f8662..ec5d00f 100644 --- a/src/client/commands/next.ts +++ b/src/client/commands/next.ts @@ -1,8 +1,11 @@ +import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; + export default { name: 'next', description: 'Next Station', category: 'radio', - async execute(interaction: any, client: any, command: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/commands/nowplaying.ts b/src/client/commands/nowplaying.ts index 354ee03..c991951 100644 --- a/src/client/commands/nowplaying.ts +++ b/src/client/commands/nowplaying.ts @@ -1,13 +1,14 @@ -import { EmbedBuilder } from "discord.js"; +import { ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'nowplaying', description: 'Current Radio Station', category: 'radio', - async execute(interaction: any, client: any, command: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) { if (client.funcs.check(client, interaction, command)) { let message: any = {}; - const radio = client.radio.get(interaction.guild.id); + const radio = client.radio?.get(interaction.guild.id); let date = new Date(); radio.currentTime = date.getTime(); @@ -21,7 +22,7 @@ export default { const embed = new EmbedBuilder() .setTitle(client.messages.nowplayingTitle) .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(message.nowplayingDescription) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/play.ts b/src/client/commands/play.ts index c56e98b..9e6e1b0 100644 --- a/src/client/commands/play.ts +++ b/src/client/commands/play.ts @@ -1,5 +1,6 @@ -import { ApplicationCommandOptionType, PermissionFlagsBits } from "discord.js"; +import { ApplicationCommandOptionType, ButtonInteraction, ChatInputCommandInteraction, PermissionFlagsBits, StringSelectMenuInteraction } from "discord.js"; import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; +import RadioClient from "../../Client"; export default { name: "play", @@ -9,7 +10,7 @@ export default { { type: ApplicationCommandOptionType.String, name: "query", description: "Select station", required: false} ], category: "radio", - async execute(interaction: any, client: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) { let message: any = {}; if(client.config.maintenanceMode){ diff --git a/src/client/commands/prev.ts b/src/client/commands/prev.ts index 351854b..55e1030 100644 --- a/src/client/commands/prev.ts +++ b/src/client/commands/prev.ts @@ -1,8 +1,12 @@ +import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; +import { command } from "../commands"; + export default { name: 'prev', description: 'Previous Station', category: 'radio', - async execute(interaction: any, client: any, command: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/commands/statistics.ts b/src/client/commands/statistics.ts index 1fe9090..85eba3a 100644 --- a/src/client/commands/statistics.ts +++ b/src/client/commands/statistics.ts @@ -1,15 +1,16 @@ -import { EmbedBuilder } from "discord.js"; +import { ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'statistics', description: 'Show statistics', category: 'info', - execute(interaction: any, client: any) { + execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) { let message: any = {}; let stations = client.stations; - let currentGuild = client.datastore.getEntry(interaction.guild.id); - let global = client.datastore.getEntry("global"); + let currentGuild = client.datastore?.getEntry(interaction.guild.id); + let global = client.datastore?.getEntry("global"); let statistics = ""; if(!client.stations) { @@ -29,7 +30,7 @@ export default { const embed = new EmbedBuilder() .setTitle(client.messages.statisticsTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["statistics"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .setDescription(statistics) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ diff --git a/src/client/commands/status.ts b/src/client/commands/status.ts index 6bdf562..1516221 100644 --- a/src/client/commands/status.ts +++ b/src/client/commands/status.ts @@ -1,10 +1,11 @@ -import { EmbedBuilder } from "discord.js"; +import { ColorResolvable, EmbedBuilder } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'status', description: 'Bot Status', category: 'info', - async execute(interaction: any, client: any) { + async execute(interaction: any, client: RadioClient) { let message: any = {}; message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username); @@ -13,7 +14,7 @@ export default { const embed = new EmbedBuilder() .setTitle(message.statusTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .addFields( { name: client.messages.statusField1, value: uptime }, { name: client.messages.statusField2, value: client.config.version }, diff --git a/src/client/commands/stop.ts b/src/client/commands/stop.ts index a85e1d7..6e2a223 100644 --- a/src/client/commands/stop.ts +++ b/src/client/commands/stop.ts @@ -1,20 +1,21 @@ -import { EmbedBuilder } from "discord.js"; +import { ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuInteraction } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'stop', description: 'Stop radio', category: 'radio', - async execute(interaction: any, client: any, command: any) { + async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) { if (client.funcs.check(client, interaction, command)) { - const radio = client.radio.get(interaction.guild.id); - client.statistics.update(client, interaction.guild, radio); + const radio = client.radio?.get(interaction.guild.id); + client.statistics?.update(client, interaction.guild, radio); radio.connection?.destroy(); client.funcs.logger('Radio', interaction.guild.id + " / " + 'Stop'); const embed = new EmbedBuilder() .setTitle(client.user.username) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["stop"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .addFields({ name: client.messages.nowplayingTitle, value: "-" @@ -39,7 +40,7 @@ export default { await radio.message?.delete(); }, 5000); - client.radio.delete(interaction.guild.id); + client.radio?.delete(interaction.guild.id); interaction.reply({ content: client.messageEmojis["stop"] + client.messages.stop, diff --git a/src/client/emojis.ts b/src/client/emojis.ts index df5f0a0..119f2bb 100644 --- a/src/client/emojis.ts +++ b/src/client/emojis.ts @@ -1,6 +1,8 @@ +import RadioClient from "../Client"; + export default { name: 'emojis', - async execute(client: any): Promise { + async execute(client: RadioClient): Promise { let customEmojis: any = { logo: "<:RadioX:688765708808487072>", eximiabots: "<:EximiaBots:693277919929303132>", diff --git a/src/client/events/SIGINT.ts b/src/client/events/SIGINT.ts index 27ee4a3..97828cc 100644 --- a/src/client/events/SIGINT.ts +++ b/src/client/events/SIGINT.ts @@ -1,13 +1,15 @@ +import RadioClient from "../../Client"; + export default { name: 'SIGINT', - execute(client: any) { + execute(client: RadioClient) { client.user.setStatus('dnd'); - client.streamer.leave(client); - client.radio.save(client); + client.streamer?.leave(client); + client.radio?.save(client); setInterval(() => { - if(client.radio.size == 0){ + if(client.radio?.size == 0){ process.exit(); } }, 500); diff --git a/src/client/events/SIGTERM.ts b/src/client/events/SIGTERM.ts index 911daf8..7e03abb 100644 --- a/src/client/events/SIGTERM.ts +++ b/src/client/events/SIGTERM.ts @@ -1,6 +1,8 @@ +import RadioClient from "../../Client"; + export default { name: 'SIGTERM', - execute(client: any) { + execute(client: RadioClient) { process.emit('SIGINT'); } } diff --git a/src/client/events/interactionCreate.ts b/src/client/events/interactionCreate.ts index ae15bbc..b396b68 100644 --- a/src/client/events/interactionCreate.ts +++ b/src/client/events/interactionCreate.ts @@ -1,8 +1,9 @@ import { PermissionFlagsBits } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'interactionCreate', - async execute(client: any, interaction: any) { + async execute(client: RadioClient, interaction: any) { const permissions = interaction.channel.permissionsFor(interaction.client.user); if (!permissions.has(PermissionFlagsBits.ViewChannel)) return; diff --git a/src/client/events/messageDelete.ts b/src/client/events/messageDelete.ts index 2b1b5b1..99a2b73 100644 --- a/src/client/events/messageDelete.ts +++ b/src/client/events/messageDelete.ts @@ -1,10 +1,11 @@ import { Message } from "discord.js"; +import RadioClient from "../../Client"; export default { name: 'messageDelete', - async execute(client: any, msg: Message) { + async execute(client: RadioClient, msg: Message) { if(!msg.author.bot || !msg.guild) return; - const radio = client.radio.get(msg.guild.id); + const radio = client.radio?.get(msg.guild.id); if(!radio) return; if(!radio.message) return; if(msg.id != radio.message.id) return; diff --git a/src/client/events/ready.ts b/src/client/events/ready.ts index e42e21a..e080aa7 100644 --- a/src/client/events/ready.ts +++ b/src/client/events/ready.ts @@ -1,3 +1,4 @@ +import RadioClient from "../../Client"; import Datastore from "../classes/Datastore"; import Radio from "../classes/Radio"; import Stations from "../classes/Stations"; @@ -8,7 +9,7 @@ import commands from "../commands"; export default { name: 'ready', - async execute(client: any) { + async execute(client: RadioClient) { client.funcs.logger("Bot", "Ready"); diff --git a/src/client/events/uncaughtException.ts b/src/client/events/uncaughtException.ts index 2153077..3f22396 100644 --- a/src/client/events/uncaughtException.ts +++ b/src/client/events/uncaughtException.ts @@ -1,6 +1,8 @@ +import RadioClient from "../../Client"; + export default { name: 'uncaughtException', - execute(client: any, error: any) { + execute(client: RadioClient, error: any) { client.funcs.logger("Error"); console.log(error.stack); console.log(''); diff --git a/src/client/events/voiceStateUpdate.ts b/src/client/events/voiceStateUpdate.ts index 4c4729a..caee4ef 100644 --- a/src/client/events/voiceStateUpdate.ts +++ b/src/client/events/voiceStateUpdate.ts @@ -1,4 +1,5 @@ import { PermissionFlagsBits, VoiceState } from "discord.js"; +import RadioClient from "../../Client"; const { getVoiceConnection, joinVoiceChannel @@ -6,7 +7,7 @@ const { export default { name: "voiceStateUpdate", - async execute(client: any, oldState: VoiceState, newState: VoiceState) { + async execute(client: RadioClient, oldState: VoiceState, newState: VoiceState) { if (oldState.channel === null) return; let change = false; const radio = client.radio?.get(newState.guild.id); @@ -15,11 +16,11 @@ export default { if (newState.member?.id === client.user.id && oldState.member?.id === client.user.id) { if (newState.channel === null) { - client.statistics.update(client, newState.guild, radio); + client.statistics?.update(client, newState.guild, radio); radio.connection?.destroy(); radio.message?.delete(); client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop'); - return client.radio.delete(newState.guild.id); + return client.radio?.delete(newState.guild.id); } const newPermissions = newState.channel.permissionsFor(newState.client.user); @@ -37,11 +38,11 @@ export default { 1000 ); } catch (error) { - client.statistics.update(client, newState.guild, radio); + client.statistics?.update(client, newState.guild, radio); radio.connection?.destroy(); radio.message?.delete(); client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop'); - client.radio.delete(oldState.guild.id); + client.radio?.delete(oldState.guild.id); } return; } @@ -56,11 +57,11 @@ export default { setTimeout(() => { if (!radio || !radio.connection || !radio.connection === null) return; if (radio.voiceChannel.members.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) { - client.statistics.update(client, newState.guild, radio); + client.statistics?.update(client, newState.guild, radio); radio.connection?.destroy(); radio.message?.delete(); client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop'); - client.radio.delete(newState.guild.id); + client.radio?.delete(newState.guild.id); } }, 5000); } diff --git a/src/client/events/warning.ts b/src/client/events/warning.ts index a831895..4b8dd8e 100644 --- a/src/client/events/warning.ts +++ b/src/client/events/warning.ts @@ -1,6 +1,8 @@ +import RadioClient from "../../Client"; + export default { name: 'warning', - execute(client: any, warning: any) { + execute(client: RadioClient, warning: Error) { if(warning.name == "ExperimentalWarning" && warning.message.startsWith("stream/web")) return; client.funcs.logger("Warning"); diff --git a/src/client/funcs/check.ts b/src/client/funcs/check.ts index c832d7f..434848e 100644 --- a/src/client/funcs/check.ts +++ b/src/client/funcs/check.ts @@ -1,6 +1,8 @@ -export default function check(client: any, interaction: any, command: any) { +import RadioClient from "../../Client"; + +export default function check(client: RadioClient, interaction: any, command: any) { let message: any = {}; - const radio = client.radio.get(interaction.guild.id); + const radio = client.radio?.get(interaction.guild.id); if(client.config.maintenanceMode){ interaction.reply({ content: client.messageEmojis["error"] + client.messages.maintenance, diff --git a/src/client/funcs/listStations.ts b/src/client/funcs/listStations.ts index e873b19..35bffc4 100644 --- a/src/client/funcs/listStations.ts +++ b/src/client/funcs/listStations.ts @@ -1,9 +1,12 @@ import { ActionRowBuilder, StringSelectMenuBuilder } from "discord.js"; +import RadioClient from "../../Client"; -export default function listStations(client: any, interaction: any){ - let stations: any = new Array(); +export default function listStations(client: RadioClient, interaction: any){ + let stations: any = new Array(); let options: any = new Array(); + if(!client.stations) return; + stations = client.stations.forEach((station: { name?: any; owner?: any; label?: any; description?: any; value?: any; }) => { if(station.name == "GrooveFM") return; station = { diff --git a/src/client/funcs/loadState.ts b/src/client/funcs/loadState.ts index 9428bb8..cc69fd6 100644 --- a/src/client/funcs/loadState.ts +++ b/src/client/funcs/loadState.ts @@ -1,6 +1,8 @@ import { Guild } from "discord.js"; +import RadioClient from "../../Client"; -export default function loadState(client: any, guild: Guild){ +export default function loadState(client: RadioClient, guild: Guild){ + if(!client.datastore) return; let data = client.datastore.getEntry(guild.id); if(!data) return; let state; diff --git a/src/client/funcs/logger.ts b/src/client/funcs/logger.ts index 17d8680..830999d 100644 --- a/src/client/funcs/logger.ts +++ b/src/client/funcs/logger.ts @@ -1,5 +1,5 @@ export default function logger(area : string, text: string){ let date = new Date(); - console.log('[' + area + '] – ' + date.toISOString()); + console.log('[' + area + '] - ' + date.toISOString()); if(text) console.log(text + '\n'); } diff --git a/src/client/funcs/play.ts b/src/client/funcs/play.ts index 899075e..e717934 100644 --- a/src/client/funcs/play.ts +++ b/src/client/funcs/play.ts @@ -1,9 +1,10 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js"; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ColorResolvable, EmbedBuilder } from "discord.js"; +import RadioClient from "../../Client"; -export default async function play(client: any, interaction: any, guild: any, station: any) { +export default async function play(client: RadioClient, interaction: any, guild: any, station: any) { let message: any = {}; - const radio = client.radio.get(guild.id); - const audioPlayer = client.streamer.listen(station); + const radio = client.radio?.get(guild.id); + const audioPlayer = client.streamer?.listen(station); radio.connection.subscribe(audioPlayer); client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name); @@ -16,7 +17,7 @@ export default async function play(client: any, interaction: any, guild: any, st const embed = new EmbedBuilder() .setTitle(client.user.username) .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) - .setColor(client.config.embedColor) + .setColor(client.config.embedColor as ColorResolvable) .addFields({ name: client.messages.nowplayingTitle, value: message.nowplayingDescription diff --git a/src/client/funcs/saveState.ts b/src/client/funcs/saveState.ts index 4940866..0bba27a 100644 --- a/src/client/funcs/saveState.ts +++ b/src/client/funcs/saveState.ts @@ -1,4 +1,7 @@ -export default function saveState(client: any, guild: any, radio: any){ +import RadioClient from "../../Client"; + +export default function saveState(client: RadioClient, guild: any, radio: any){ + if(!client.datastore) return; client.datastore.checkEntry(guild.id); let date = new Date(); diff --git a/src/client/utils/typings.ts b/src/client/utils/typings.ts index 1e5d860..e69de29 100644 --- a/src/client/utils/typings.ts +++ b/src/client/utils/typings.ts @@ -1,3 +0,0 @@ -export interface command { } - -export interface radio {}