Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions bot/Dockerfile

This file was deleted.

46 changes: 0 additions & 46 deletions bot/Makefile

This file was deleted.

14 changes: 5 additions & 9 deletions bot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
6 changes: 3 additions & 3 deletions site/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down