Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: remove Promise.resolve() return and fix queue type
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Aug 29, 2023
1 parent d5cc5b8 commit 67e4572
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/handlers/interactionCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const handleCommand = async (
}

if (await cannotSendMessageInChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

logger.debug('Executing command interaction.');
Expand Down
27 changes: 9 additions & 18 deletions src/interactions/commands/info/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,28 @@ const command: CustomSlashCommandInteraction = {
let totalTracks: number = 0;
let totalListeners: number = 0;

await client!.shard!
.broadcastEval(() => {
await client!
.shard!.broadcastEval(() => {
/* eslint-disable no-undef */
return player.generateStatistics();
})
.then((results) => {
const queueCountList: number[] = [];
const trackCountList: number[] = [];
const listenerCountList: number[] = [];
results.map((result) => {
queueCountList.push(result.queues.length);
if (result.queues.length > 0) {
result.queues.map((queue) => {
trackCountList.push(queue.status.playing ? queue.tracksCount + 1 : queue.tracksCount);
listenerCountList.push(queue.listeners);
});
}
activeVoiceConnections += result.queues.length;
result.queues.map((queue) => {
totalTracks += queue.status.playing ? queue.tracksCount + 1 : queue.tracksCount;
totalListeners += queue.listeners;
});
});

activeVoiceConnections = queueCountList.reduce((acc, queueAmount) => acc + queueAmount, 0);
totalTracks = trackCountList.reduce((acc, trackAmount) => acc + trackAmount, 0);
totalListeners = listenerCountList.reduce((acc, listenerAmount) => acc + listenerAmount, 0);

logger.debug('Successfully fetched player statistics from shards.');
})
.catch((error) => {
logger.error(error, 'Failed to fetch player statistics from shards.');
});

await client!.shard!
.fetchClientValues('guilds.cache')
await client!
.shard!.fetchClientValues('guilds.cache')
.then((results) => {
const guildCaches = results as Guild[][];
guildCaches.map((guildCache: Guild[]) => {
Expand Down
12 changes: 6 additions & 6 deletions src/interactions/commands/player/filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, QueueFilters, useQueue } from 'discord-player';
import { GuildQueue, QueueFilters, useQueue } from 'discord-player';
import {
APIActionRowComponent,
APIMessageActionRowComponent,
Expand Down Expand Up @@ -40,21 +40,21 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const filterOptions: StringSelectMenuOptionBuilder[] = [];
Expand Down
8 changes: 4 additions & 4 deletions src/interactions/commands/player/leave.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, useQueue } from 'discord-player';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -28,10 +28,10 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (!queue) {
logger.debug('There is already no queue.');
Expand All @@ -49,7 +49,7 @@ const command: CustomSlashCommandInteraction = {
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (!queue.deleted) {
Expand Down
11 changes: 6 additions & 5 deletions src/interactions/commands/player/loop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, useQueue } from 'discord-player';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -42,17 +42,17 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const loopModesFormatted = new Map([
Expand Down Expand Up @@ -132,6 +132,7 @@ const command: CustomSlashCommandInteraction = {
if (queue.repeatMode === 0) {
logger.debug('Disabled loop mode.');

// TODO: Different text when disabling autoplay.
logger.debug('Responding with success embed.');
return await interaction.editReply({
embeds: [
Expand Down
14 changes: 7 additions & 7 deletions src/interactions/commands/player/lyrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, QueryType, useMainPlayer, useQueue } from 'discord-player';
import { GuildQueue, QueryType, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';

import { lyricsExtractor } from '@discord-player/extractor';
Expand Down Expand Up @@ -43,24 +43,24 @@ const command: CustomSlashCommandInteraction = {
});

const query = interaction.options.getString('query');
const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
let geniusSearchQuery = '';

if (!query) {
if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}
geniusSearchQuery = queue.currentTrack!.title.slice(0, 50);

Expand Down Expand Up @@ -188,7 +188,7 @@ const command: CustomSlashCommandInteraction = {
}
}

return Promise.resolve();
return;
}

logger.debug('Responding with info embed.');
Expand Down
12 changes: 6 additions & 6 deletions src/interactions/commands/player/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, Track, useQueue } from 'discord-player';
import { GuildQueue, Track, useQueue } from 'discord-player';
import {
APIActionRowComponent,
APIMessageActionRowComponent,
Expand Down Expand Up @@ -38,21 +38,21 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const sourceStringsFormatted = new Map([
Expand Down
12 changes: 6 additions & 6 deletions src/interactions/commands/player/pause.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, useQueue } from 'discord-player';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -29,21 +29,21 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const currentTrack = queue.currentTrack!;
Expand Down
15 changes: 8 additions & 7 deletions src/interactions/commands/player/play.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { useMainPlayer, useQueue } from 'discord-player';
import { GuildQueue, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -43,17 +43,18 @@ const command: CustomSlashCommandInteraction = {
guildId: interaction.guild?.id
});


if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

if (await cannotJoinVoiceOrTalk({ interaction, executionId })) {
return Promise.resolve();
return;
}

let queue = useQueue(interaction.guild!.id);
let queue: GuildQueue = useQueue(interaction.guild!.id)!;
if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) {
return Promise.resolve();
return;
}

const player = useMainPlayer()!;
Expand Down Expand Up @@ -86,7 +87,7 @@ const command: CustomSlashCommandInteraction = {
});
}

queue = useQueue(interaction.guild!.id);
queue = useQueue(interaction.guild!.id)!;
const queueSize = queue?.size ?? 0;

if ((searchResult.playlist! && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
Expand Down Expand Up @@ -211,7 +212,7 @@ const command: CustomSlashCommandInteraction = {

logger.debug(`Successfully added track with player.play(). Query: '${query}'.`);

queue = useQueue(interaction.guild!.id);
queue = useQueue(interaction.guild!.id)!;

if (!queue || !track) {
logger.warn(`After player.play(), queue is undefined. Query: '${query}'.`);
Expand Down
8 changes: 4 additions & 4 deletions src/interactions/commands/player/queue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, useQueue } from 'discord-player';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -30,13 +30,13 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
Expand Down
12 changes: 6 additions & 6 deletions src/interactions/commands/player/seek.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import { NodeResolvable, useQueue } from 'discord-player';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';

import loggerModule from '../../../services/logger';
Expand Down Expand Up @@ -35,21 +35,21 @@ const command: CustomSlashCommandInteraction = {
});

if (await notInVoiceChannel({ interaction, executionId })) {
return Promise.resolve();
return;
}

const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;

if (await queueDoesNotExist({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
return Promise.resolve();
return;
}

const durationInput = interaction.options.getString('duration');
Expand Down
Loading

0 comments on commit 67e4572

Please sign in to comment.