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

@ -251,6 +251,7 @@ async function scheduleRandomMessage(firstTime = false)
} }
const randomMessage = await fetchMotd(); const randomMessage = await fetchMotd();
if (randomMessage) { if (randomMessage) {
try {
const audio = await requestTTSResponse(randomMessage); const audio = await requestTTSResponse(randomMessage);
const audioBuf = await audio.arrayBuffer(); const audioBuf = await audio.arrayBuffer();
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav'); const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
@ -258,7 +259,12 @@ async function scheduleRandomMessage(firstTime = false)
content: randomMessage, content: randomMessage,
files: [audioFile] files: [audioFile]
}); });
logInfo(`[bot] Sent MOTD: ${randomMessage}`); 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 { } else {
logWarn(`[bot] Could not fetch MOTD.`); logWarn(`[bot] Could not fetch MOTD.`);
} }

View File

@ -4,7 +4,7 @@ import {
SlashCommandBuilder SlashCommandBuilder
} from 'discord.js'; } from 'discord.js';
import 'dotenv/config'; import 'dotenv/config';
import { logError, logInfo, logWarn } from '../../../logging'; import { logError } from '../../../logging';
import { requestTTSResponse } from '../../util'; import { requestTTSResponse } from '../../util';
const config = { const config = {