feat: add tts commands
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
AutocompleteInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
MessageFlags,
|
||||
SlashCommandBuilder
|
||||
} from 'discord.js';
|
||||
import { Command } from '../../commands';
|
||||
import { DatabaseManager } from '../../modules/db';
|
||||
import { TTSManager } from '../../modules/tts';
|
||||
|
||||
const builder = new SlashCommandBuilder()
|
||||
.setName('tts-mode')
|
||||
.setDescription('Selects a mode to use for TTS')
|
||||
.addStringOption((opt) =>
|
||||
opt
|
||||
.setName('mode')
|
||||
.setDescription('Which TTS provider to use')
|
||||
.setAutocomplete(true)
|
||||
.setRequired(true)
|
||||
);
|
||||
|
||||
const cmd: Command = {
|
||||
name: builder.name,
|
||||
builder: builder,
|
||||
|
||||
execute: async (interaction: ChatInputCommandInteraction): Promise<void> => {
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
const userData = await DatabaseManager.get.getUser(interaction.user.id);
|
||||
const modeName = interaction.options.getString('mode', true);
|
||||
const selectedMode = TTSManager.get
|
||||
.getModules()
|
||||
.find((mode) => mode.name === modeName);
|
||||
|
||||
if (!selectedMode) {
|
||||
await interaction.editReply(`Unknown mode (${modeName})`);
|
||||
return;
|
||||
}
|
||||
|
||||
await userData.set('tts_mode', modeName);
|
||||
await userData.save();
|
||||
|
||||
interaction.editReply(`TTS mode has been set to: ${modeName}.`);
|
||||
},
|
||||
|
||||
autocomplete: async (interaction: AutocompleteInteraction): Promise<void> => {
|
||||
const focused = interaction.options.getFocused(true);
|
||||
if (focused.name != 'mode') return;
|
||||
|
||||
const modes = TTSManager.get.getModules();
|
||||
|
||||
const filtered: string[] = modes
|
||||
.filter((mode) =>
|
||||
mode.name.toLowerCase().startsWith(focused.value.toLowerCase())
|
||||
)
|
||||
.map((mode) => mode.name)
|
||||
.slice(0, 25);
|
||||
|
||||
await interaction.respond(
|
||||
filtered.map((choice) => ({ name: choice, value: choice }))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default cmd;
|
||||
Reference in New Issue
Block a user