Skip to content

Commit

Permalink
Tweak Tiltify API backup logic, add Discord Webhook notification if i…
Browse files Browse the repository at this point in the history
…t's used
  • Loading branch information
zoton2 committed Feb 17, 2024
1 parent c5e864d commit 1168350
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 14 additions & 1 deletion configschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@
"required": [
"enabled"
]
},
"tiltify": {
"type": "object",
"additionalProperties": false,
"properties": {
"errorDiscordWebhook": {
"type": "string"
},
"errorDiscordWebhookUserIdToPing": {
"type": "string"
}
}
}
},
"required": [
Expand All @@ -772,6 +784,7 @@
"server",
"discord",
"streamlabsCharity",
"therungg"
"therungg",
"tiltify"
]
}
23 changes: 22 additions & 1 deletion src/extension/tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const eventConfig = nodecg().bundleConfig.event;
const config = nodecg().bundleConfig.tracker;
const { useTestData } = nodecg().bundleConfig;
let cookies: NeedleResponse['cookies'];
let tiltifyApiBackupInterval: NodeJS.Timeout | undefined;
const tiltifyApiBackupLength = 5 * 60 * 1000;

/**
* Returns tracker cookies, if set.
Expand Down Expand Up @@ -53,6 +55,20 @@ async function updateDonationTotalFromAPI(init = false): Promise<void> {
if (init || donationTotal.value < total) {
nodecg().log.info('[Tracker] API donation total changed: $%s', total);
donationTotal.value = total;
// If we checked the donation total on an interval and it was different, the MQ
// messages may be failing. Using a Discord Webhook to notify someone for ease of use.
const webhookUrl = nodecg().bundleConfig.tiltify.errorDiscordWebhook;
const userId = nodecg().bundleConfig.tiltify.errorDiscordWebhookUserIdToPing;
if (!init && webhookUrl) {
await needle(
'post',
webhookUrl,
{
content: `${userId ? `<@${userId}> ` : ''}There may be an issue with the esa-layouts `
+ 'Tiltify integration with RabbitMQ messages!',
},
);
}
}
} catch (err) {
nodecg().log.warn('[Tracker] Error updating donation total from API');
Expand Down Expand Up @@ -88,7 +104,12 @@ mq.evt.on('donationTotalUpdated', (data) => {
let total = 0;
// HARDCODED FOR NOW!
if (data.event === 'esaw2024') {
clearInterval(tiltifyApiBackupInterval);
total += data.new_total;
tiltifyApiBackupInterval = setInterval(
updateDonationTotalFromAPITiltify,
tiltifyApiBackupLength,
);
}
if (donationTotal.value < total) {
nodecg().log.debug('[Tracker] Updated donation total received: $%s', total.toFixed(2));
Expand Down Expand Up @@ -218,5 +239,5 @@ if (config.enabled) {
// FOR TILTIFY USE!
// Get initial total from API and set an interval as a fallback.
updateDonationTotalFromAPITiltify(true);
setInterval(updateDonationTotalFromAPITiltify, 60 * 1000);
tiltifyApiBackupInterval = setInterval(updateDonationTotalFromAPITiltify, tiltifyApiBackupLength);
}
4 changes: 4 additions & 0 deletions src/types/schemas/configschema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export interface Configschema {
therungg: {
enabled: boolean;
};
tiltify: {
errorDiscordWebhook?: string;
errorDiscordWebhookUserIdToPing?: string;
};
}
export interface BidwarBias {
bidId: number;
Expand Down

0 comments on commit 1168350

Please sign in to comment.