From c858d66a3f005d3324e7a23246dc2aed65477e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 1 May 2024 13:08:13 +0200 Subject: [PATCH] feat: bun.report reports --- bun.lockb | Bin 18181 -> 18546 bytes package.json | 1 + src/listeners/message_create.tsx | 19 ++++++++++++++++++- src/util.ts | 24 ++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bun.lockb b/bun.lockb index c248908b96a19d3e14a1f995f4b48d363798d02a..4a46b8d6d1d75ae959afd4e0f855627277963862 100755 GIT binary patch delta 3061 zcmcguX>3$g6ux(s(&@}=sn~X2r|py-WM(?U&}p%>LlL@-RW>uYp)7@tK*6>MO~h6r z#)8$7lNfMA{yPLgj`$PYN*{I188wT#;&78eF|hoG|5eTl@W;PuPXX zfbl_e;-A+8HQ;Wi5ElYB0Ciw7FqiEPA##BCKrR4Y2P^_M0xtl@fO)_SApd_5|1*R<3~U5Cjk80U!t5v1rvw zs70}d?vkPOUI;PP9dzp;VfFmw%BbPHSKcISN+*OW*vE4xj9A&bF2B3Q$x@pi! z^eLHus8m~hQ&UT@tyvs1Q*5fmNyz#5o2uawTXvK`crR^{A_l+{sVT7@$+O^CUQ zyB^%7ihCAZgW`Sxw?J{14HM!T#XSvfrs9r+yG(J@(yhLC{KES9x)51{X)Pb~WD<)SVG`l_Ik|U*rfmxRG4$xO{}_@jXJ_?zk=Jq5bYE zc`dm-arqF{d*U{s(PmGTty-h~o+{ZvE-fw(P`wtn`7>#=Rwd`r094z_m08h=FnAGF zW5m|rO{p5A4TK%98Y7mB_kwDSY{zC)jgjpm4DlS~zN0``5HZ%Y13MKvM4=pvgO(kQ z2VwqVvMEP_>;RiW4P0*Or+4 zKT37qso@n43KUm+&|QkNS!aP7P0UHsM>!hxLG8fm_S^wX8TB&8Q<^eUv05~$1kBS4Yhc)Bf6pyRqy`*=2x56mo34XBp- z0~Iqyg5w>GD@q+n)CIN6c|99Ie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vw#5rVUV!TKB4Cm=TBvk#F6U+hLyL<-13I6wls{gA5 z-!-4EyXG@gom6C@pN3XSjS7basbH8!?ZW~xkuE{I2yL1*Ad{%g8l+aMMt?v{rYW`{ zRoFDzV++Wk^gFcQpw;LBX{8Q5NN?*JY4(8BsoEZ-*>;T%Kyy&6BS1TrIGFmlFg;jv#x*~K}Vq-f#yyL$Whdg5~MXL8l8nUhSF1m zG&WVE&8Y#IPMy%sKr0>|kQuabc&}^^HK+ATYB5_vts_d!p{t{>M#Yt8hO_r@CRG&- zA**|w{m+|W;)ZeHCZo$(H_dZT(77TX0`t0*fhU2>!Gmd^yQrA!4~Gk%&}utzy;gvy zfO$*s-o)vw_B-!g-ruv`_<(j$jeAVeSV&{Qydk-$oV3j2Ys3|y#^ELq4zL}JYlp80 zzIK#fTuUMu%q7cy**{KuHIDzwwg}(qkNw>0Ffq!jSC-4ZUI#3+F56~0 zZK2D#Hq#{w)#uuzpkvv(Bk~-0tLNl}?>p*t^bN|Q=W=vMy(wb#k2%19&eV2yo|PvpR;-NN5zFE$u-DSO6~$ZZUtX~puIjE z6{VFz)UH~wVCAY>aeP9_{@%%R5B`7y7Tcle$V(sI_`GVy?rYF-4mADv^!mC%3#WA7 ofR6pyv}@_ymlsWb(Ai@+Tvkq91@DI5FDx[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?.+?)#L(?\d+)[-~]?L?(?\d*)/i; const TWITTER_TWEET_URL_REGEX = /https:\/\/(?:www\.)?(?:twitter|x)\.com\/(?[a-zA-Z0-9-_]+)\/status\/(?\d+)/i; +const BUN_REPORT_URL_REGEX = /(https:\/\/bun\.report\/\d+\.\d+(\.\d+)?\/\S+)/g; export default { event: "messageCreate", @@ -21,6 +27,7 @@ export default { function handleOthers(message: Message): void { handleGithubLink(message); + handleBunReportLink(message); //handleTwitterLink(message); // discord finnaly has embeds } @@ -106,6 +113,16 @@ async function handleGithubLink(message: Message): Promise { }); } +async function handleBunReportLink(message: Message): Promise { + if (!message.content) return; + + const match = message.content.match(BUN_REPORT_URL_REGEX); + if (!match?.[0]) return; + + const data = await getBunReportDetailsInMarkdown(match[0]); + message.reply(data); +} + function handleTwitterLink(message: Message): void { if (!message.content) return; diff --git a/src/util.ts b/src/util.ts index 97fc010..c2f0a77 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,6 @@ import { GuildMember } from "@lilybird/transformers"; import { BUN_EMOJIS } from "./constants.ts"; +import { parse, formatMarkdown } from "bun-tracestrings"; export function safeSlice>( input: T, @@ -46,3 +47,26 @@ export function getRandomBunEmoji() { export function sliceIfStartsWith(input: string, startsWith: string) { return input.startsWith(startsWith) ? input.slice(startsWith.length) : input; } + +export async function getBunReportDetailsInMarkdown( + url: string +): Promise { + const parsed = await parse(url); + + const res = await fetch("https://bun.report/remap", { + method: "POST", + body: url, + }); + + if (!res.ok) { + return `Failed to get details from bun.report: ${res.statusText}`; + } + + const json = await res.json(); + console.log(json); + + return formatMarkdown({ + ...parsed, + ...json, + }); +}