Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions commands/preview-group/PreviewCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/preview-group/helpers/codeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Loading