Skip to content

Commit

Permalink
Created MicrosoftSetChannelSettingsCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
moonstar-x committed Mar 25, 2022
1 parent 816a36f commit be529f6
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
const { SlashCommand } = require('@greencoast/discord.js-extended');
const { SlashCommandBuilder } = require('@discordjs/builders');
const logger = require('@greencoast/logger');
const MicrosoftProvider = require('../../../../classes/tts/providers/MicrosoftProvider');
const languageData = require('../../../../../provider-data/ttstool_microsoft_languages.json');

class MicrosoftSetChannelSettingsCommand extends SlashCommand {
constructor(client) {
super(client, {
name: 'ms_set_channel',
description: 'Sets the settings to be used with message-only based TTS from Microsoft.',
emoji: ':pencil2:',
group: 'ms-tts',
guildOnly: true,
userPermissions: ['MANAGE_CHANNELS'],
dataBuilder: new SlashCommandBuilder()
.addSubcommand((input) => {
return input
.setName('language')
.setDescription('Sets the language to be used by the message-only based TTS.')
.addStringOption((input) => {
return input
.setName('value')
.setDescription('The language to use from now. Use /ms_langs to see a list of supported languages.')
.setRequired(true);
});
})
.addSubcommand((input) => {
return input
.setName('voice')
.setDescription('Sets the voice to be used by the message-only based TTS.')
.addStringOption((input) => {
return input
.setName('value')
.setDescription('The voice to be used from now. Use /ms_voices to see a list of supported voices.')
.setRequired(true);
});
})
.addSubcommand((input) => {
return input
.setName('volume')
.setDescription('Sets the volume to be used used by the message-only based TTS.')
.addStringOption((input) => {
return input
.setName('value')
.setDescription('The volume to be used from now.')
.setRequired(true)
.setChoices(MicrosoftProvider.getSupportedVolumeChoices());
});
})
.addSubcommand((input) => {
return input
.setName('rate')
.setDescription('Sets the rate to be used by the message-only based TTS.')
.addStringOption((input) => {
return input
.setName('value')
.setDescription('The rate to be used from now.')
.setRequired(true)
.setChoices(MicrosoftProvider.getSupportedRateChoices());
});
})
.addSubcommand((input) => {
return input
.setName('pitch')
.setDescription('Sets the pitch to be used by the message-only based TTS.')
.addStringOption((input) => {
return input
.setName('value')
.setDescription('The pitch to be used from now.')
.setRequired(true)
.setChoices(MicrosoftProvider.getSupportedPitchChoices());
});
})
});
}

async handleLanguage(interaction, localizer) {
const language = interaction.options.getString('value');
const languageInfo = languageData[language];

if (!languageInfo) {
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.language.unsupported', { language }) });
}

const [defaultVoice] = languageInfo.voices;

await this.client.ttsSettings.set(interaction.channel, {
[MicrosoftProvider.NAME]: {
language,
voice: defaultVoice.id
}
});

logger.info(`${interaction.guild.name} has changed the microsoft language for the channel ${interaction.channel.name} to ${language} with voice ${defaultVoice.name}.`);
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.language.success', { language, voice: defaultVoice.name }) });
}

async handleVoice(interaction, localizer) {
const voice = interaction.options.getString('value').toLowerCase();

const settings = await this.client.ttsSettings.getCurrentForChannel(interaction.channel);
const { language } = settings[MicrosoftProvider.NAME];
const languageInfo = languageData[language];

const voiceInfo = languageInfo.voices.find((v) => v.name.toLowerCase() === voice);

if (!voiceInfo) {
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.voice.unsupported', { voice }) });
}

await this.client.ttsSettings.set(interaction.channel, {
[MicrosoftProvider.NAME]: {
language,
voice: voiceInfo.id
}
});

logger.info(`${interaction.channel.name} has changed the microsoft voice for the channel ${interaction.channel.name} to ${voiceInfo.name}.`);
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.voice.success', { voice: voiceInfo.name }) });
}

async handleVolume(interaction, localizer) {
const volume = interaction.options.getString('value');

await this.client.ttsSettings.set(interaction.channel, { [MicrosoftProvider.NAME]: { volume } });

logger.info(`${interaction.guild.name} has changed the microsoft volume for the channel ${interaction.channel.name} to ${volume}.`);
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.volume.success', { volume }) });
}

async handleRate(interaction, localizer) {
const rate = interaction.options.getString('value');

await this.client.ttsSettings.set(interaction.channel, { [MicrosoftProvider.NAME]: { rate } });

logger.info(`${interaction.guild.name} has changed the microsoft rate for the channel ${interaction.channel.name} to ${rate}.`);
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.rate.success', { rate }) });
}

async handlePitch(interaction, localizer) {
const pitch = interaction.options.getString('value');

await this.client.ttsSettings.set(interaction.channel, { [MicrosoftProvider.NAME]: { pitch } });

logger.info(`${interaction.guild.name} has changed the microsoft pitch for the channel ${interaction.channel.name} to ${pitch}.`);
return interaction.reply({ content: localizer.t('channel_commands.microsoft.settings.pitch.success', { pitch }) });
}

async run(interaction) {
const localizer = this.client.localizer.getLocalizer(interaction.guild);
const subCommand = interaction.options.getSubcommand();

switch (subCommand) {
case 'language':
return this.handleLanguage(interaction, localizer);
case 'voice':
return this.handleVoice(interaction, localizer);
case 'volume':
return this.handleVolume(interaction, localizer);
case 'rate':
return this.handleRate(interaction, localizer);
case 'pitch':
return this.handlePitch(interaction, localizer);
default:
throw new Error(`Invalid subcommand ${subCommand} supplied to MicrosoftSetChannelSettingsCommand.`);
}
}
}

module.exports = MicrosoftSetChannelSettingsCommand;
12 changes: 11 additions & 1 deletion src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ const CHANNEL_COMMANDS = {

'channel_commands.google.settings.language.invalid': "That's not a valid language. Type **/google_langs** for a list of available languages.",
'channel_commands.google.settings.language.success': 'You have successfully changed the language for this channel to **{language}**.',
'channel_commands.google.settings.speed.success': 'You have successfully changed the speed for this channel to **{speed}**.'
'channel_commands.google.settings.speed.success': 'You have successfully changed the speed for this channel to **{speed}**.',

'channel_commands.microsoft.settings.language.unsupported': 'Language **{language}** is not supported by the Microsoft provider. Use **/ms_langs** to check the languages available.',
'channel_commands.microsoft.settings.language.success': "You have successfully changed the language for this channel to **{language}** with **{voice}**'s voice.",

'channel_commands.microsoft.settings.voice.unsupported': 'The voice **{voice}** is not supported for the language of this channel. Use **/ms_voices** to check the voices available.',
'channel_commands.microsoft.settings.voice.success': "You have successfully changed this channel's voice to **{voice}**.",

'channel_commands.microsoft.settings.volume.success': "You have successfully changed this channel's volume to **{volume}**.",
'channel_commands.microsoft.settings.rate.success': "You have successfully changed this channel's rate to **{rate}**.",
'channel_commands.microsoft.settings.pitch.success': "You have successfully changed this channel's pitch to **{pitch}**."
};

module.exports = {
Expand Down
12 changes: 11 additions & 1 deletion src/locales/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ const CHANNEL_COMMANDS = {

'channel_commands.google.settings.language.invalid': 'Ese no es un idioma válido. Escribe **/google_langs** para obtener una lista de los idiomas disponibles.',
'channel_commands.google.settings.language.success': 'Has cambiado el idioma de este canal a **{language}** con éxito.',
'channel_commands.google.settings.speed.success': 'Has cambiado la velocidad de este canal a **{speed}** con éxito.'
'channel_commands.google.settings.speed.success': 'Has cambiado la velocidad de este canal a **{speed}** con éxito.',

'channel_commands.microsoft.settings.language.unsupported': 'El idioma **{language}** no está disponible en el proveedor de Microsoft. Utiliza **/ms_langs** para obtener una lista de los idiomas disponibles.',
'channel_commands.microsoft.settings.language.success': 'Has cambiado con éxito el idioma de este canal a **{language}** con la voz de **{voice}**.',

'channel_commands.microsoft.settings.voice.unsupported': 'La voz **{voice}** no está disponible para el idioma de este canal. Utiliza **/ms_voices** para obtener una lista de los idiomas disponibles.',
'channel_commands.microsoft.settings.voice.success': 'Has cambiado la voz de este canal a **{voice}** con éxito.',

'channel_commands.microsoft.settings.volume.success': 'Has cambiado el volumen de este canal a **{volume}** con éxito.',
'channel_commands.microsoft.settings.rate.success': 'Has cambiado el ritmo de este canal a **{rate}** con éxito.',
'channel_commands.microsoft.settings.pitch.success': 'Has cambiado el tono de este canal a **{pitch}** con éxito.'
};

module.exports = {
Expand Down
12 changes: 11 additions & 1 deletion src/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ const CHANNEL_COMMANDS = {

'channel_commands.google.settings.language.invalid': "Cela n'est pas une langue valide. Utilisez **/google_langs** pour obtenir une liste de toutes les langues disponibles.",
'channel_commands.google.settings.language.success': 'Vous avez changé la langue de ce canal à **{language}** avec succès.',
'channel_commands.google.settings.speed.success': 'Vous avez changé la vitesse de ce canal à **{speed}** avec succès.'
'channel_commands.google.settings.speed.success': 'Vous avez changé la vitesse de ce canal à **{speed}** avec succès.',

'channel_commands.microsoft.settings.language.unsupported': "La langue **{language}** n'est pas disponible pour le fournisseur de Microsoft. Utilisez **/ms_langs** pour obtenir une liste des langues disponibles.",
'channel_commands.microsoft.settings.language.success': 'Vous avez changé la langue de ce canal à **{language}** avec la voix de **{voice}**.',

'channel_commands.microsoft.settings.voice.unsupported': "La voix **{voice}** n'est pas disponible pour la langue de ce canal. Utilisez **/ms_voices** pour obtenir une liste des voix disponibles.",
'channel_commands.microsoft.settings.voice.success': 'Vous avez changé la voix de ce canal à **{voice}** avec succès.',

'channel_commands.microsoft.settings.volume.success': 'Vous avez changé le volume de ce canal à **{volume}** avec succès.',
'channel_commands.microsoft.settings.rate.success': 'Vous avez changé le rythme de ce canal à **{rate}** avec succès.',
'channel_commands.microsoft.settings.pitch.success': 'Vous avez changé le ton de voix de ce canal à **{pitch}** avec succès.'
};

module.exports = {
Expand Down

0 comments on commit be529f6

Please sign in to comment.