Skip to content

Commit

Permalink
Refactors for submodule
Browse files Browse the repository at this point in the history
- Moves the relevant GitHub Actions to the submodule
- Refactors the readme to reference the main repo

Signed-off-by: Diana <dmoore@xn4p4lm.com>
  • Loading branch information
xN4P4LM committed Feb 8, 2024
1 parent 5c3f24b commit 402a652
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 123 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Build Docker Images"
on:
pull_request:
branches:
- main
push:

jobs:
build-bot-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate X509 certificate for testing
run: scripts/generate_x509.sh
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Build
uses: docker/build-push-action@v5
with:
context: bot/.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Linting"
on:
pull_request:
branches:
- main
push:

jobs:
run-py-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
- name: Install apt dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools python3-venv python3-pip gcc
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint pytest-pylint
- name: Lint with Pylint
run: scripts/lint.sh
28 changes: 28 additions & 0 deletions .github/workflows/pytest.yaml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: pytest

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: cache pytest
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Run pytest
run: |
pytest
125 changes: 4 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,7 @@
# Bot-O-Cat
# Bot-O-Cat: Bot - This is the bot portion of the [Bot-O-Cat](https://github.com/xN4P4LM-org/bot-o-cat)

[![Linting](https://github.com/xN4P4LM-org/bot-o-cat/actions/workflows/lint.yaml/badge.svg)](https://github.com/xN4P4LM-org/bot-o-cat/actions/workflows/lint.yaml)
[![Linting](https://github.com/xN4P4LM-org/bot-o-cat_bot/actions/workflows/lint.yaml/badge.svg)](https://github.com/xN4P4LM-org/bot-o-cat_bot/actions/workflows/lint.yaml)

### ( This is a work in progress - use at your own risk )
## Contributing guidelines

## Overview

This is a general purpose bot that is designed to be customizable and extensible. It's built on top of the [discord.py](https://github.com/Rapptz/discord.py) library by [Rapptz](https://github.com/Rapptz).

## Features

## Running the bot

There are a few ways to run this bot, but the easiest way is to use Docker Compose.

### Standalone from source

```bash
pip install -r requirements.txt
python bot.py
```

### Docker Compose from source

```yaml
version: "3"
services:
bot:
container_name: discord-bot
build: ./bot
environment:
- DISCORD_BOT_DESCRIPTION="A simple discord bot"
- DISCORD_BOT_TOKEN=
- DISCORD_BOT_OWNER_ID=
- DISCORD_BOT_COMMAND_PREFIX=.
- DISCORD_BOT_LOG_LEVEL=20 # 10=DEBUG, 20=INFO, 30=WARNING, 40=ERROR, 50=CRITICAL
- DISCORD_MONGO_DB_HOST_NAME=mongo-db
- DISCORD_MONGO_DB_PORT=27017
- DISCORD_MONGO_DB_DATABASE_NAME=bot-o-cat
volumes:
- discord_cogs:/bot/cogs
- discord_git_ssh:/root/.ssh
depends_on:
mongo-db:
condition: service_healthy
restart: true

mongoDB:
container_name: discord-mongoDB
build: ./db
environment:
- MONGO_INITDB_ROOT_USERNAME=
- MONGO_INITDB_ROOT_PASSWORD=
volumes:
- discord_db:/data/db
healthcheck:
test: mongosh mongo-db:27017/test --tls --tlsCertificateKeyFile /etc/ssl/mongo-db.pem --tlsCAFile /etc/ssl/ca.pem --quiet --eval 'db.runCommand({ping:1})'
interval: 10s
timeout: 5s
retries: 3
start_period: 5s

api-certbot:
container_name: discord-api-certbot
image: certbot/dns-cloudflare
volumes:
- discord_api_ssl_certs:/etc/letsencrypt
- ./cloudflare.ini:/root/cloudflare.ini
command: >-
certonly --dns-cloudflare
--dns-cloudflare-credentials /root/cloudflare.ini
--dns-cloudflare-propagation-seconds 15
--email dmoore
--agree-tos --no-eff-email
--force-renewal
-d api.bot-o-cat.com
depends_on:
- mongo-db
- bot

api:
container_name: discord-api
build: ./api
environment:
- API_PORT=8443
ports:
- "8443:8443"
volumes:
- discord_api_ssl_certs:/etc/letsencrypt/live/api.bot-o-cat.com
depends_on:
api-certbot:
condition: service_completed_successfully
restart: true

volumes:
discord_git_ssh:
discord_cogs:
discord_db:
discord_api_ssl_certs:
```
## Required environment variables
- `DISCORD_BOT_DESCRIPTION` - The description of the bot
- `DISCORD_BOT_TOKEN` - Discord Token for your bot from the Discord Developer Portal
- `DISCORD_BOT_OWNER_ID` - The Bot Owner's user id
- `DISCORD_BOT_COMMAND_PREFIX` - Command Prefix Ex. `!`
- `DISCORD_BOT_LOG_LEVEL` - the int log level `(10, 20, 30, 40, 50)`
- `MONGO_INITDB_ROOT_USERNAME` - The root user for MongoDB
- `MONGO_INITDB_ROOT_PASSWORD` - The root password for MongoDB

# Contributing

Please fork this repository and contribute back using [pull requests](https://github.com/xn4p4lm-org/bot-o-cat/pulls).
Ensure that when submitting code that you have read the [developer-certificate-of-origin](developer-certificate-of-origin) and that you have signed off on your commits with `git commit -s` or `git commit --signoff`.

Features request can be submitted by using [GitHub Issues](https://github.com/xn4p4lm-org/bot-o-cat/issues).

All code, comments, and critiques are greatly appreciated.

# License

bot-o-cat is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
If you would like to contribute to the project, please navigate to the [Bot-O-Cat](https://github.com/xN4P4LM-org/bot-o-cat) repository and follow the [CONTRIBUTING.md](https://github.com/xN4P4LM-org/bot-o-cat/blob/main/CONTRIBUTING.md) guidelines.
4 changes: 2 additions & 2 deletions helpers/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def getEnvVar(var_name: str) -> str:
"""
try:
return os.environ[var_name]
except KeyError as e:
logger.error("Environment variable %s not found: %s - EXITING", var_name, e)
except KeyError as key_error:
logger.error("Environment variable %s not found: %s - EXITING", var_name, key_error)
sys.exit(1)
4 changes: 4 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Run pylint on all python files in the project
find bot/ ! -path "./.venv/*" -type f -name "*.py" | xargs pylint --rcfile pylintrc

0 comments on commit 402a652

Please sign in to comment.