Error handling for automatic TTS request

This commit is contained in:
James Shiffer
2024-05-11 05:15:45 +00:00
parent 09e3c4307c
commit 0adc21d73e
3 changed files with 23 additions and 17 deletions

View File

@@ -250,18 +250,24 @@ async function scheduleRandomMessage(firstTime = false)
return;
}
const randomMessage = await fetchMotd();
if (randomMessage) {
const audio = await requestTTSResponse(randomMessage);
const audioBuf = await audio.arrayBuffer();
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
await channel.send({
content: randomMessage,
files: [audioFile]
});
logInfo(`[bot] Sent MOTD: ${randomMessage}`);
} else {
logWarn(`[bot] Could not fetch MOTD.`);
}
if (randomMessage) {
try {
const audio = await requestTTSResponse(randomMessage);
const audioBuf = await audio.arrayBuffer();
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
await channel.send({
content: randomMessage,
files: [audioFile]
});
logInfo(`[bot] Sent MOTD + TTS: ${randomMessage}`);
} catch (err) {
await channel.send(randomMessage);
logWarn(`[bot] Could not fetch MOTD TTS: ${err}`);
logInfo(`[bot] Send text MOTD: ${randomMessage}`);
}
} else {
logWarn(`[bot] Could not fetch MOTD.`);
}
}
// wait between 2-8 hours
const timeoutMins = Math.random() * 360 + 120;