Compare commits
3 commits
9dd060aa28
...
eecb6020ea
Author | SHA1 | Date | |
---|---|---|---|
eecb6020ea | |||
605390bfe2 | |||
91b3b6bc1e |
5 changed files with 51 additions and 4 deletions
|
@ -144,6 +144,7 @@ export default {
|
||||||
utility: '🔩\u2000Utility',
|
utility: '🔩\u2000Utility',
|
||||||
admin: '⚡\u2000Admin',
|
admin: '⚡\u2000Admin',
|
||||||
owner: '🛠️\u2000Owner',
|
owner: '🛠️\u2000Owner',
|
||||||
|
voice: '🗣️\u2000Voice',
|
||||||
}[category];
|
}[category];
|
||||||
|
|
||||||
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });
|
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });
|
||||||
|
|
43
commands/voice/dectalk.js
Normal file
43
commands/voice/dectalk.js
Normal 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] });
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
1
index.js
1
index.js
|
@ -20,6 +20,7 @@ client.commands = new Collection();
|
||||||
await loadCommandFromDir('fun');
|
await loadCommandFromDir('fun');
|
||||||
await loadCommandFromDir('secret');
|
await loadCommandFromDir('secret');
|
||||||
await loadCommandFromDir('utility');
|
await loadCommandFromDir('utility');
|
||||||
|
await loadCommandFromDir('voice');
|
||||||
await loadCommandFromDir('admin');
|
await loadCommandFromDir('admin');
|
||||||
await loadCommandFromDir('owner');
|
await loadCommandFromDir('owner');
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ const commands = [];
|
||||||
await loadCommandFromDir('fun');
|
await loadCommandFromDir('fun');
|
||||||
await loadCommandFromDir('secret');
|
await loadCommandFromDir('secret');
|
||||||
await loadCommandFromDir('utility');
|
await loadCommandFromDir('utility');
|
||||||
|
await loadCommandFromDir('voice');
|
||||||
await loadCommandFromDir('admin');
|
await loadCommandFromDir('admin');
|
||||||
await loadCommandFromDir('owner');
|
await loadCommandFromDir('owner');
|
||||||
commands.map(command => command.toJSON());
|
commands.map(command => command.toJSON());
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import fs from 'node:fs';
|
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
|
// Find a value in an array of objects in Javascript - https://stackoverflow.com/a/12462387
|
||||||
function search(nameKey, myArray) {
|
function search(nameKey, myArray) {
|
||||||
for (let i = 0; i < myArray.length; i++) {
|
for (let i = 0; i < myArray.length; i++) {
|
||||||
|
@ -23,15 +24,15 @@ export function rand(text, message) {
|
||||||
const variables = [
|
const variables = [
|
||||||
{
|
{
|
||||||
name: /\[author\]/,
|
name: /\[author\]/,
|
||||||
value: message ? message.author.username : '',
|
value: interaction ? interaction.author.username : '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: /\[member\]/,
|
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\]/,
|
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*\]/,
|
name: /\[dice\d*\]/,
|
||||||
|
|
Loading…
Reference in a new issue