-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 ID123.
Purpose & Functionality:
-
Data Retrieval:
Based on the presence of anid, the command makes an HTTP GET request to eitherhttps://xkcd.com/<id>orhttps://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,descriptionandimage_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.