This commit is contained in:
Christer Warén 2023-11-28 22:55:11 +02:00
parent 2a7dca38f2
commit 32fabe63ff
6 changed files with 19 additions and 11 deletions

View File

@ -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 { 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: Channel | TextBasedChannel | undefined | null, textChannel: TextBasedChannel | undefined | null,
voiceChannel: Channel | VoiceBasedChannel | undefined, voiceChannel: VoiceBasedChannel | undefined,
connection: VoiceConnection | null, connection: VoiceConnection | null,
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
} }
export interface state { export interface state {
@ -28,7 +29,7 @@ export interface state {
} }
} }
export default class Radio extends Map { export default class Radio extends Map<string, radio> {
constructor() { constructor() {
super(); super();
@ -75,8 +76,8 @@ export default class Radio extends Map {
let date = new Date(); let date = new Date();
const construct: radio = { const construct: radio = {
textChannel: client.channels.cache.get(state.channels.text), textChannel: client.channels.cache.get(state.channels.text) as TextBasedChannel,
voiceChannel: client.channels.cache.get(state.channels.voice), voiceChannel: client.channels.cache.get(state.channels.voice) as VoiceBasedChannel,
connection: null, connection: null,
message: null, message: null,
station: station, station: station,

View File

@ -9,7 +9,9 @@ export default {
category: 'radio', category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
if(!interaction.guild) return;
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!radio) return;
if(client.config.maintenanceMode){ if(client.config.maintenanceMode){
return interaction.reply({ return interaction.reply({

View File

@ -9,7 +9,9 @@ export default {
category: 'radio', category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
if(!interaction.guild) return;
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!radio) return;
if(client.config.maintenanceMode){ if(client.config.maintenanceMode){
return interaction.reply({ return interaction.reply({

View File

@ -8,7 +8,9 @@ export default {
category: 'radio', category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) { async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
if(!interaction.guild) return;
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!radio) 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');
@ -28,9 +30,9 @@ export default {
}); });
if(!radio.message){ if(!radio.message){
radio.message = radio.textChannel.send({ embeds: [embed], components: [] }); radio.message = await radio.textChannel?.send({ embeds: [embed], components: [] }) ?? null;
} else { } else {
if(radio.textChannel.id == radio.message.channel.id){ if(radio.textChannel?.id == radio.message.channel.id){
radio.message.edit({ embeds: [embed], components: [] }); radio.message.edit({ embeds: [embed], components: [] });
} else { } else {
radio.message?.delete(); radio.message?.delete();
@ -41,7 +43,7 @@ export default {
await radio.message?.delete(); await radio.message?.delete();
}, 5000); }, 5000);
client.radio?.delete(interaction.guild?.id); client.radio?.delete(interaction.guild.id);
interaction.reply({ interaction.reply({
content: client.messages.emojis["stop"] + client.messages.stop, content: client.messages.emojis["stop"] + client.messages.stop,

View File

@ -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) { if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && oldState.channel === radio.voiceChannel) || change) {
setTimeout(() => { setTimeout(() => {
if (!radio || !radio.connection || !radio.connection === null) return; 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); client.statistics?.update(client, newState.guild, radio);
radio.connection?.destroy(); radio.connection?.destroy();
radio.message?.delete(); radio.message?.delete();

View File

@ -4,6 +4,7 @@ import { command } from "../commands";
export default function check(client: RadioClient, interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, command: command) { export default function check(client: RadioClient, interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, command: command) {
if(!interaction.guild) return;
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!client.stations) { if(!client.stations) {
interaction.reply({ interaction.reply({