mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 14:41:05 +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 { BUN_EMOJIS } from "./constants.ts";
|
||||||
import { parse, formatMarkdown } from "bun-tracestrings";
|
import { parse, formatMarkdown } from "bun-tracestrings";
|
||||||
|
|
||||||
|
const URL_REGEX = /\(\s*(https?:\/\/[^\s\[\]]+)\s*\)/gi;
|
||||||
|
|
||||||
export function safeSlice<T extends string | Array<any>>(
|
export function safeSlice<T extends string | Array<any>>(
|
||||||
input: T,
|
input: T,
|
||||||
length: number
|
length: number
|
||||||
|
@ -63,10 +65,22 @@ export async function getBunReportDetailsInMarkdown(
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
console.log(json);
|
|
||||||
|
|
||||||
return formatMarkdown({
|
let content = formatMarkdown({
|
||||||
...parsed,
|
...parsed,
|
||||||
...json,
|
...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