Compare commits

..

5 commits

Author SHA1 Message Date
a430d0d1ed lib.unicode: use www 2022-12-20 11:27:26 -07:00
bb597279b5 fedimbed: fix newlines yet again 2022-12-19 18:20:30 -07:00
0f3e029430 anonradio: attempt to reduce gradual edit spam 2022-12-19 10:33:17 -07:00
f77466831b . 2022-12-18 15:01:50 -07:00
a3cf7aabee anonradio: fix empty slots 2022-12-18 13:04:20 -07:00
3 changed files with 21 additions and 6 deletions

View file

@ -2,7 +2,7 @@ const mappings = {};
async function cacheList() { async function cacheList() {
const data = await fetch( const data = await fetch(
"https://unicode.org/Public/UNIDATA/UnicodeData.txt" "https://www.unicode.org/Public/UNIDATA/UnicodeData.txt"
).then((res) => res.text()); ).then((res) => res.text());
data data

View file

@ -40,6 +40,8 @@ async function updateNowPlaying() {
lines = lines.slice(4, lines.length - 2); lines = lines.slice(4, lines.length - 2);
const line = lines[0]; const line = lines[0];
if (!line) return;
const [_, _time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/); const [_, _time, id, name] = line.match(/^(.{3,4} .{4})\s+(.+?) {2}(.+?)$/);
const liveNow = {name: "ident", id: "aNONradio"}; const liveNow = {name: "ident", id: "aNONradio"};
@ -55,6 +57,8 @@ async function updateNowPlaying() {
if (playing.includes("listeners with a daily peak of")) { if (playing.includes("listeners with a daily peak of")) {
title = `${liveNow.name} (\`${liveNow.id}\`)`; title = `${liveNow.name} (\`${liveNow.id}\`)`;
subtitle = playing; subtitle = playing;
} else if (playing.startsWith("Coming up")) {
title = playing;
} else { } else {
const [_, current, peakDay, peakMonth, dj, metadata] = playing.match( const [_, current, peakDay, peakMonth, dj, metadata] = playing.match(
/\[(\d+)\/(\d+)\/(\d+)\] \((.+?)\): (.+)/ /\[(\d+)\/(\d+)\/(\d+)\] \((.+?)\): (.+)/
@ -95,10 +99,21 @@ async function updateNowPlaying() {
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) {
const msg = await thread.getMessage(MESSAGE_ID); const msg = await thread.getMessage(MESSAGE_ID);
if (msg.content !== content) { if (msg.content !== content) {
thread.editMessage(MESSAGE_ID, {content}); await thread.editMessage(MESSAGE_ID, {content});
}
} }
} }
hf.timer.add("anonradio", updateNowPlaying, 2000); hf.timer.add(
"anonradio",
async () => {
await new Promise((resolve, reject) => {
setTimeout(() => reject("timeout"), 1900);
updateNowPlaying().then(() => resolve(true));
}).catch(() => {});
},
2000
);

View file

@ -289,7 +289,7 @@ async function processUrl(msg, url) {
cw = cw ?? ""; cw = cw ?? "";
// TODO: convert certain HTML tags back to markdown // TODO: convert certain HTML tags back to markdown
content = content.replace(/<br>/g, "\n"); content = content.replace(/<\/?\s*br\s*\/?>/g, "\n");
content = content.replace(/<\/p><p>/g, "\n\n"); content = content.replace(/<\/p><p>/g, "\n\n");
content = content.replace(/(<([^>]+)>)/gi, ""); content = content.replace(/(<([^>]+)>)/gi, "");
content = parseHtmlEntities(content); content = parseHtmlEntities(content);