diff --git a/README.md b/README.md index 35859a62..0424c3ea 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 551 +Total: 552 ### Utility: @@ -824,6 +824,7 @@ Total: 551 * **join:** Joins your voice channel. * **leave:** Leaves the current voice channel. * **soundboard:** Plays a sound in a voice channel. +* **vocodes:** Speak text like a variety of famous figures. ### Phone: @@ -1722,6 +1723,8 @@ here. * rip ([Image](https://www.123rf.com/profile_vician?mediapopup=13181623)) - [VocaDB](https://vocadb.net/) * vocadb ([API](https://vocadb.net/swagger/ui/index)) +- [Vocodes](https://vo.codes/) + * vocodes (API) - [Wait, what does your startup do?](http://itsthisforthat.com/) * this-for-that ([API](http://itsthisforthat.com/api.php)) - [WAIT: What Anime Is This?](https://trace.moe/) diff --git a/commands/voice/vocodes.js b/commands/voice/vocodes.js new file mode 100644 index 00000000..5d284050 --- /dev/null +++ b/commands/voice/vocodes.js @@ -0,0 +1,72 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { Readable } = require('stream'); +const { list } = require('../../util/Util'); +const voices = { + sonic: 'sonic', + homer: 'homer-simpson', + spongebob: 'spongebob-squarepants', + arnold: 'arnold-schwarzenegger' +}; + +module.exports = class VocodesCommand extends Command { + constructor(client) { + super(client, { + name: 'vocodes', + group: 'voice', + memberName: 'vocodes', + description: 'Speak text like a variety of famous figures.', + guildOnly: true, + throttling: { + usages: 1, + duration: 10 + }, + userPermissions: ['CONNECT', 'SPEAK'], + credit: [ + { + name: 'Vocodes', + url: 'https://vo.codes/', + reason: 'API' + } + ], + args: [ + { + key: 'voice', + prompt: `What voice do you want to use? Either ${list(Object.keys(voices), 'or')}.`, + type: 'string', + oneOf: Object.keys(voices), + parse: voice => voices[voice.toLowerCase()] + }, + { + key: 'text', + prompt: 'What text do you want to say?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { voice, text }) { + const connection = this.client.voice.connections.get(msg.guild.id); + if (!connection) { + const usage = this.client.registry.commands.get('join').usage(); + return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`); + } + try { + const body = await request + .post('https://mumble.stream/speak_spectrogram') + .send({ + speaker: voice, + text + }); + connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')])); + if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) { + await msg.react('🔉'); + } + return null; + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index ea312b9e..a945a762 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.33.1", + "version": "119.34.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {