A simple karma bot for Slack.
This is a simple, standalone Slack bot that watches for “karma events” and will keep track of scores for users and topics.
In a channel where Karma Chameleon is present, do the following to add a point to a user or topic.
@user++
subject++
In a channel where Karma Chameleon is present, do the following to remove a point from the user or topic.
@user—-
subject--
Note that decrementing or incrementing a user's own karma (the self-bump) is not a valid operation. You will be chastised by the Chameleon.
Karma Chameleon relies on pip
to install its dependencies and is easiest to develop with
a Python Virtual Environment.
$ git clone https://github.com/subecho/KarmaChameleon.git
$ cd KarmaChameleon
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python3 -m pip install -r requirements.txt
Before running the code, we need to do some initial setup on the Slack side so that Slack knows who we are, we are who we say we are, and which events we wish to subscribe to. You will need to create a new app in Slack and add the following scopes:
Bot Token Scopes:
App-Level Tokens Scopes:
User Token Scopes:
There are two steps to testing the bot on your local machine: running the code and forwarding the port on which Karma Chameleon is listening to some publicly available URL. The CLI tool ngrok may be used to do this.
The following environment variables must be present in order for Karma Chameleon to function:
SLACK_BOT_TOKEN
: populated with the contents of the SLACK_BOT_TOKEN OAuth key in the
Slack App OAuth settingsSLACK_APP_TOKEN
: populated with the contents of an App-Level Token specifically
generated for use with socket mode, which may be found in Slack App Basic InformationKARMA_FILE_PATH
: the path to which Karma Chameleon will create and maintain a JSON
record of all karma.In one terminal window, run: python3 karma_chameleon.py
After running that, in another terminal window, run: ngrok http 3000
This command will output an https URL that can be used to interact with the bot. You will
want to paste this URL into the Request URL field in the Event Subscriptions page for
your app. The format of the URL should be "message.channels
event to the subscribed events for the
bot. For slash-command support, a new command must be added with the request URL also
being the ngrok URL in the format of "
The Karma Chameleon icon was made by Eucalyp from www.flaticon.com.