NOTICE: I have sunsetted this fork in favor of https://github.com/plainenough/slackbot
PyBites Article: Building a Karma Bot with Python and the Slack API
Original Project: pybytes/karmabot
- Setup user
useradd -d /opt/slackbot/ -r -s /usr/sbin/nologin -U slackbot
- Clone the repo to /opt/slackbot/
mkdir -p /opt/slackbot/
git clone https://github.com/plainenough/karmabot.git /opt/slackbot
chown -R slackbot:slackbot /opt/slackbot/
- Create service file - Use the above pybit articticle to get a gist on the setup process.
vim /etc/systemd/system/slackbot.service
[Unit]
Description=Karma Bot Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=slackbot
Environment=SLACK_KARMA_TOKEN=<INSERT YOUR APP TOKEN HERE>
Environment=SLACK_KARMA_BOTUSER=<INSERT BOT NAME HERE>
WorkingDirectory=/opt/slackbot/
ExecStart=/usr/bin/python3 /opt/slackbot/main.py
[Install]
WantedBy=multi-user.target
systemctl enable slackbot.service
systemctl start slackbot.service
-
Add the botname to a your config file.
-
Generating a config file will happen automatically when you start the service. But in case you want to just generate a config.
I made a utility for that.
python3 utils/create_config.py
docker build -t karmabot -f ./container/Dockerfile .
- You need to make sure you generate a config file in the mounted directory.
docker run -v /PATH/TO/DATA:/opt/slackbot/data --name karmabot karmabot
- Review commands/template.py (this is a great started template)
- After coding your command, add an import to the bot/slack.py
from commands.newmodule import your_function
- Add your command to the config and restart your service.