mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: remove unnecessary async/await
This commit is contained in:
1 parent
dd0804770c
commit
7dc7b4ff7e
5 files changed
+15
-18
No files matched your search
@@ -26,7 +26,7 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
logger.debug('Deleting queue.');
|
logger.debug('Deleting queue.');
|
||||||
await this.deleteQueue(queue);
|
this.deleteQueue(queue);
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -43,7 +43,7 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deleteQueue(queue: GuildQueue): Promise<void> {
|
private deleteQueue(queue: GuildQueue): void {
|
||||||
if (!queue.deleted) {
|
if (!queue.deleted) {
|
||||||
queue.delete();
|
queue.delete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class PlayCommand extends BaseSlashCommandInteraction {
|
|||||||
|
|
||||||
const player = useMainPlayer()!;
|
const player = useMainPlayer()!;
|
||||||
const searchQuery = interaction.options.getString('query')!;
|
const searchQuery = interaction.options.getString('query')!;
|
||||||
const transformedQuery = await transformQuery({ query: searchQuery, executionId });
|
const transformedQuery = transformQuery({ query: searchQuery, executionId });
|
||||||
|
|
||||||
const searchResult = await this.searchTrack(player, transformedQuery, interaction, logger);
|
const searchResult = await this.searchTrack(player, transformedQuery, interaction, logger);
|
||||||
if (!searchResult || searchResult.tracks.length === 0) {
|
if (!searchResult || searchResult.tracks.length === 0) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { GuildQueue, useQueue } from 'discord-player';
|
import { GuildQueue, useQueue } from 'discord-player';
|
||||||
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { ChatInputCommandInteraction, EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
|
||||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||||
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||||
@@ -57,11 +57,11 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
formattedDurationString: string
|
formattedDurationString: string
|
||||||
) {
|
): Promise<Message> {
|
||||||
logger.debug('Invalid duration format input.');
|
logger.debug('Invalid duration format input.');
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
logger.debug('Responding with warning embed.');
|
||||||
await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
@@ -76,7 +76,6 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async seekToDurationInCurrentTrack(
|
private async seekToDurationInCurrentTrack(
|
||||||
@@ -85,12 +84,12 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
queue: GuildQueue,
|
queue: GuildQueue,
|
||||||
durationInMilliseconds: number,
|
durationInMilliseconds: number,
|
||||||
formattedDurationString: string
|
formattedDurationString: string
|
||||||
) {
|
): Promise<Message> {
|
||||||
queue.node.seek(durationInMilliseconds);
|
queue.node.seek(durationInMilliseconds);
|
||||||
logger.debug(`Seeked to '${formattedDurationString}' in current track.`);
|
logger.debug(`Seeked to '${formattedDurationString}' in current track.`);
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setAuthor(await this.getEmbedUserAuthor(interaction))
|
.setAuthor(await this.getEmbedUserAuthor(interaction))
|
||||||
@@ -102,7 +101,6 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
.setColor(this.embedOptions.colors.success)
|
.setColor(this.embedOptions.colors.success)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleDurationLongerThanTrack(
|
private async handleDurationLongerThanTrack(
|
||||||
@@ -110,11 +108,11 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
formattedDurationString: string,
|
formattedDurationString: string,
|
||||||
queue: GuildQueue
|
queue: GuildQueue
|
||||||
) {
|
): Promise<Message> {
|
||||||
logger.debug('Duration specified is longer than the track duration.');
|
logger.debug('Duration specified is longer than the track duration.');
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
logger.debug('Responding with warning embed.');
|
||||||
await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
@@ -127,7 +125,6 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
|||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseDurationArray(durationInputSplit: string[]): string {
|
private parseDurationArray(durationInputSplit: string[]): string {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ describe('searchQueryValidator', () => {
|
|||||||
async (countryCode) => {
|
async (countryCode) => {
|
||||||
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
const query: string = `https://open.spotify.com/${countryCode}/track/${trackId}`;
|
const query: string = `https://open.spotify.com/${countryCode}/track/${trackId}`;
|
||||||
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
const transformedQuery: string = transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
expect(transformedQuery).toBe(`https://open.spotify.com/track/${trackId}`);
|
expect(transformedQuery).toBe(`https://open.spotify.com/track/${trackId}`);
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ describe('searchQueryValidator', () => {
|
|||||||
async (path) => {
|
async (path) => {
|
||||||
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
||||||
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
const transformedQuery: string = transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ describe('searchQueryValidator', () => {
|
|||||||
async (path) => {
|
async (path) => {
|
||||||
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
||||||
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
const transformedQuery: string = transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ describe('searchQueryValidator', () => {
|
|||||||
]
|
]
|
||||||
])('should return the same url if it is not a valid Spotify url', async (inputUrl, expectedUrl) => {
|
])('should return the same url if it is not a valid Spotify url', async (inputUrl, expectedUrl) => {
|
||||||
const executionId: string = 'test';
|
const executionId: string = 'test';
|
||||||
const transformedQuery: string = await transformQuery({ query: inputUrl, executionId });
|
const transformedQuery: string = transformQuery({ query: inputUrl, executionId });
|
||||||
|
|
||||||
expect(transformedQuery).toBe(expectedUrl);
|
expect(transformedQuery).toBe(expectedUrl);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Logger } from 'pino';
|
|||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { TransformQueryParams } from '../../types/utilTypes';
|
import { TransformQueryParams } from '../../types/utilTypes';
|
||||||
|
|
||||||
export const transformQuery = async ({ query, executionId }: TransformQueryParams) => {
|
export const transformQuery = ({ query, executionId }: TransformQueryParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'transformQuery',
|
name: 'transformQuery',
|
||||||
|
|||||||
Reference in new issue
Block a user