Skip to content

feat: add ;man command#29

Merged
calebephrem merged 2 commits into
open-devhub:mainfrom
calebephrem:main
Jul 2, 2026
Merged

feat: add ;man command#29
calebephrem merged 2 commits into
open-devhub:mainfrom
calebephrem:main

Conversation

@calebephrem

Copy link
Copy Markdown
Member

No description provided.

@devhub-bot devhub-bot Bot added feat New feature fix Bug fix labels Jul 2, 2026
@beetle-ai

beetle-ai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR introduces two key improvements to the Discord bot: code refactoring for better maintainability and a new documentation feature. The first commit centralizes the changelog parsing logic by extracting duplicate code into a shared utility module, while also fixing a formatting issue with double newlines. The second commit adds a new man command that allows users to search and view Unix/Linux manual pages directly from Discord, complete with formatted embeds and links to full documentation.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/utils/parseChangelog.ts Added +33/-0 New centralized utility module for parsing changelog content into version sections. Extracts duplicate logic from command and interaction handlers, and includes fix for double newline characters using .replace(/\r?\n\r?\n/g, "\n")
src/commands/meta/changelog.ts
src/interactions/changelog.ts
Modified +2/-69 Refactored to import and use the centralized parseChangelog utility instead of maintaining duplicate parsing logic. Removed 69 lines of redundant code across both files
src/commands/docs/man.ts Added +55/-0 New command implementation for searching Unix/Linux manual pages. Provides formatted Discord embeds with descriptions and clickable buttons linking to full documentation on man.archlinux.org
src/utils/man.ts Added +94/-0 Core utility module for fetching and parsing manual pages from Arch Linux man page repository. Handles input validation, HTTP requests, text parsing, section extraction, and structured data return
CHANGELOG.md Modified +1/-0 Updated to document the new man command feature in the changelog

Total Changes: 5 files changed, +185 additions, -69 deletions

🗺️ Walkthrough:

sequenceDiagram
participant User
participant Discord
participant ManCommand as "man.ts Command"
participant ManUtil as "man() Utility"
participant ArchLinux as "man.archlinux.org"
User->>Discord: ;man ls
Discord->>ManCommand: Execute command
ManCommand->>ManUtil: man("ls")
ManUtil->>ManUtil: Validate term (alphanumeric check)
ManUtil->>ArchLinux: GET /man/ls.txt
ArchLinux-->>ManUtil: Raw man page text
ManUtil->>ManUtil: Parse sections (NAME, SYNOPSIS, etc.)
ManUtil->>ManUtil: Extract title & description
ManUtil-->>ManCommand: Return ManPage object
ManCommand->>ManCommand: Build Discord Embed
ManCommand->>ManCommand: Create "Read Full" button
ManCommand-->>Discord: Reply with embed + button
Discord-->>User: Display formatted man page
Note over User,ArchLinux: User can click button to view full documentation
Loading

🎯 Key Changes:

  • Code Deduplication: Eliminated 69 lines of duplicate changelog parsing logic by centralizing it into src/utils/parseChangelog.ts, improving maintainability and reducing potential for inconsistencies
  • Formatting Fix: Resolved double newline issue in changelog content by adding .replace(/\r?\n\r?\n/g, "\n") to normalize line breaks
  • New Documentation Feature: Implemented ;man command (with manual alias) enabling users to search Unix/Linux manual pages directly from Discord
  • Rich Embed Presentation: Man pages are displayed with formatted Discord embeds including title, description, and a clickable button linking to the full documentation
  • Robust Parsing: The man page utility extracts and structures standard sections (NAME, SYNOPSIS, DESCRIPTION, OPTIONS, etc.) from raw text format
  • Input Validation: Includes security measures with regex validation (/^[a-zA-Z0-9._+-]+$/) to prevent injection attacks

📊 Impact Assessment:

  • Security: ✅ Positive - The man command includes input validation to prevent malicious queries. The regex pattern restricts input to safe alphanumeric characters and common punctuation. External API calls use proper URL encoding. No user input is directly executed or evaluated.
  • Performance: ✅ Neutral to Positive - The refactoring reduces code duplication, slightly improving memory footprint. The new man command makes external HTTP requests which could introduce latency, but includes proper error handling and timeouts. The parsing logic is efficient with single-pass processing.
  • Maintainability: ✅✅ Highly Positive - This is the strongest improvement. Centralizing the changelog parser eliminates code duplication across two files, making future updates easier and reducing bug surface area. The new utility modules (parseChangelog.ts and man.ts) follow single-responsibility principle with clear interfaces and TypeScript types. Code is well-structured and self-documenting.
  • Testing: ⚠️ Needs Attention - No test files are included in this PR. The new man command should have unit tests covering: input validation edge cases, parsing logic for various man page formats, error handling for network failures, and invalid search terms. The centralized changelog parser should also have tests to ensure consistent behavior across both usage locations.
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

@devhub-bot

devhub-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Note

Linting checks passed successfully 🎉

All formatting and code quality checks are clean.

You're good to merge 🚀

Comment thread src/utils/man.ts

const url = `https://man.archlinux.org/man/${encodeURIComponent(term)}.txt`;

const res = await fetch(url);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fetch call has no timeout or error handling, which can cause the Discord bot to hang indefinitely if the archlinux.org server is slow or unresponsive. This could lead to resource exhaustion and bot unresponsiveness.

Confidence: 5/5

Suggested Fix
Suggested change
const res = await fetch(url);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
try {
const res = await fetch(url, { signal: controller.signal });
clearTimeout(timeoutId);
if (!res.ok) return null;
} catch (error) {
clearTimeout(timeoutId);
if (error.name === 'AbortError') {
throw new Error("Man page request timed out.");
}
throw new Error("Failed to fetch man page.");
}

Add a 5-second timeout using AbortController to prevent indefinite hangs. Wrap the fetch in try-catch to handle network errors gracefully. This prevents the bot from becoming unresponsive when the external API is slow or down.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/utils/man.ts around line 17, the fetch call has no timeout or error handling which can cause the Discord bot to hang indefinitely if archlinux.org is slow or unresponsive; add an AbortController with a 5-second timeout and wrap the fetch in a try-catch block to handle network errors and timeouts gracefully, throwing appropriate error messages for timeout and fetch failures.

@calebephrem calebephrem merged commit 132a574 into open-devhub:main Jul 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant