ESN-Trondheim / ESNbot

A Slack bot for ESN Trondheim
MIT License
3 stars 2 forks source link

ESNbot

[![Python](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/) [![Build](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/build.yml/badge.svg)](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/build.yml) [![Tests](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/test.yml/badge.svg)](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/test.yml) [![Formatting](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/formatting.yml/badge.svg)](https://github.com/ESN-Trondheim/ESNbot/actions/workflows/formatting.yml) [![License](https://img.shields.io/github/license/ESN-Trondheim/ESNbot)](https://github.com/ESN-Trondheim/ESNbot/blob/master/LICENSE) [![Issues](https://img.shields.io/github/issues/ESN-Trondheim/ESNbot)](https://github.com/ESN-Trondheim/ESNbot/issues) [![Contributors](https://img.shields.io/github/contributors/ESN-Trondheim/ESNbot)](https://github.com/ESN-Trondheim/ESNbot/graphs/contributors) [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\ A Slack bot for ESN Trondheim.\ Original author: [Lai Alexander Holmsen](https://github.com/LaiAlexander)

Overview

ESNbot is a self hosted slack bot. ESNbot tries to help the members of ESN Trondheim to have an easier digital workflow by automating common tasks. This includes creating coverphotos for events, watermarking pictures, getting contact info for members and more.

Setup

Prerequisites

Project setup

Once the prerequisites are in order, you can proceed with the rest of the project setup. All code/commands are executed in Git Bash, but other CLIs may be used. The commands may differ somewhat.

  1. Clone/pull/fork this repo from GitHub
  2. Not strictly necessary, but it is heavily recommended to create a virtual environment and run the bot from there: python -m venv env If you for some reason don't want to use a virtual environment, skip to step 4.
  3. Activate virtual environment: . env/Scripts/activate
  4. Install requirements or dev requiremnents (preferably into the virtual environment): pip install -r requirements.txt or pip install -r requirements-dev.txt. Note that dev requirements are optional, and also install regular requirements, meaning that you don't have try to install both.
  5. Copy public.envand name it secret-dev.env or secret-prod.env and place it into the setup folder. Make sure that it has the same structure as public.env. Enter your credentials from the steps in the prerequisites. If both secret-dev.envand secret-prod.envare present, secret-dev.env will be used. Remember to never include your credentials/tokens in a repository, especially not a public one! I.e. do not commit secret-dev.env or secret-prod.env to the repo, and do not add any secrets to public.env. secret-prod.env should only be used for your production environment, and secret-dev.env is intended for your development environment.
  6. Run the bot: python esnbot.py. If everyhting has been setup correctly you should see something like
    secret-dev/prod.env loaded...
    DD-MM-YYYY HH:MM:SS: ESNbot connected and running...
  7. Stop the bot by pressing ctrl + c in Git Bash (or another CLI) and deactivate the virtual environment with the command deactivate

Step 2 and 4 can be done in one go by using the script setup-venv-win.sh. In Git Bash you can run it like this: . setup-venv-win.sh. The virtual environment still needs to be activated prior to running the bot.

Requirements

You can install all of the above at once with pip install -r requirements.txt (or pip install -r requirements-dev.txt), preferably into a virtual environment.

Usage

The bot will not do anything before it is tagged in a channel.\ For a list of all available commands type @[botname] list

Adding your own commands

To add your own command, use the core_commands.register_command decorator. This will register the command with the bot, along with the help text for your command. A simple example:

@register_command(
    keyword="mycommand", help_text="My example command", visible=True
)
def my_custom_command(client, channel, user, argument, output):
    client.respond_to(channel, user, "Hello, this is my_custom_command")

Contributing

Contributions are welcome!\ You can contribute with both code and registering issues.

Please see our contributing guidelines for information about how to contribute to this project.

License

MIT