Add support for sending stats to Matrix, split out some code into more generic classes. #1
18
index.js
18
index.js
|
@ -140,15 +140,15 @@ async function sendSummaryMatrix(yesterday, stats) {
|
||||||
const html = `
|
const html = `
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr><td colspan="2"><strong>Summary from ${yesterday.startDate.toString()} to ${yesterday.endDate.toString()}</strong></td></tr><br/>
|
<tr><td colspan="2"><strong>Summary from ${yesterday.startDate.toString()} to ${yesterday.endDate.toString()}</strong></td></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td>Calls Made</td><td>${stats.totalCallsMade}</td></tr><br/>
|
<tr><td>Calls Made</td><td>${stats.totalCallsMade}</td></tr>
|
||||||
<tr><td>Monthly Total</td><td>${stats.totalCallsThisMonth}</td></tr><br/>
|
<tr><td>Monthly Total</td><td>${stats.totalCallsThisMonth}</td></tr>
|
||||||
<tr><td>Total Calls Ever Placed</td><td>${stats.totalCallsEverPlaced}</td></tr><br/>
|
<tr><td>Total Calls Ever Placed</td><td>${stats.totalCallsEverPlaced}</td></tr>
|
||||||
<tr><td>System Uptime</td><td>${getSystemUptime().toString(false, false)}</td></tr><br/>
|
<tr><td>System Uptime</td><td>${getSystemUptime().toString(false, false)}</td></tr>
|
||||||
<tr><td>All Time Record</td><td>${stats.allTimeRecord}</td></tr><br/>
|
<tr><td>All Time Record</td><td>${stats.allTimeRecord}</td></tr>
|
||||||
${stats.isNewRecord ? `<tr><td colspan="2">🎉 NEW RECORD! 🎉 A new record has been set, at ${stats.totalCallsMade}!</td></tr><br/>` : ''}
|
${stats.isNewRecord ? `<tr><td colspan="2"><span data-mx-color="#FFD700">🎉 NEW RECORD! 🎉</span> A new record has been set, at ${stats.totalCallsMade} calls in a day!</td></tr>` : ''}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
`;
|
`;
|
||||||
|
@ -161,7 +161,7 @@ Monthly Total: ${stats.totalCallsThisMonth}
|
||||||
Total Calls Ever Placed: ${stats.totalCallsEverPlaced}
|
Total Calls Ever Placed: ${stats.totalCallsEverPlaced}
|
||||||
System Uptime: ${getSystemUptime().toString(false, false)}
|
System Uptime: ${getSystemUptime().toString(false, false)}
|
||||||
All Time Record: ${stats.allTimeRecord}
|
All Time Record: ${stats.allTimeRecord}
|
||||||
${stats.isNewRecord ? `🎉 NEW RECORD! 🎉 A new record has been set, at ${stats.totalCallsMade}!` : ''}`,
|
${stats.isNewRecord ? `🎉 NEW RECORD! 🎉 A new record has been set, at ${stats.totalCallsMade} calls in a day!` : ''}`,
|
||||||
"formatted_body": html.split('\n').map(s => s.trim()).join(''),
|
"formatted_body": html.split('\n').map(s => s.trim()).join(''),
|
||||||
"tel.litenet.call_stats_summary": {
|
"tel.litenet.call_stats_summary": {
|
||||||
...stats, date: yesterday
|
...stats, date: yesterday
|
||||||
|
@ -193,7 +193,7 @@ async function sendSummaryDiscord(yesterday, stats) {
|
||||||
|
|
||||||
if (stats.isNewRecord) {
|
if (stats.isNewRecord) {
|
||||||
embed.color = 0xFFD700; // Gold color for new record
|
embed.color = 0xFFD700; // Gold color for new record
|
||||||
embed.fields.push(makeField("🎉 NEW RECORD! 🎉", `A new record has been set, at ${stats.totalCallsMade}!`));
|
embed.fields.push(makeField("🎉 NEW RECORD! 🎉", `A new record has been set, at ${stats.totalCallsMade} calls in a day!`));
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = { embeds: [ embed ] };
|
const payload = { embeds: [ embed ] };
|
||||||
|
|
Loading…
Reference in a new issue