Skip to content

Instantly share code, notes, and snippets.

@matthewjohnston4
Last active May 26, 2021 10:36
Show Gist options
  • Save matthewjohnston4/3b75062d7772ec4a05be938e80bcffd5 to your computer and use it in GitHub Desktop.
Save matthewjohnston4/3b75062d7772ec4a05be938e80bcffd5 to your computer and use it in GitHub Desktop.
Nightbot shoutout command with customised per-user messages

This two-piece code will allow you to setup a Nightbot shoutout command which can be customised to allow per-user shoutout messages, with a fallback default message.

Because Nightbot commands have a character limit, you won't get far with including the custom messages directly in your command string.

The solution is to use Nightbots urlfetch variable to fetch a JSON object filled with custom messages from somewhere on the web — here I'm placing it in a Github Gist (which works fine, but a bit slowly). You could put it somewhere on a plain old HTTP page served anywhere on the internet.

How to use

  1. Clone this JSON: https://gist.github.com/matthewjohnston4/ef62107655e471384fe027e0738a5c05 and store it where you want.
  2. Customise the JSON object to add or remove any "username": "shoutout message" combinations you want (don't forget those trailing commas).
  3. Note the URL where you placed the file — if you're using a Gist, you should click on the RAW button and use that URL.
  4. Copy and paste the Nightbot code from here https://gist.github.com/matthewjohnston4/f79505398a512015f055c59398432951 into wherever you configure Nightbot usually. Make sure you update the urlfetch URL being used to the URL in step 3 above.
  5. You should be done!

If you want to update an existing shoutout command, change the code in step 4 from !commands add to !commands edit and that should work.

## Some notes

The urlfetch part of Nightbot isn't very efficient, and will sometimes timeout — that's why it might be faster to serve the JSON from a real webpage rather than via Github's Gist system.

I think Gist URLs change any time you update them, which means you'll also have to update your Nightbot command each time. Another reason to serve it from somewhere permanent and fully under your control.

The default message is defined in the Nightbot command code in Step 4 — customise it there — you can use $(query) anywhere you need to include the username of the shoutoutee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment