misc: add arsched
This commit is contained in:
parent
4f18677bc0
commit
bbbc82c611
1 changed files with 70 additions and 0 deletions
|
@ -256,3 +256,73 @@ vote.callback = async function (msg, line) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
hf.registerCommand(vote);
|
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.callback = async function (msg, line) {
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const schedule = await fetch("https://anonradio.net/schedule/").then((res) =>
|
||||||
|
res.text()
|
||||||
|
);
|
||||||
|
|
||||||
|
let lines = schedule.split("\n");
|
||||||
|
lines = lines.slice(4, lines.length - 2);
|
||||||
|
|
||||||
|
const parsedLines = [];
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
const [_, time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/);
|
||||||
|
|
||||||
|
const tmp = time.split(" ");
|
||||||
|
const day = tmp[0];
|
||||||
|
let hour = tmp[1];
|
||||||
|
const currentDay = now.getUTCDay();
|
||||||
|
const targetDay = DAYS.indexOf(day);
|
||||||
|
const delta = (targetDay + 7 - currentDay) % 7;
|
||||||
|
|
||||||
|
let currentYear = now.getUTCFullYear();
|
||||||
|
const currentMonth = now.getUTCMonth();
|
||||||
|
const currentDateDay = now.getUTCDate();
|
||||||
|
let targetMonth = currentMonth;
|
||||||
|
const lastDay = new Date(currentYear, currentMonth, 0).getDate();
|
||||||
|
let targetDateDay = currentDateDay + delta;
|
||||||
|
if (targetDateDay > lastDay) {
|
||||||
|
targetMonth = currentMonth === 12 ? 1 : currentMonth + 1;
|
||||||
|
targetDateDay = 1;
|
||||||
|
if (currentMonth === 12) currentYear++;
|
||||||
|
}
|
||||||
|
|
||||||
|
hour = hour.slice(0, 2) + ":" + hour.slice(-2);
|
||||||
|
|
||||||
|
const timestamp =
|
||||||
|
Date.parse(
|
||||||
|
`${DAYS[targetDay]}, ${currentYear}-${targetMonth}-${targetDateDay} ${hour} UTC`
|
||||||
|
) / 1000;
|
||||||
|
|
||||||
|
parsedLines.push({timestamp, id, name});
|
||||||
|
}
|
||||||
|
|
||||||
|
const liveNow = parsedLines.splice(0, 1)[0];
|
||||||
|
liveNow.name = liveNow.name.replace(" <- Live NOW", "");
|
||||||
|
|
||||||
|
return {
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Click to listen",
|
||||||
|
url: "http://anonradio.net:8000/anonradio",
|
||||||
|
author: {
|
||||||
|
name: `LIVE NOW: ${liveNow.name} (\`${liveNow.id}\`)`,
|
||||||
|
},
|
||||||
|
fields: parsedLines.map((line) => ({
|
||||||
|
inline: true,
|
||||||
|
name: `${line.name} (\`${line.id}\`)`,
|
||||||
|
value: `<t:${line.timestamp}:R>`,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
hf.registerCommand(arsched);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue