diff --git a/commands/preview-group/PreviewCommands.cs b/commands/preview-group/PreviewCommands.cs index 5bf1586..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); } @@ -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); + 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 { - string link = matches[0].Value; + string link = match.Groups[1].Value; await CodeReader.Respond(Context.Interaction, link); } @@ -149,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); } } @@ -178,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); } }