Computer Science Club Discord Server Bots
The service manager relies on a configuration file named service.json
. This file defines the services to be managed, the Python interpreter path, and update scripts to be executed after pulling changes from the GitHub repository.
Example service.json
:
{
"pythonPath": "./.venv/Scripts/python.exe",
"updateScripts": [".\\CodingChallengerBot\\DockerFiles\\buildDocker.bat"],
"services": ["service1.py", "service2.py"]
}
pythonPath
: Path to the Python interpreter executable.services
: List of service scripts to be managed.updateScripts
: List of scripts to be executed after updating from the GitHub repository.
- Configuration Loading:
- The script starts by loading the configuration from
service.json
. - It reads the Python interpreter path, service scripts, and update scripts.
- The script starts by loading the configuration from
- GitHub Token:
- The script checks for the presence of a GitHub token in the
.env
file. - The GitHub token is used for API authentication when querying the repository.
- The script checks for the presence of a GitHub token in the
- Service Startup:
- The script starts the specified services as separate subprocesses.
- The processes are stored in the
running_processes
list for later management.
- Update Check Loop:
- The script enters an infinite loop to periodically check for updates.
- It queries the GitHub repository to get the latest commit in the main branch.
- Update Detection:
- If a new commit is detected, the script terminates the running services.
- It then pulls the latest changes from the GitHub repository and executes update scripts.
- Service Restart:
- After updates are applied, the script restarts the services with the new code.
- Update Commit Tracking:
- The latest commit is recorded in a file (
latestCommit.txt
) to track changes.
- The latest commit is recorded in a file (
- Sleep Interval:
- The script sleeps for a specified interval (10 seconds by default) before checking for updates again.
- Interrupt Handling:
- The script is designed to gracefully terminate the running processes when interrupted (e.g., using Ctrl+C).
rename the .env.example file in the root folder of the bot
In this file copy the channel ID from discord of the channel you would like the bot to create channel threads in. You can look up how copy the channel ID online, it is quite simple
Make sure to add a bot token in the .env file
run the command below to install the dependencies, you can do this in a python virtual environment if you so choose
pip install -r requirements.txt
cd
into the directory CSBotCommon
and run the command
pip install .
This needs to be ran everytime the CSBotCommon module is updated
The best way to setup docker is to install docker desktop
https://www.docker.com/products/docker-desktop/
Once docker or docker desktop is installed you will want to run the docker build script associated with your operating system, dockerBuild.bat
for windows and dockerBuild.sh
for linux. These scripts will build the docker images for each of the code validators and will add them to your docker instance.
Docker images are virtual machines that are created programatically from a "dockerfile". You can create a container from this docker image. The container will act as its own virtual machine seperate from other containers on your system. You can create multiple containers from the same image if you wish. The docker image acts only as a base from which the container can run and manipilate. Docker allows the bot to run code in sandboxed environments where malicious code will have much much more difficulty causing problems.