Jake is a basic node.js implementation of the slack api to make a slack bot. He is hosted on a heroku instance that auto-builds off the latest push to the main branch. Currently on the dev branch he is being re-worked to use express to listen to more diverse HTTP requests. Ideally this will allow him to support more features, like twitch/dndbeyond access and native slash commands.
Half of the existence of our slack group is around Dungeons and Dragons, and there are not many great slack apps built for DnD. Specifically, we wanted one that could be used to perform look up of the source material in slack to settle disputes, and provide quick reference.
Furthermore, slack free tier is very restricing. We had most integrations accounted for, and I had to remove one not totally necessary integration to fit jake in. Any new features needed from a bot that couldn't be put elsewhere got pushed into Jake. Slack free tier also has file limits that get very complicated to sort out. The most common upload and offender of file sharing policies is images. That led to building the auto re-upload to imgur function discussed below.
All of jake's user functions are called by prepending with a '$' right before so that he can filter only messages that matter. At some point with the express rework we will implement traditional slash command calls so as to make Jake more compliant and worthy of his khakis
- spell:
- roll:
- sarcasm:
- clap:
- Mentions (@Jake):
Using the dnd5eapi.co, Jake looks up a DnD 5e spell listed in the SRD. The SRD is limited so there are some PHB spells missing, and does not inlcude mostly everything in the expansion books. The command will look to correct capitlization as the 5e API matches names exactly. Most every preposition used in spells, like "dispel evil and good" below, will work; however, there is no globbing, so dispel good and evil will return nothing:
Jake also generates the link to the appropiate spell page on dndbeyond as well. This helps for anymore advanced reference, if one is looking for a specific reagent, to add to their character sheet, or get specifics on an entity used in the description.
Rolls standard XdY dice. The full command can take multiple dice stringed together with commas, include a flat +/- modifier to add to the total roll, and include a number of Advantage or Disadvtange dice. Jake will provide a sum of all the dice roll per different sides of dice requested:
As you can see if a user does not specify an amount of dice to be rolled it will default to rolling a singular dice. Furthermore, Jake will sum up the total for all dice specified of a single roll. This comes in handing when adding modifiers in Dnd. Below is an example:
Here we can see Jake both rolling multiple rolls and adding, or subtracting, a modifier from the total sum. Jake will not modify the rolls directly as it helps keep the rolling logic faster and makes it easier for users to implement rolls. A modifier can be any integer prepended with either a plus or minus sign. Note that the regex used requires no spaces between the modifier and the dice roll. Lastly we have advantage and disadvantage. The Adv/Dis essentially marks the N-most high or low dice. For instance, a stat roll, which is 4d6 and drop the lowest, can be done quickly as D4d6 so the the final value for the stat is the sum minus the bolded lowest die. For traditional advantage and disadvantage, where one picks the higher or lower of two d20, the roll would be either A2d20 or D2d20. Similar to the number of dice the user doesn't need to enter a number for a single advantage or disadvantage:
As mentioned, a number of advantage or disadvantage can be specified. The use case for this is slim but it is nice to not the max or min graphically without having to look. It could potentially have some advantages in DnD but mostly for edge cases:
Takes the message given by the user and snake case every alpha characer within it. Pretty much, it's a shorthand for the sponge-gar meme. It's not necessarily a high function utility but it can actually be somewhat helpful for expression. Once the user types out the command Jake creates the alternate capital string, and posts an message appearing as the other user with the APP badge, and deletes the original post. At some pending update we will get users tokens to send messages on their behalf directly but this is a very functional workaround for now:
This adds clap emojis in the spaces of a text string. This does the same as the sarcasm command for sending the message. Once the text is created it posts the message in the guise of the user, and deletes the original message. Both of these commands are built this way so as to not clutter slack with too many extra posts
This one is less of a function but is useful to check status. If a user mentions Jake in post he responds back with a hello saying their display or username:
- Imgur Re-Upload: Normally when we want to share files with eachother, images especially, we upload the files directly to slack: However, on the free tier of slack with tens of users this become a lot of files very quick. Additionally, if users leave and they haven't cleared their files it's quite difficult to clean up. Jake has an automatic function that listens for when users upload files. If they are identified as a MIME/image type file, Jake downloads it, uploads it to imgur, posts a link to the imgur image and deletes the original: Jake will only delete the image if both the imgur upload and the link post execute succesfully. If something goes wrong it fails silently to the logs and not to the user. Jake currently can only listen in channels he's in. In a pending update we will get user permissions and more that will enable him to travel more across channels and access more files. Most importantly of all, he also posts a delete link to the imgur photo only visible to the poster. In case the image is uploaded in error or something to that effect it can be taken down from imgur going forward and mitigates any damage that could be caused. Ideally we would also use the sharePublicURL call. This would allow us to give imgur an external link so Jake doesn't need to do heavy lifting, but we need user tokens for that despite it not being specified in the slack API. Admins also don't have permission to share other user's files in groups and IMs. Ideally in an upcoming change Jake would have users tokens and have action that could let the user turn off auto-uploads. Then jake could do this in every channel he's in for every user, and if someone doesn't want to repost something the user would control that before hand. Additionally, he could use the action menu to delete any images rather than posting an ephemeral link. The rework would result in a much cleaner experience overall for the end user