fix: Extract logic for getting author value for embeds

This commit is contained in:
Marius Begby committed 2023-09-05 21:52:03 +02:00
1 parent 8c05499f08
commit 83e23d87b4
60 files changed
+126 -317

No files matched your search

@@ -1,9 +1,9 @@
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember } from 'discord.js';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { EmbedBuilder } from 'discord.js';
import { BaseComponentInteraction } from '../../classes/interactions';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
class FiltersDisableButtonComponent extends BaseComponentInteraction {
constructor() {
@@ -30,22 +30,11 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction {
logger.debug('Reset queue filters.');
}
let authorName: string;
if (interaction.member instanceof GuildMember) {
authorName = interaction.member.nickname || interaction.user.username;
} else {
authorName = interaction.user.username;
}
logger.debug('Responding with success embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setAuthor(await this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Disabled filters**\nAll audio filters have been disabled.`
)
@@ -1,11 +1,12 @@
import config from 'config';
import { GuildQueue, QueueFilters, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.js';
import { EmbedBuilder, StringSelectMenuInteraction } from 'discord.js';
import { BaseComponentInteraction } from '../../classes/interactions';
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { BaseComponentInteraction } from '../../classes/interactions';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
class FiltersSelectMenuComponent extends BaseComponentInteraction {
@@ -61,22 +62,11 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
let authorName: string;
if (selectMenuInteraction.member instanceof GuildMember) {
authorName = selectMenuInteraction.member.nickname || selectMenuInteraction.user.username;
} else {
authorName = selectMenuInteraction.user.username;
}
logger.debug('Responding with success embed.');
return await selectMenuInteraction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: selectMenuInteraction.user.avatarURL() || ''
})
.setAuthor(await this.getEmbedUserAuthor(interaction))
.setDescription(
`**${
this.embedOptions.icons.success
@@ -1,9 +1,9 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember } from 'discord.js';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { EmbedBuilder } from 'discord.js';
import { BaseComponentInteraction } from '../../classes/interactions';
import { checkQueueExists, checkQueueCurrentTrack } from '../../utils/validation/queueValidator';
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
class NowplayingSkipButton extends BaseComponentInteraction {
constructor() {
@@ -85,22 +85,11 @@ class NowplayingSkipButton extends BaseComponentInteraction {
const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode);
let authorName: string;
if (interaction.member instanceof GuildMember) {
authorName = interaction.member.nickname || interaction.user.username;
} else {
authorName = interaction.user.username;
}
logger.debug('Responding with success embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setAuthor(await this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${
skippedTrack.title