mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-30 20:05:29 +02:00
added speaking queue to ensure bot doesn't say multiple things at once
This commit is contained in:
parent
e612b00410
commit
4b38aba2dc
1 changed files with 23 additions and 5 deletions
|
@ -1,6 +1,23 @@
|
|||
import { exec } from 'child_process';
|
||||
|
||||
let speakingQueue = [];
|
||||
let isSpeaking = false;
|
||||
|
||||
export function say(textToSpeak) {
|
||||
speakingQueue.push(textToSpeak);
|
||||
if (!isSpeaking) {
|
||||
processQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function processQueue() {
|
||||
if (speakingQueue.length === 0) {
|
||||
isSpeaking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isSpeaking = true;
|
||||
const textToSpeak = speakingQueue.shift();
|
||||
const isWin = process.platform === "win32";
|
||||
const isMac = process.platform === "darwin";
|
||||
|
||||
|
@ -17,11 +34,12 @@ export function say(textToSpeak) {
|
|||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`Error: ${stderr}`);
|
||||
return;
|
||||
console.error(`Stack: ${error.stack}`);
|
||||
} else if (stderr) {
|
||||
console.error(`Stderr: ${stderr}`);
|
||||
} else {
|
||||
console.log(`Stdout: ${stdout}`);
|
||||
}
|
||||
processQueue(); // Continue with the next message in the queue
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue