Haha-Yes/commands/fun/tts/dectalk.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-17 23:39:13 +02:00
const { Command } = require('discord-akairo');
const axios = require('axios');
const fs = require('fs');
2019-05-19 21:36:42 +02:00
const rand = require('../../../rand.js');
2019-05-17 23:39:13 +02:00
class dectalkCommand extends Command {
constructor() {
super('dectalk', {
aliases: ['dectalk', 'dec'],
category: 'fun',
args: [
{
id: 'decMessage',
type: 'string',
2019-06-23 03:41:59 +02:00
prompt: {
start: 'Write something so i can say it back in dectalk',
},
2019-05-17 23:39:13 +02:00
match: 'rest'
}
],
description: {
2019-05-18 03:01:57 +02:00
content: 'Send a wav of what you wrote into .wav with dectalk',
usage: '[text]',
examples: ['This command is very epic']
2019-05-17 23:39:13 +02:00
}
});
}
async exec(message, args) {
2019-05-19 20:41:58 +02:00
args.decMessage = rand.random(args.decMessage, message);
2019-05-17 23:55:17 +02:00
args.decMessage = args.decMessage.replace('\n', ' ');
2019-05-17 23:39:13 +02:00
args.decMessage = encodeURI(args.decMessage);
return axios.request({
responseType: 'arraybuffer',
url: `https://talk.moustacheminer.com/api/gen.wav?dectalk=${args.decMessage}`,
method: 'get',
headers: {
'Content-Type': 'audio/wav',
},
}).then((result) => {
const outputFilename = './dectalk.wav';
fs.writeFileSync(outputFilename, result.data);
return message.channel.send({files: ['./dectalk.wav']});
});
}
}
module.exports = dectalkCommand;