Skip to content

Commit

Permalink
Merge pull request #1 from bits-bsc-cs/sattwyk/bot
Browse files Browse the repository at this point in the history
Email Verification Bot for BITS Pilani Discord Server
  • Loading branch information
sattwyk authored Oct 28, 2024
2 parents 24512ad + 2a9c809 commit bb180ae
Show file tree
Hide file tree
Showing 17 changed files with 1,582 additions and 313 deletions.
6 changes: 0 additions & 6 deletions .devcontainer/devcontainer.json

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy to Cloud Run

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE_NAME: discord-bot

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'

steps:
- uses: actions/checkout@v4

- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'

- name: Configure Docker
run: gcloud auth configure-docker

- name: Build and Push Docker image
run: |
echo "Building image for project: $PROJECT_ID"
docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} ./bot
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }}
- name: Deploy to Cloud Run
run: |
gcloud run deploy $SERVICE_NAME \
--image gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \
--platform managed \
--region asia-south1 \
--allow-unauthenticated \
--set-env-vars="DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }},RESEND_API_KEY=${{ secrets.RESEND_API_KEY }},UPSTASH_REDIS_REST_URL=${{ secrets.UPSTASH_REDIS_REST_URL }},UPSTASH_REDIS_REST_TOKEN=${{ secrets.UPSTASH_REDIS_REST_TOKEN }}"
160 changes: 1 addition & 159 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,160 +1,2 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.env.prod
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# discord-bot
# BITS Pilani Discord Email Verification Bot

source .venv/bin/activate
This bot provides email verification for the BITS Pilani Discord server, ensuring that only students with valid BITS Pilani email addresses can access certain channels.

## Features

- Email verification using BITS Pilani student email addresses
- Discord slash command for initiating verification
- Rate limiting to prevent abuse
- Automatic role assignment upon successful verification
- Docker support for easy deployment

## Local Development Setup

1. Clone the repository:
```
git clone https://github.com/bits-bsc-cs/discord-bot.git
cd discord-bot
```

2. Create a `.env` file in the root directory with the following variables:
```
DISCORD_TOKEN=your_discord_bot_token
RESEND_API_KEY=your_resend_api_key
```

3. Install Docker and Docker Compose on your system.

4. Run the bot locally using Docker Compose:
```
docker-compose up --build
```

5. The bot should now be running and connected to Discord. You can test it by using the `/verify` command in your Discord server.

## Usage

1. Invite the bot to your Discord server and ensure it has the necessary permissions.
2. Users can start the verification process by using the `/verify` command.
3. The bot will prompt users to enter their BITS Pilani email address.
4. A verification code will be sent to the provided email.
5. Users must enter the verification code to complete the process.
6. Upon successful verification, users will be assigned the "Verified" role.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
9 changes: 9 additions & 0 deletions bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.uv
.venv
.ruff_cache

.env
.env.local
.env.production


1 change: 1 addition & 0 deletions bot/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
35 changes: 35 additions & 0 deletions bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use the official Python image as the base image
FROM python:3.10-slim-bookworm AS base

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV UV_SYSTEM_PYTHON=1
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
ENV PORT=8080

# Set the working directory
WORKDIR /app

# Copy only the necessary files for dependency installation
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system -r pyproject.toml

# Copy the rest of the application code
COPY bot.py ./

# Compile bytecode
RUN python -m compileall .

# Expose the port the app runs on
EXPOSE 8080

# Set the command to run the application
CMD ["python", "bot.py"]
Loading

0 comments on commit bb180ae

Please sign in to comment.