Skip to content

DrSnuggly/comic-bot

Repository files navigation

Comic bot

codecov Checks

A Discord bot to post webcomic updates that runs on Cloudflare Workers (including the free tier).

Deploy

If you don't already have a Cloudflare account, you can sign up for one for free.

  1. Log into Cloudflare.

  2. Click the button below on this page:

    Deploy to Cloudflare

  3. Follow the remaining instructions provided by Cloudflare.

Configure

An example JSON file can be found here: tests/e2e/comics.json.

  1. Using your favourite text editor, build a JSON file with the following format:
    [
      {
        "name": "Oglaf!",
        "feedUrl": "https://www.oglaf.com/feeds/rss/",
        "webhooks": [
          // Test webhook from Discord's documentation.
          "https://discord.com/api/webhooks/223704706495545344/3d89bb7572e0fb30d8128367b3b1b44fecd1726de135cbe28a41f8b2f777c372ba2939e72279b94526ff5d1bd4358d65cf11"
        ],
        "imageSelector": "img#strip"
      },
      // Additional comic configurations, if desired.
      {
        // Another comic configuration.
      },
      {
        // Another comic configuration.
      }
    ]
    • name: the name of the comic.
    • feedUrl: the URL of the comic feed (e.g. an RSS feed).
    • webhooks: a list of Discord webhook URLs to send updates to.
    • imageSelector: the CSS selector for the comic image.
    • altTextSelector (optional): if alt text isn't present on the comic img element, you can provide the CSS selector for any alt text.
    • nextPageSelector (optional): the CSS selector for the link to the next comic page — this allows all pages from a multipage update to be retrieved.
  2. Remove all comments and unnecessary trailing commas:
    • Before:
      {
        "name": "Oglaf!",
        "feedUrl": "https://www.oglaf.com/feeds/rss/",
        "webhooks": [
          "https://discord.com/api/webhooks/223704706495545344/3d89bb7572e0fb30d8128367b3b1b44fecd1726de135cbe28a41f8b2f777c372ba2939e72279b94526ff5d1bd4358d65cf11",
          // 👆 the above line has a trailing comma that should be removed.
        ],
        "imageSelector": "img#strip",
        // 👆 the above line has a trailing comma that should be removed.
      }
    • After:
      {
        "name": "Oglaf!",
        "feedUrl": "https://www.oglaf.com/feeds/rss/",
        "webhooks": [
          "https://discord.com/api/webhooks/223704706495545344/3d89bb7572e0fb30d8128367b3b1b44fecd1726de135cbe28a41f8b2f777c372ba2939e72279b94526ff5d1bd4358d65cf11"
        ],
        "imageSelector": "img#strip"
      }
  3. In the Cloudflare KV storage attached to this worker, add a new entry with the following:
    • Key: index
    • Value: use the value from step 2.

Local development

  1. Install pnpm.
    • If Node.js also needs to be installed, you can use the following command:
      pnpm env use --global lts
  2. Install dependencies with:
    pnpm install --frozen-lockfile

End-to-end tests

  1. Create a .env file in the root of your project with the following info:
    WEBHOOK="<your Discord channel's webhook URL>"
  2. Run the following command:
    pnpm run tests:e2e

Reference

About

Send webcomic updates to Discord channels.

Resources

License

Stars

Watchers

Forks

Contributors