Add file name with line numbers when sending code block message. (#30)

This commit is contained in:
Aritra Karak 2023-10-13 01:03:33 +05:30 committed by GitHub
parent 8ff1bdaee3
commit b8f0721eb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -3,7 +3,7 @@ import { defineListener } from "../loaders/listeners.ts";
import { MESSAGE_PREFIX, BUN_ONLY_CHANNEL_ID } from "../constants.ts"; import { MESSAGE_PREFIX, BUN_ONLY_CHANNEL_ID } from "../constants.ts";
import { COMMANDS } from "../loaders/commands.ts"; import { COMMANDS } from "../loaders/commands.ts";
import { MessageCommandContext } from "../structs/context/CommandContext.ts"; import { MessageCommandContext } from "../structs/context/CommandContext.ts";
import { extname } from "node:path"; import { extname, basename } from "node:path";
import { safeSlice } from "../util.ts"; import { safeSlice } from "../util.ts";
const GITHUB_LINE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?<repo>[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?<path>.+?)#L(?<first_line_number>\d+)[-~]?L?(?<second_line_number>\d*)/i; const GITHUB_LINE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?<repo>[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?<path>.+?)#L(?<first_line_number>\d+)[-~]?L?(?<second_line_number>\d*)/i;
@ -90,7 +90,7 @@ async function handleGithubLink(message: Message) {
if (extension === "zig") extension = "rs"; if (extension === "zig") extension = "rs";
message.reply({ message.reply({
content: `\`\`\`${extension}\n${safeSlice(text, 2000 - 6 - extension.length)}\n\`\`\``, content: `***${basename(path)}*** — *(L${firstLineNumber}${secondLineNumber ? `-L${secondLineNumber}` : ""})*\n\`\`\`${extension}\n${safeSlice(text, 2000 - 6 - extension.length)}\n\`\`\``,
components: [ components: [
new ActionRowBuilder<ButtonBuilder>() new ActionRowBuilder<ButtonBuilder>()
.setComponents( .setComponents(