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
1 changed files with 13 additions and 9 deletions

View File

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