2022-12-18 19:37:00 +00:00
|
|
|
const {formatTime} = require("../lib/utils.js");
|
|
|
|
|
2022-12-18 19:27:32 +00:00
|
|
|
const GUILD_ID = "300436792916836352";
|
|
|
|
const THREAD_ID = "1054106209273253888";
|
|
|
|
const MESSAGE_ID = "1054109813132509245";
|
|
|
|
|
2022-12-21 15:58:57 +00:00
|
|
|
if (hf.__anonradio_timeout) {
|
|
|
|
clearTimeout(hf.__anonradio_timeout);
|
|
|
|
}
|
|
|
|
|
2022-12-18 19:27:32 +00:00
|
|
|
async function updateNowPlaying() {
|
|
|
|
let playing;
|
|
|
|
try {
|
|
|
|
playing = await fetch("https://anonradio.net/playing").then((res) =>
|
|
|
|
res.text()
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
try {
|
|
|
|
playing = await fetch("http://anonradio.net/playing").then((res) =>
|
|
|
|
res.text()
|
|
|
|
);
|
2022-12-18 19:37:00 +00:00
|
|
|
} catch (err) {
|
|
|
|
//
|
|
|
|
}
|
2022-12-18 19:27:32 +00:00
|
|
|
}
|
|
|
|
let schedule;
|
|
|
|
try {
|
|
|
|
schedule = await fetch("https://anonradio.net/schedule/").then((res) =>
|
|
|
|
res.text()
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
try {
|
|
|
|
schedule = await fetch("http://anonradio.net/schedule/").then((res) =>
|
|
|
|
res.text()
|
|
|
|
);
|
2022-12-18 19:37:00 +00:00
|
|
|
} catch (err) {
|
|
|
|
//
|
|
|
|
}
|
2022-12-18 19:27:32 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 23:46:13 +00:00
|
|
|
if (!playing || !schedule) {
|
|
|
|
hf.__anonradio_timeout = setTimeout(updateNowPlaying, 2000);
|
|
|
|
return;
|
|
|
|
}
|
2022-12-18 19:27:32 +00:00
|
|
|
|
|
|
|
let lines = schedule.split("\n");
|
|
|
|
lines = lines.slice(4, lines.length - 2);
|
|
|
|
const line = lines[0];
|
|
|
|
|
2022-12-21 23:46:13 +00:00
|
|
|
if (!line) {
|
|
|
|
hf.__anonradio_timeout = setTimeout(updateNowPlaying, 2000);
|
|
|
|
return;
|
|
|
|
}
|
2022-12-18 22:01:50 +00:00
|
|
|
|
2022-12-18 19:37:00 +00:00
|
|
|
const [_, _time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/);
|
2022-12-18 19:27:32 +00:00
|
|
|
|
2022-12-18 19:37:00 +00:00
|
|
|
const liveNow = {name: "ident", id: "aNONradio"};
|
2022-12-18 19:27:32 +00:00
|
|
|
|
|
|
|
if (name.includes("<- Live NOW")) {
|
|
|
|
liveNow.id = id;
|
|
|
|
liveNow.name = name.replace("<- Live NOW", "").trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = "";
|
|
|
|
let subtitle = "";
|
|
|
|
|
|
|
|
if (playing.includes("listeners with a daily peak of")) {
|
|
|
|
title = `${liveNow.name} (\`${liveNow.id}\`)`;
|
|
|
|
subtitle = playing;
|
2022-12-18 20:04:20 +00:00
|
|
|
} else if (playing.startsWith("Coming up")) {
|
|
|
|
title = playing;
|
2022-12-18 19:27:32 +00:00
|
|
|
} else {
|
|
|
|
const [_, current, peakDay, peakMonth, dj, metadata] = playing.match(
|
|
|
|
/\[(\d+)\/(\d+)\/(\d+)\] \((.+?)\): (.+)/
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
metadata == "https://archives.anonradio.net" ||
|
|
|
|
liveNow.name == "Synth Battle Royale"
|
|
|
|
) {
|
|
|
|
title = `${liveNow.name} (\`${dj}\`)`;
|
|
|
|
} else {
|
|
|
|
title = `${metadata} (\`${dj}\`)`;
|
|
|
|
}
|
|
|
|
subtitle = `${current} listening with a daily peak of ${peakDay} and ${peakMonth} peak for the month.`;
|
|
|
|
}
|
|
|
|
|
|
|
|
let openmicTime = "";
|
|
|
|
if (liveNow.id == "openmic") {
|
|
|
|
try {
|
|
|
|
const icecast = await fetch("http://anonradio.net:8010/status-json.xsl")
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then((data) =>
|
|
|
|
JSON.parse(data.replace(/"title": - ,/g, '"title":" - ",'))
|
|
|
|
);
|
|
|
|
const streamData = icecast.icestats.source.find(
|
|
|
|
(src) => src.listenurl == "http://anonradio.net:8010/openmic"
|
|
|
|
);
|
|
|
|
if (streamData && streamData.stream_start_iso8601) {
|
|
|
|
const startTime = new Date(streamData.stream_start_iso8601).getTime();
|
2022-12-21 17:59:24 +00:00
|
|
|
title = `${streamData.title} (\`${streamData.server_name ? streamData.server_name + " | " + liveNow.id : liveNow.id}\`)`;
|
2022-12-18 19:27:32 +00:00
|
|
|
openmicTime = `-\\*- OpenMIC DJ has been streaming for ${formatTime(
|
|
|
|
Date.now() - startTime
|
|
|
|
)} -\\*-\n`;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-21 16:03:53 +00:00
|
|
|
const now = Date.now();
|
|
|
|
const timestamp = `<t:${Math.floor(now/1000)}:T>`;
|
|
|
|
|
2022-12-21 16:07:19 +00:00
|
|
|
const content = `${title}\n${subtitle}\n${openmicTime}`.trim();
|
2022-12-21 16:05:10 +00:00
|
|
|
const thread = hf.bot.guilds.get(GUILD_ID)?.threads.get(THREAD_ID);
|
2022-12-19 17:33:17 +00:00
|
|
|
if (thread) {
|
|
|
|
const msg = await thread.getMessage(MESSAGE_ID);
|
2022-12-21 16:09:55 +00:00
|
|
|
const oldContent = msg.content.replace(/<t:\d+:T>/,"").trim();
|
2022-12-21 16:07:19 +00:00
|
|
|
if (oldContent !== content) {
|
|
|
|
await thread.editMessage(MESSAGE_ID, {content: timestamp + "\n" + content});
|
2022-12-19 17:33:17 +00:00
|
|
|
}
|
2022-12-18 19:27:32 +00:00
|
|
|
}
|
2022-12-21 15:58:57 +00:00
|
|
|
|
|
|
|
hf.__anonradio_timeout = setTimeout(updateNowPlaying, 2000);
|
2022-12-18 19:27:32 +00:00
|
|
|
}
|
2022-12-21 16:05:10 +00:00
|
|
|
updateNowPlaying();
|
2022-12-18 19:27:32 +00:00
|
|
|
|
2022-12-21 15:58:57 +00:00
|
|
|
/*hf.timer.add(
|
2022-12-19 17:33:17 +00:00
|
|
|
"anonradio",
|
|
|
|
async () => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
setTimeout(() => reject("timeout"), 1900);
|
|
|
|
updateNowPlaying().then(() => resolve(true));
|
|
|
|
}).catch(() => {});
|
|
|
|
},
|
|
|
|
2000
|
2022-12-21 15:58:57 +00:00
|
|
|
);*/
|