codePreviews: ignore markdown, limit full to 20 line files, fix

reactions (hopefully)
This commit is contained in:
Cynthia Foxwell 2023-08-03 20:24:01 -06:00
parent e212bade7b
commit 932d24d6a4

View file

@ -36,6 +36,8 @@ async function processFile(link) {
? "" ? ""
: fileName.substring(fileName.lastIndexOf(".") + 1); : fileName.substring(fileName.lastIndexOf(".") + 1);
if (fileType == "md") return "";
const lineStr = link.match(/#L\d+(-L?\d+)?/)?.[0]; const lineStr = link.match(/#L\d+(-L?\d+)?/)?.[0];
let startLine, endLine; let startLine, endLine;
let entireFile = false; let entireFile = false;
@ -60,21 +62,15 @@ async function processFile(link) {
? "Line " + startLine ? "Line " + startLine
: "Lines " + startLine + "-" + endLine; : "Lines " + startLine + "-" + endLine;
if (entireFile && lines.length > 20) return "";
const targetLines = ( const targetLines = (
entireFile entireFile ? lines : lines.slice(startLine - 1, endLine)
? lines.length > 30
? lines.slice(0, 30)
: lines
: lines.slice(startLine - 1, endLine)
).join("\n"); ).join("\n");
return `**${fileName}: **${whichLines}\n\`\`\`${fileType}\n${unindent( return `**${fileName}: **${whichLines}\n\`\`\`${fileType}\n${unindent(
targetLines targetLines
)}${ )}\n\`\`\``;
entireFile && lines.length > 30
? `\n... (${lines.length - 30} lines left)`
: ""
}\n\`\`\``;
} }
events.add("messageCreate", "codePreviews", async function (msg) { events.add("messageCreate", "codePreviews", async function (msg) {
@ -168,7 +164,7 @@ events.add(
const ref = await channel.getMessage(msg.messageReference.messageID); const ref = await channel.getMessage(msg.messageReference.messageID);
if (!ref) return; if (!ref) return;
if ( if (
ref.author.id != reactor.id || ref.author.id != reactor.id &&
!channel.permissionsOf(reactor.id).has("manageMessages") !channel.permissionsOf(reactor.id).has("manageMessages")
) )
return; return;