https://gitlab.com/btreecat/xkcd-for-slack
1.5K
A FOSS service that you can self-host, providing /xkcd commands in Slack.
/commands)pip install -r requirements.txtYou will need a SLACK_BOT_TOKEN and a SLACK_SIGNING_SECRET which you can get when you create a slack app.
You will need a Google Programmable search setup, and the associated SEARCH_ENGINE_ID and CUST_SEARCH_KEY.
Under the Advanced option for the Programmable Search Engine it is recommended to add the following exclusions:
| URL | Setting |
|---|---|
| 3d.xkcd.com | Exclude all |
| m.xkcd.com | Exclude all |
| store.xkcd.com | Exclude all |
| wiki.xkcd.com | Exclude all |
| what-if.xkcd.com | Exclude all |
| blog.xkcd.com | Exclude all |
| xkcd.com/random/comic/ | Exclude just |
| xkcd.com/about/ | Exclude just |
| xkcd.com/archive/ | Exclude just |
| xkcd.com/ | Exclude just |
This service needs to be hosted at a publicly reachable location, so any machine with a public IP will work.
There is an included Dockerfile for building the image and a docker-compose.yml for building and running the service.
$ docker-compose up --build
Prebuilt Docker container: btreecat/xkcd-4-slack
| Key | Description |
|---|---|
SLACK_BOT_TOKEN | Token from Slack for your bot authentication ( has '-' characters) |
SLACK_SIGNING_SECRET | Token from Slack for your bot authentication |
CUST_SEARCH_KEY | Token from Google for your Custom Search Engine API Access |
SEARCH_ENGINE_ID | ID from Google that matches your Programmable Search Engine |
The bot responds to /xkcd commands or to @xkcd-4-slack mentions (but only with helper text in a mention).
Given a comic ID number, fetch that specific comic.
/xkcd 386
Pass the random flag (-r or --random) to get a random comic.
/xkcd -r
Pass the latest flag (-l or --latest) to get the latest comic.
/xkcd -l
Uses DuckDuckGo to site search xkcd.com for the right comic. By default this will pick the first valid
result. Using the -r or --random flag after your search terms will force the choice to be random rather
than the first one.
/xkcd exploit
or
/xkcd sys admin -r
Just like Giphy, this plugin will preview the image only to the person running the /xkcd command.
From the preview, you can choose to Approve or Reject the image selected.
When searching, there is also the option to select Spin which will re-run the search (stateless), but with the
-r random flag added on to force a random choice from the results list rather than just picking the first one.
Using doctest for testing.
From the repo root:
$ python -m doctest -v src/utils.py
MIT
Mostly complete. Bug fixes as needed.
Content type
Image
Digest
sha256:ddb4696e7…
Size
85.3 MB
Last updated
about 4 years ago
docker pull btreecat/xkcd-4-slack