Last active
November 30, 2024 10:55
-
-
Save brian6932/747c5c9333bb89b64a34e6aace014f7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
y = 31_536_000, | |
d = 86_400, | |
h = 3_600, | |
m = 60, | |
unescObject = { | |
__proto__: null, | |
'&': `&`, | |
'\': `\\`, | |
'"': `"`, | |
'<': `<`, | |
'>': `>`, | |
''': `'` | |
}, | |
unescRe = RegExp(`&(?:a(?:mp|pos)|bsol|quot|[lg]t);`, `lg`), | |
SecondsConverter = function (input) { | |
let remainder | |
this.y = input / y | 0 | |
this.d = (remainder = input - y * this.y) / d | 0 | |
this.h = (remainder -= d * this.d) / h | 0 | |
this.m = (remainder -= h * this.h) / m | 0 | |
}, | |
rm = async () => { | |
let cmd = await command.execute(rm.name, args[0], `rawData:true`) | |
if (!cmd.success) | |
throw Error(cmd.reason ?? cmd.reply) | |
let { score } = cmd = cmd.data.post | |
if (score >= 1_000) { | |
const | |
negative = +(Math.sign(score) === -1), | |
log = Math.log10(score = Math.abs(score)) | 0 | |
let | |
length = (log / 3 | 0) + log + 1 + negative, | |
third = 0 | |
const buf = Buffer.allocUnsafe(length) | |
buf[0] = 45 // dash | |
for (;;) { | |
const tenth = score * .1 | 0 | |
buf[--length] = (score - 10 * tenth) + 48 // zero | |
score = tenth | |
if (length <= negative) | |
break | |
if (++third === 3) { | |
buf[--length] = 44 // comma | |
third = 0 | |
} | |
} | |
score = buf.toString(`ascii`) | |
} | |
let | |
metadata = ` (Score: ${score}, posted `, | |
i = 0 | |
const | |
difference = new SecondsConverter((Date.now() - new Date(cmd.created).getTime()) * .001 | 0), | |
{ length } = metadata | |
for (const field in difference) { | |
if (!difference[field]) | |
continue | |
metadata += (metadata.length === length ? `` : `, `) + difference[field] + field | |
if (++i === 2) | |
break | |
} | |
metadata += ` ago` | |
if (cmd.crosspostOrigin !== null) | |
metadata += `, x-posted from r/${cmd.crosspostOrigin}` | |
metadata += `)` | |
cmd.title = cmd.title.replace(unescRe, str => obj[str]) | |
if (cmd.isGallery) | |
return cmd.title + ` ` + cmd.galleryLinks.join(` `) + metadata | |
if (cmd.isVideo) | |
cmd.url += ` ` + cmd.url + `/HLSPlaylist.m3u8` | |
return cmd.title + ` ` + cmd.url + metadata | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment