From 352f92866019ba9002b52a82fab9d4d36d0f0a30 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 16 Aug 2022 14:30:58 -0600 Subject: [PATCH] misc.anonradio: pull metadata --- src/modules/misc.js | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/modules/misc.js b/src/modules/misc.js index 0175f70..20acbe3 100644 --- a/src/modules/misc.js +++ b/src/modules/misc.js @@ -269,13 +269,15 @@ vote.callback = async function (msg, line) { hf.registerCommand(vote); const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; -const arsched = new Command("arsched"); -arsched.category = CATEGORY; -arsched.helpText = "aNONradio.net schedule"; -arsched.addAlias("anonradio"); -arsched.callback = async function (msg, line) { +const anonradio = new Command("anonradio"); +anonradio.category = CATEGORY; +anonradio.helpText = "aNONradio.net schedule"; +anonradio.callback = async function (msg, line) { const now = new Date(); + const playing = await fetch("https://anonradio.net/playing").then((res) => + res.text() + ); const schedule = await fetch("https://anonradio.net/schedule/").then((res) => res.text() ); @@ -320,14 +322,34 @@ arsched.callback = async function (msg, line) { const liveNow = parsedLines.splice(0, 1)[0]; liveNow.name = liveNow.name.replace(" <- Live NOW", ""); + let title = ""; + let subtitle = ""; + + if (playing.includes("listeners with a daily peak of")) { + title = `${liveNow.name} (\`${liveNow.id}\`)`; + subtitle = playing; + } else { + const [_, current, peakDay, peakMonth, dj, metadata] = playing.match( + /\[(\d+)\/(\d+)\/(\d+)\] \((.+?)\): (.+?)/ + ); + + if (metadata == "https://archives.anonradio.net") { + title = `${liveNow.name} (\`${dj}\`)`; + } else { + title = `${metadata} (\`${dj}\`)`; + } + subtitle = `${current} listening with a daily peak of ${peakDay} and ${peakMonth} peak for the month.`; + } + return { embeds: [ { - title: "Click to listen", - url: "http://anonradio.net:8000/anonradio", + title: subtitle, author: { - name: `LIVE NOW: ${liveNow.name} (\`${liveNow.id}\`)`, + name: title, + url: "http://anonradio.net:8000/anonradio", }, + description: "__Schedule:__", fields: parsedLines.map((line) => ({ inline: true, name: `${line.name} (\`${line.id}\`)`, @@ -337,7 +359,7 @@ arsched.callback = async function (msg, line) { ], }; }; -hf.registerCommand(arsched); +hf.registerCommand(anonradio); const REGEX_IPV4 = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/; const shodan = new Command("shodan");