diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 204d3d1..5d9889f 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -8,15 +8,13 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 - name: Run tests - working-directory: bot - run: make test + run: make bot-test end-to-end-test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: build-image - working-directory: ./bot run: docker build . -t boink_bot --build-arg DISCORD_BOT_TOKEN=${{ secrets.DISCORD_BOT_TOKEN }} - name: run-tests run: docker run boink_bot test/E2E/init_server.py ${{ secrets.WEBHOOK_URL }} diff --git a/.gitignore b/.gitignore index 24326bb..591cfa3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ *.db sqlite_test.py env/ -config.ini +bot/config.ini nohup.out __pycache__/ .pytest* .vscode map.sql logs/ -bot/.DS_Store +.DS_Store diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..902b2c9 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a1f38ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.11.1-slim-bullseye + +ARG DISCORD_BOT_TOKEN + +WORKDIR /app + +# Copy entire project +COPY . . + +# Install make +RUN apt-get update && apt-get install -y make + +# Setup environment and install dependencies +RUN make setup DISCORD_BOT_TOKEN=$DISCORD_BOT_TOKEN + +# Ensure proper permissions +RUN chmod -R 755 /app + +# Set working directory to bot for running the application +WORKDIR /app/bot + +ENTRYPOINT ["python3"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ddd614e --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +VENV = env +PYTHON = python3.11 +BIN=$(VENV)/bin +CONFIG = bot/config.ini + +$(VENV): + @if [ ! -d env/ ]; then \ + echo "Creating a virtual environment and installing dependencies..."; \ + fi; + @$(PYTHON) -m venv $(VENV) + @$(BIN)/pip install --upgrade -q pip + @$(BIN)/pip install -q -r bot/requirements.txt + @$(BIN)/pip install -q -r databases/requirements.txt + @$(BIN)/pip install -q -r site/requirements.txt + +setup: + @if [ ! -d databases/bot_servers ]; then \ + mkdir -p databases/bot_servers; \ + fi + @if [ ! -d databases/game_servers ]; then \ + mkdir -p databases/game_servers; \ + fi + @if [ ! -d databases/analytics ]; then \ + mkdir -p databases/analytics; \ + fi + @if [ ! -f $(CONFIG) ]; then \ + echo "[default]" > $(CONFIG); \ + echo "token = $${DISCORD_BOT_TOKEN}" >> $(CONFIG); \ + echo "database = databases/default.db" >> $(CONFIG); \ + echo "" >> $(CONFIG); \ + echo "[meta]" >> $(CONFIG); \ + echo "database = databases/meta.db" >> $(CONFIG); \ + fi + +bot-run: $(VENV) + @cd bot && $(BIN)/python core.py + +bot-lint: $(VENV) + @cd bot && $(BIN)/python -m ruff check + +bot-format: $(VENV) + @cd bot && $(BIN)/python -m ruff format + +bot-test: $(VENV) + @cd bot && $(BIN)/python -m pytest test/ -v -s --log-cli-level=DEBUG + +site-run: $(VENV) + @cd site && $(BIN)/python app.py + +clean: + @rm -rf env/ .ruff_cache/ \ + bot/__pycache__ \ + bot/test/__pycache__ \ + bot/.pytest_cache/ \ + site/__pycache__ \ + databases/__pycache__ + +reset: clean $(VENV) + +todo: + @grep -inr "todo" bot/commands/ bot/handlers/ bot/interactions/ bot/utils/ databases/ + +.PHONY: setup bot-run bot-test bot-lint bot-format dev-site clean reset todo \ No newline at end of file diff --git a/bot/Dockerfile b/bot/Dockerfile deleted file mode 100644 index c732e62..0000000 --- a/bot/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM python:3.11.1-slim-bullseye - -ARG DISCORD_BOT_TOKEN - -ADD . /bot - -# Uncomment this line if you are running locally -# RUN rm /bot/config.ini - -WORKDIR /bot - -# Install make -RUN apt-get update && apt-get install -y make - -RUN make setup DISCORD_BOT_TOKEN=$DISCORD_BOT_TOKEN -RUN pip3 install -r requirements.txt - -# Create a directory for the database and set permissions -RUN mkdir -p /databases/bot_servers && chmod 777 /databases/bot_servers - -# Ensure proper permissions for the bot directory -RUN chmod -R 755 /bot - -ENTRYPOINT ["python3"] \ No newline at end of file diff --git a/bot/Makefile b/bot/Makefile deleted file mode 100644 index 4472893..0000000 --- a/bot/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -VENV = env -BIN=$(VENV)/bin -CONFIG = config.ini - -$(VENV): - @if [ ! -d env/ ]; then \ - echo "Creating a virtual environment and installing dependencies..."; \ - fi; - @python -m venv $(VENV) - @$(BIN)/pip install --upgrade -q pip - @$(BIN)/pip install -q -r requirements.txt - -setup: - @if [ ! -d databases ]; then \ - mkdir databases; \ - fi - @if [ ! -f $(CONFIG) ]; then \ - echo "[default]" > $(CONFIG); \ - echo "token = $${DISCORD_BOT_TOKEN}" >> $(CONFIG); \ - echo "database = databases/default.db" >> $(CONFIG); \ - echo "" >> $(CONFIG); \ - echo "[meta]" >> $(CONFIG); \ - echo "database = databases/meta.db" >> $(CONFIG); \ - fi - -dev: $(VENV) - @$(BIN)/python core.py - -lint: $(VENV) - @$(BIN)/python -m ruff check - -format: $(VENV) - @$(BIN)/python -m ruff format - -test: $(VENV) - @$(BIN)/python -m pytest test/ -v -s --log-cli-level=DEBUG - -clean: - @rm -rf env/ .ruff_cache/ \ - src/bot/__pycache__ \ - tests/__pycache__ .pytest_cache/ - -reset: clean $(VENV) - -todo: - @grep -inr "todo" commands/ handlers/ interactions/ utils/ databases/ diff --git a/bot/core.py b/bot/core.py index 6f341ff..d4c627d 100644 --- a/bot/core.py +++ b/bot/core.py @@ -243,15 +243,11 @@ async def run_server_database_alerts(self): logger.info("Running server database alerts") for guild in self.guilds: - try: - logger.info( - f"Config for {guild}: {read_config_str(guild.id, ConfigKeys.ALERTS, '0')}" - ) - if read_config_str(guild.id, ConfigKeys.ALERTS, "0") == "1": - await self._send_alerts_for_guild(guild) - except KeyError as e: - logger.error(f"Failed to check alerts for {guild}") - logger.error(e) + logger.info( + f"Config for {guild}: {read_config_str(guild.id, ConfigKeys.ALERTS, '0')}" + ) + if read_config_str(guild.id, ConfigKeys.ALERTS, "0") == "1": + await self._send_alerts_for_guild(guild) if __name__ == "__main__": diff --git a/site/requirements.txt b/site/requirements.txt index d0f155f..703ca9b 100644 --- a/site/requirements.txt +++ b/site/requirements.txt @@ -12,7 +12,7 @@ dash==2.13.0 dash-auth==2.0.0 dash-bootstrap-components==1.5.0 dash-core-components==2.0.0 -dash_daq=0.5.0 +dash_daq==0.5.0 dash-html-components==2.0.0 dash-table==5.0.0 discord.py==2.3.2 @@ -33,9 +33,9 @@ packaging==23.1 pandas==2.1.1 Pillow==10.0.1 plotly==5.17.0 -pluggy==1.3.0 +pluggy>=1.4.0 pyparsing==3.1.1 -pytest==7.4.1 +pytest>=8.2.0 python-dateutil==2.8.2 pytz==2023.3.post1 requests==2.31.0