slack-thug icon indicating copy to clipboard operation
slack-thug copied to clipboard

Thug memes from Slack image uploads

slack-thug

Build Status codecov license PRs

example gif

What

Thug memes from Slack image uploads.

Messages that are posted in threads of uploaded images and start with thug or Thug are considered as commands to create and upload thug memes based on the original image and given command. Any member of a public channel (which thug bot is also part of) can thug anyone's uploads.

Calling api

  • thug: creates a thug meme without any texts
  • thug some message: creates a thug meme with some message as text in the upper part of the image
  • thug "some message" "some other message": creates a thug meme with some message as text in the upper part and some other message in the lower part of the image
  • thug "some message" "some other message" -o configoption foo: same as previous but also overrides default value of configoption by value foo while creating thug meme. Multiple config options can be overridden by mentioning -o flag multiple times. See full list of available thug meme configuration options here. slack-thug uses dlib detector of thug-memes so opencv* config options in detect section are not relevant.

If there's an issue while creating the thug meme, the bot will reply nicely in the Slack thread of the given thug command with some additional details about what went wrong.

Tech stack

Setup

Slack

Create a Slack App

  1. Access the web UI of your workspace, e.g. click your workspace name in Slack desktop application and select Customize Slack
  2. Configure apps -> Build (top right corner) -> Your Apps -> Create an App
  3. Give you app a dope name and select workspace

Create a bot user

  1. Bot Users -> Add a bot user -> configure display name and default name -> Add Bot User -> Save changes

Install the app to the workspace

  1. Your Apps -> your app name -> Install your app to your workspace -> Install App to Workspace -> Authorize

Get the token

  1. OAuth & Permissions -> Bot User OAuth Access Token
  2. Save the token as env variable, e.g. export SLACK_TOKEN=<the token>

NOTE: the slack-thug application should be running before the next step.

Configure event subscription

  1. Event Subscriptions -> Enable Events
  2. Fill Request URL: <your_url>/event (see Endpoint for Slack App below), you should see green at this point if everything is ok
  3. The bot requires access to messages: Add Bot User Event -> add message.channels -> Save Changes

Start having fun

  • Invite the bot to public channel(s) in which you want to thug image uploads.

slack-thug

NOTE: make sure SLACK_TOKEN env variable is configured at this point.

Option 1 - docker-compose (the easy way):

  1. Install Docker Engine and Docker Compose if you don't have those.
  2. Run docker-compose up. Hold your horses though, installing dlib inside a docker image takes a while.
docker-compose up

Option 2 - manual installation, running services separately:

  1. slack-thug relies heavily on thug-memes which in turn uses dlib under the hood. Here's one guide for installing dlib on different platforms.
  2. slack-thug uses poetry for dependency management, install deps by:
poetry install
  1. slack-thug uses redis for the communication between the web app and the worker process. Install redis and run redis server.
  2. Run the worker
poetry run python -m slack_thug.worker
  1. Run the web app (on a separate console)
poetry run python -m slack_thug.app

Endpoint for Slack App

Regardless which installation/running option you used for slack-thug, the endpoint for Slack App will be accessible in http://localhost:5000/event if default configuration is used. To access this endpoint from outside, you can use e.g. ngrok. After running ngrok http 5000, the endpoint (accessible from outside) will be something like https://asfsdfdsg.ngrok.io/event. You can use this while configuring the event subscription for the Slack App.

Better option compared to running stuff locally is obviously to deploy it on your (employer's) favorite hosting provider, which is not covered here.

Development

Installation

poetry install

Testing

poetry run pytest

pre-commit

  • Install it and it'll be ran automatically with every commit
pre-commit install
  • Running manually
pre-commit run -a