Error handling for automatic TTS request
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user