anonradio: reduce edit spam on openmic

This commit is contained in:
Cynthia Foxwell 2022-12-21 20:13:34 -07:00
parent 5b04ce97a9
commit 370f6a882a

View file

@ -1,5 +1,3 @@
const {formatTime} = require("../lib/utils.js");
const GUILD_ID = "300436792916836352";
const THREAD_ID = "1054106209273253888";
const MESSAGE_ID = "1054109813132509245";
@ -98,10 +96,14 @@ async function updateNowPlaying() {
);
if (streamData && streamData.stream_start_iso8601) {
const startTime = new Date(streamData.stream_start_iso8601).getTime();
title = `${streamData.title} (\`${streamData.server_name ? streamData.server_name + " | " + liveNow.id : liveNow.id}\`)`;
openmicTime = `-\\*- OpenMIC DJ has been streaming for ${formatTime(
Date.now() - startTime
)} -\\*-\n`;
title = `${streamData.title} (\`${
streamData.server_name
? streamData.server_name + " | " + liveNow.id
: liveNow.id
}\`)`;
openmicTime = `-\\*- OpenMIC DJ has been streaming since <t:${Math.round(
startTime / 1000
)}:R> -\\*-\n`;
}
} catch (err) {
//
@ -109,15 +111,17 @@ async function updateNowPlaying() {
}
const now = Date.now();
const timestamp = `<t:${Math.floor(now/1000)}:T>`;
const timestamp = `<t:${Math.floor(now / 1000)}:T>`;
const content = `${title}\n${subtitle}\n${openmicTime}`.trim();
const thread = hf.bot.guilds.get(GUILD_ID)?.threads.get(THREAD_ID);
if (thread) {
const msg = await thread.getMessage(MESSAGE_ID);
const oldContent = msg.content.replace(/<t:\d+:T>/,"").trim();
const oldContent = msg.content.replace(/<t:\d+:T>\n/, "").trim();
if (oldContent !== content) {
await thread.editMessage(MESSAGE_ID, {content: timestamp + "\n" + content});
await thread.editMessage(MESSAGE_ID, {
content: timestamp + "\n" + content,
});
}
}