From 5dd80d060e2e56ed47bdafcd282e2f4e30353898 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 8 May 2021 20:58:34 -0400 Subject: [PATCH] Trebek Command --- commands/voice/trebek.js | 67 ++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 commands/voice/trebek.js diff --git a/commands/voice/trebek.js b/commands/voice/trebek.js new file mode 100644 index 00000000..57b5c02c --- /dev/null +++ b/commands/voice/trebek.js @@ -0,0 +1,67 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { Readable } = require('stream'); +const { reactIfAble } = require('../../util/Util'); +const { LOADING_EMOJI_ID } = process.env; + +module.exports = class TrebekCommand extends Command { + constructor(client) { + super(client, { + name: 'trebek', + aliases: ['alex-trebek'], + group: 'voice', + memberName: 'trebek', + description: 'Speak text like Alex Trebek.', + guildOnly: true, + throttling: { + usages: 2, + duration: 30 + }, + userPermissions: ['CONNECT', 'SPEAK'], + credit: [ + { + name: 'Uberduck', + url: 'https://uberduck.ai/', + reason: 'API', + reasonURL: 'https://uberduck.ai/#voice=trebek' + } + ], + args: [ + { + key: 'speech', + label: 'text', + prompt: 'What text do you want to say?', + type: 'string', + max: 500 + } + ] + }); + } + + async run(msg, { speech }) { + 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!`); + } + if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.'); + try { + await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬'); + const { text } = await request + .post('https://api.uberduck.ai/speak') + .send({ + voice: 'trebek', + speech + }); + const dispatcher = connection.play(Readable.from([Buffer.from(text, 'base64')])); + this.client.dispatchers.set(msg.guild.id, dispatcher); + dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id)); + dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id)); + await reactIfAble(msg, this.client.user, '🔉'); + return null; + } catch (err) { + await reactIfAble(msg, this.client.user, '⚠️'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 127debb4..d9731eb2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "139.2.3", + "version": "139.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true,