Compare commits

...

3 commits

Author SHA1 Message Date
eecb6020ea Some fix? 2022-09-23 19:45:59 +02:00
605390bfe2 dectalk! 2022-09-23 19:41:18 +02:00
91b3b6bc1e Add "voice" category 2022-09-23 19:41:07 +02:00
5 changed files with 51 additions and 4 deletions

View file

@ -144,6 +144,7 @@ export default {
utility: '🔩\u2000Utility',
admin: '⚡\u2000Admin',
owner: '🛠️\u2000Owner',
voice: '🗣️\u2000Voice',
}[category];
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });

43
commands/voice/dectalk.js Normal file
View file

@ -0,0 +1,43 @@
import { SlashCommandBuilder } from 'discord.js';
import { rand } from '../../utils/rand.js';
import { execFile } from 'node:child_process';
export default {
data: new SlashCommandBuilder()
.setName('dectalk')
.setDescription('Send a .wav sound file of what you wrote with dectalk')
.addStringOption(option =>
option.setName('message')
.setDescription('Write something so I can talk it back with dectalk.')
.setRequired(true)),
category: 'voice',
async execute(interaction, args) {
args.message = rand(args.message, interaction);
const output = `${interaction.id}_dectalk.wav`;
const message = '[:phoneme on]' + args.message;
await interaction.deferReply({ ephemeral: false });
if (process.platform === 'win32') {
// Untested, most likely do not work.
execFile('say.exe', ['-w', output, `${message}`], { cwd: './bin/dectalk/' }, (error, stdout, stderr) => {
sendMessage(output, error, stdout, stderr);
});
}
else if (process.platform === 'linux' || process.platform === 'darwin') {
execFile('wine', ['say.exe', '-w', output, `${message}`], { cwd: './bin/dectalk/' }, (error, stdout, stderr) => {
sendMessage(`./bin/dectalk/${output}`, error, stdout, stderr);
});
}
async function sendMessage(file, error, stdout, stderr) {
if (error) {
console.error(stderr);
console.error(error);
return interaction.editReply('Oh no! an error has occurred!');
}
return interaction.editReply({ files: [file] });
}
},
};

View file

@ -20,6 +20,7 @@ client.commands = new Collection();
await loadCommandFromDir('fun');
await loadCommandFromDir('secret');
await loadCommandFromDir('utility');
await loadCommandFromDir('voice');
await loadCommandFromDir('admin');
await loadCommandFromDir('owner');

View file

@ -14,6 +14,7 @@ const commands = [];
await loadCommandFromDir('fun');
await loadCommandFromDir('secret');
await loadCommandFromDir('utility');
await loadCommandFromDir('voice');
await loadCommandFromDir('admin');
await loadCommandFromDir('owner');
commands.map(command => command.toJSON());

View file

@ -1,5 +1,6 @@
import fs from 'node:fs';
export function rand(text, message) {
export function rand(text, interaction) {
interaction.author = interaction.user;
// Find a value in an array of objects in Javascript - https://stackoverflow.com/a/12462387
function search(nameKey, myArray) {
for (let i = 0; i < myArray.length; i++) {
@ -23,15 +24,15 @@ export function rand(text, message) {
const variables = [
{
name: /\[author\]/,
value: message ? message.author.username : '',
value: interaction ? interaction.author.username : '',
},
{
name: /\[member\]/,
value: message ? message.guild ? message.guild.members.cache.random().user.username : '' : '',
value: interaction ? interaction.guild ? interaction.guild.members.cache.random().user.username : '' : '',
},
{
name: /\[memberRand\]/,
value: (() => message.guild ? message.guild.members.cache.random().user.username : ''),
value: (() => interaction.guild ? interaction.guild.members.cache.random().user.username : ''),
},
{
name: /\[dice\d*\]/,