-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added slash commands autocomplete for playlist names. Added /pl-delete command.
- Loading branch information
1 parent
eab8632
commit d1ba342
Showing
11 changed files
with
131 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,76 @@ | ||
import { CommandArgument, ICommand } from '../../CommandTypes.js'; | ||
import { GroupAudio } from './AudioTypes.js'; | ||
import { Message, PermissionsBitField, SlashCommandBuilder } from 'discord.js'; | ||
import { ChatInputCommandInteraction, Message, PermissionsBitField, SlashCommandBuilder } from 'discord.js'; | ||
import i18next from 'i18next'; | ||
import { | ||
PlaylistIsNotExists, | ||
UserPlaylistDelete, | ||
UserPlaylistNamesAutocomplete | ||
} from '../../schemas/SchemaPlaylist.js'; | ||
import { generateSimpleEmbed } from '../../utilities/generateSimpleEmbed.js'; | ||
import { generateErrorEmbed } from '../../utilities/generateErrorEmbed.js'; | ||
import { ENV } from '../../EnvironmentVariables.js'; | ||
import { loggerError } from '../../utilities/logger.js'; | ||
|
||
export default function (): ICommand { | ||
return { | ||
text_data: { | ||
name: 'pl-delete', | ||
description: i18next.t('commands:pl-delete_desc'), | ||
arguments: [new CommandArgument(i18next.t('commands:pl-delete_link'), true)], | ||
execute: async (message: Message) => {} | ||
arguments: [new CommandArgument(i18next.t('commands:pl_arg_name'), true)], | ||
execute: async (message: Message, args: Array<string>) => { | ||
const playlistsName = args[0]; | ||
|
||
await plDeleteAndReply(message, message.author.id, playlistsName); | ||
} | ||
}, | ||
slash_data: { | ||
slash_builder: new SlashCommandBuilder() | ||
.setName('pl-delete') | ||
.setDescription(i18next.t('commands:pl-delete_desc')) | ||
.addStringOption((option) => | ||
option | ||
.setName('request') | ||
.setDescription(i18next.t('commands:pl-delete_link')) | ||
.setName('playlist_name') | ||
.setDescription(i18next.t('commands:pl_arg_name')) | ||
.setAutocomplete(true) | ||
.setRequired(true) | ||
), | ||
execute: async (interaction) => {} | ||
execute: async (interaction) => { | ||
const playlistsName = interaction.options.getString('playlist_name')!; | ||
|
||
await plDeleteAndReply(interaction, interaction.user.id, playlistsName); | ||
}, | ||
autocomplete: UserPlaylistNamesAutocomplete | ||
}, | ||
group: GroupAudio, | ||
guild_data: { | ||
guild_only: true, | ||
voice_required: true | ||
}, | ||
bot_permissions: [PermissionsBitField.Flags.SendMessages] | ||
}; | ||
} | ||
|
||
async function plDeleteAndReply(ctx: Message | ChatInputCommandInteraction, userID: string, playlistName: string) { | ||
try { | ||
await UserPlaylistDelete(userID, playlistName); | ||
|
||
await ctx.reply({ | ||
embeds: [generateSimpleEmbed(i18next.t('commands:pl-delete_embed_deleted', { name: playlistName }))], | ||
ephemeral: true | ||
}); | ||
} catch (e) { | ||
if (e instanceof PlaylistIsNotExists) { | ||
await ctx.reply({ | ||
embeds: [ | ||
generateErrorEmbed( | ||
i18next.t('commands:pl_error_playlist_not_exists', { | ||
name: playlistName, | ||
interpolation: { escapeValue: false } | ||
}) | ||
) | ||
], | ||
ephemeral: true | ||
}); | ||
} | ||
|
||
await ctx.reply({ embeds: [generateErrorEmbed(i18next.t('commands:pl-delete_error'))], ephemeral: true }); | ||
if (ENV.BOT_VERBOSE_LOGGING) loggerError(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters