Skip to content

[New Command]: xkcd Command for XKCD Comics #2

@lcox74

Description

@lcox74

Summary

We propose adding an /xkcd [id] command to the bot. This command displays an XKCD comic in Discord. If an id is provided, it fetches that specific comic from https://xkcd.com/<id>. If not, it retrieves a random comic from https://c.xkcd.com/random/comic. The HTTP response is parsed using regex to extract the comic’s number, title, description, and img URL.

Problem / Motivation

  • Developer Culture:
    As developers, integrating XKCD into our Discord bots isn’t just a feature—it’s a way of life. XKCD has been a staple in our communities on other servers and it represents a shared joke, tradition, and inspiration among us.

  • Enhanced Engagement:
    Bringing this feature to our bot reinforces our community's identity and adds a fun, light-hearted element to our interactions.

  • Future-Proofing:
    While our current Lua bindings (Driftwood) do not support embedded messages, the design is planned for future support. We like the embed style for its clean and attractive display; implementing this command now lays the groundwork for a smoother transition when embeds become available.

Command/Application Details

  • Name:
    /xkcd

  • Invocation / Trigger:

    • /xkcd — Fetches a random XKCD comic.
    • /xkcd 123 — Fetches the specific XKCD comic with the ID 123.

Purpose & Functionality:

  • Data Retrieval:
    Based on the presence of an id, the command makes an HTTP GET request to either https://xkcd.com/<id> or https://c.xkcd.com/random/comic.

  • Parsing Logic:
    The response is regex-parsed to extract the comic's details:

    • Number: The comic’s ID.
    • Title: The title of the comic.
    • Description: The alt-text or description.
    • Image URL: The URL for the comic image.

    Refer to our prior Python implementation for this logic.

  • Display:
    The final output will be formatted as an embedded message. The embed design includes:

    • Title: Combined comic number and title.
    • Description: The comic’s alt-text/description.
    • Image: The comic image.
    • URL: A link to the comic on XKCD.

Note: Although Driftwood currently doesn’t support embedded messages, this layout is planned and will be implemented once embedded support is available.

  • Parameters & Options:

    • id (optional, type: number): Specifies the comic to fetch. If omitted, the command returns a random XKCD comic.
  • Permissions & Role Restrictions:

    • Available to all users—no additional permissions required.

Testing & Validation

Use busted and build some logical unit tests.

  • Comic Parsing: Ensure that the comics are parsed correctly, have some dummy HTML responses and ensure that it can get the number, title, description and image_url.
  • Invalid IDs: Validate error messaging when an invalid ID is provided by the user.
  • HTTP Failures: Simulate network or HTTP errors to check robust error handling.

Metadata

Metadata

Assignees

Labels

command-requestThis issue is requesting a new command to be added to the botenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions