mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-10 01:08:07 +01:00
feat: own escape for bun.report urls
This commit is contained in:
parent
c858d66a3f
commit
c72e4c5917
1 changed files with 16 additions and 2 deletions
18
src/util.ts
18
src/util.ts
|
@ -2,6 +2,8 @@ import { GuildMember } from "@lilybird/transformers";
|
|||
import { BUN_EMOJIS } from "./constants.ts";
|
||||
import { parse, formatMarkdown } from "bun-tracestrings";
|
||||
|
||||
const URL_REGEX = /\(\s*(https?:\/\/[^\s\[\]]+)\s*\)/gi;
|
||||
|
||||
export function safeSlice<T extends string | Array<any>>(
|
||||
input: T,
|
||||
length: number
|
||||
|
@ -63,10 +65,22 @@ export async function getBunReportDetailsInMarkdown(
|
|||
}
|
||||
|
||||
const json = await res.json();
|
||||
console.log(json);
|
||||
|
||||
return formatMarkdown({
|
||||
let content = formatMarkdown({
|
||||
...parsed,
|
||||
...json,
|
||||
});
|
||||
|
||||
for (const match of content.matchAll(URL_REGEX)) {
|
||||
let url = match[1];
|
||||
if (url.endsWith(")")) {
|
||||
url = url.slice(0, -1);
|
||||
}
|
||||
|
||||
if (!url.startsWith("<")) {
|
||||
content = content.replace(url, `<${url}>`);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue