From 94e476e2175c301b5f8f96078ec83e22806617cd Mon Sep 17 00:00:00 2001 From: Zach Goodson Date: Sun, 7 Dec 2025 02:25:40 -0600 Subject: [PATCH 1/2] Fix <> __ Preventing Message Code Previews --- commands/preview-group/PreviewCommands.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/commands/preview-group/PreviewCommands.cs b/commands/preview-group/PreviewCommands.cs index 5bf1586..c99fe7e 100644 --- a/commands/preview-group/PreviewCommands.cs +++ b/commands/preview-group/PreviewCommands.cs @@ -68,21 +68,19 @@ public async Task CodePreview([Summary("link", "A GitHub Link to specific lines [MessageCommand("Preview Code")] public async Task PreviewCodeMessage(IMessage message) { - string pattern = @"(https?://\S+)|(www\.\S+)"; + string pattern = @"[_*<]*(https?:\/\/[^\s>_*]+)[_* >]*"; // Create a Regex object with the pattern Regex regex = new(pattern); - // Find all matches in the input string - MatchCollection matches = regex.Matches(message.Content); - - if (matches.Count == 0) + Match match = regex.Match(message.Content); + if (!match.Success) { await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/`.\n- If you preview a link with no line specificaions, Bob will automatically show as many lines as possible from the start.\n- For line specifications, put `#L15` or `#L15-L18` at the end of the link to the file. (see below).\n- If you are sharing a single line it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15`\n- If you are sharing multiple lines it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15-L18`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } else { - string link = matches[0].Value; + string link = match.Groups[1].Value; await CodeReader.Respond(Context.Interaction, link); } From abab010ea933df6c332aceaff894e3cdc4d97700 Mon Sep 17 00:00:00 2001 From: Zach Goodson Date: Sun, 7 Dec 2025 02:32:45 -0600 Subject: [PATCH 2/2] Add Public Repo Disclaimer to GitHub Previews --- commands/preview-group/PreviewCommands.cs | 8 ++++---- commands/preview-group/helpers/codeReader.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/preview-group/PreviewCommands.cs b/commands/preview-group/PreviewCommands.cs index c99fe7e..0b01d52 100644 --- a/commands/preview-group/PreviewCommands.cs +++ b/commands/preview-group/PreviewCommands.cs @@ -47,7 +47,7 @@ await RespondAsync( text: "❌ Your link is not valid. Here are some things to know: \n" + "- The link must start with `https://github.com/`.\n" + - "- The link must point to a repository, e.g. `https://github.com/bob-el-bot/BobTheBot`.\n" + + "- The link must point to a ***public*** repository, e.g. `https://github.com/bob-el-bot/BobTheBot`.\n" + "- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } @@ -76,7 +76,7 @@ public async Task PreviewCodeMessage(IMessage message) Match match = regex.Match(message.Content); if (!match.Success) { - await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/`.\n- If you preview a link with no line specificaions, Bob will automatically show as many lines as possible from the start.\n- For line specifications, put `#L15` or `#L15-L18` at the end of the link to the file. (see below).\n- If you are sharing a single line it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15`\n- If you are sharing multiple lines it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15-L18`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); + await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/`.\n- The link must be for a ***public*** repository.\n- If you preview a link with no line specificaions, Bob will automatically show as many lines as possible from the start.\n- For line specifications, put `#L15` or `#L15-L18` at the end of the link to the file. (see below).\n- If you are sharing a single line it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15`\n- If you are sharing multiple lines it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15-L18`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } else { @@ -147,7 +147,7 @@ public async Task PullRequestPreview([Summary("link", "A GitHub Link to a specif } catch { - await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/` or `github.com/`.\n- Your link must be to a pull request.\n- A valid link could look like this: `https://github.com/bob-el-bot/BobTheBot/pull/149`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); + await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/` or `github.com/`.\n- The link must be for a ***public*** repository.\n- Your link must be to a pull request.\n- A valid link could look like this: `https://github.com/bob-el-bot/BobTheBot/pull/149`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } } @@ -176,7 +176,7 @@ public async Task IssuePreview([Summary("link", "A GitHub Link to a specific iss } catch { - await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/` or `github.com/`.\n- Your link must be to an issue.\n- A valid link could look like this: `https://github.com/bob-el-bot/BobTheBot/issues/153`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); + await RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/` or `github.com/`.\n- The link must be for a ***public*** repository.\n- Your link must be to an issue.\n- A valid link could look like this: `https://github.com/bob-el-bot/BobTheBot/issues/153`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } } diff --git a/commands/preview-group/helpers/codeReader.cs b/commands/preview-group/helpers/codeReader.cs index 76cd50a..9fc52fa 100644 --- a/commands/preview-group/helpers/codeReader.cs +++ b/commands/preview-group/helpers/codeReader.cs @@ -63,7 +63,7 @@ public static async Task Respond(SocketInteraction interaction, string link) } catch { - await interaction.RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/`.\n- If you preview a link with no line specificaions, Bob will automatically show as many lines as possible from the start.\n- For line specifications, put `#L15` or `#L15-L18` at the end of the link to the file. (see below).\n- If you are sharing a single line it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15`\n- If you are sharing multiple lines it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15-L18`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); + await interaction.RespondAsync(text: "❌ Your link is not valid. Here are some things to know: \n- Your link needs to start with `https://github.com/`.\n- The link must be for a ***public*** repository.\n- If you preview a link with no line specifications, Bob will automatically show as many lines as possible from the start.\n- For line specifications, put `#L15` or `#L15-L18` at the end of the link to the file. (see below).\n- If you are sharing a single line it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15`\n- If you are sharing multiple lines it could look like this: `https://github.com/bob-el-bot/website/blob/main/index.html#L15-L18`\n- If you think this is a mistake, let us know here: [Bob's Official Server](https://discord.gg/HvGMRZD8jQ)", ephemeral: true); } }