Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.

Github line previews cog + tests - #188

Open
Xarlos89 wants to merge 1 commit into
masterfrom
feature/github-line-preview
Open

Xarlos89 wants to merge 1 commit into
masterfrom
feature/github-line-preview

Conversation

@Xarlos89

Copy link
Copy Markdown
Collaborator

Description of your PR

Adds a cog that replies with a code preview when someone posts a GitHub link to specific lines.

Describe your changes

New GithubLines cog that watches guild messages for GitHub line links and replies with those lines as a syntax-highlighted code block.

Added

  • src/bot/cogs/features/github_lines.py:

    • Handles single lines, ranges, reversed ranges (#L9-L3), branches containing /, and query strings like ?plain=1
    • Previews at most 3 links per message
    • Fetches files from raw.githubusercontent.com and skips private or broken links without replying
    • Escapes backticks inside the file and cuts off the reply at Discord's 2000-character limit
  • tests/test_github_lines.py: unit tests for link parsing, snippet formatting, backtick escaping and truncation

Issue link

No issue. feature comes from a suggestion

Checklist

  • Does an issue of this PR exist and have you linked it?
  • Have your ran pre-commit over your PR?
  • Was this PR branched off from master?
  • Is this PR merging to master?

@Xarlos89

Xarlos89 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator Author
image

if start > end:
temp = start
start = end
end = temp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

start, end = end, start

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants