#!/bin/bash
# This script updates the system, installs required system packages,
# clones the Discord bot repository, sets up a Python virtual environment,
# installs Python dependencies, and finally runs the bot.

# Exit immediately if a command exits with a non-zero status.
set -e

echo "Updating package lists and installing system dependencies..."
sudo apt update
sudo apt install python3.12-venv -y
sudo apt-get install python3-pip -y

echo "Cloning the Discord bot repository..."
git clone https://gitlab.com/pancakes1234/wdiscordbot-internal-server-aws.git

echo "Setting up the Python virtual environment..."
python3 -m venv venv
# Activate the virtual environment so that subsequent pip installs are local
source venv/bin/activate

echo "Installing Python dependencies..."
pip install \
    aiohappyeyeballs==2.6.1 \
    aiohttp==3.11.16 \
    aiosignal==1.3.2 \
    annotated-types==0.6.0 \
    anyio==4.9.0 \
    archspec==0.2.3 \
    async-timeout==5.0.1 \
    attrs==25.3.0 \
    beautifulsoup4==4.13.4 \
    blis==1.3.0 \
    boltons==24.1.0 \
    Brotli==1.1.0 \
    catalogue==2.0.10 \
    certifi==2025.1.31 \
    cffi==1.17.1 \
    charset-normalizer==3.3.2 \
    ChatterBot==1.2.6 \
    chatterbot-corpus==1.2.2 \
    click==8.1.8 \
    cloudpathlib==0.21.0 \
    confection==0.1.5 \
    cryptography==43.0.3 \
    cymem==2.0.11 \
    decorator==5.2.1 \
    discord.py==2.5.2 \
    distro==1.9.0 \
    docx2pdf==0.1.8 \
    et_xmlfile==2.0.0 \
    fastapi==0.115.12 \
    filelock==3.18.0 \
    frozendict==2.4.2 \
    frozenlist==1.5.0 \
    fsspec==2025.3.2 \
    GPUtil==1.4.0 \
    greenlet==3.2.1 \
    h11==0.14.0 \
    hf-xet==1.1.1 \
    httpcore==1.0.8 \
    httpx==0.28.1 \
    huggingface-hub==0.31.1 \
    idna==3.7 \
    imageio==2.37.0 \
    imageio-ffmpeg==0.6.0 \
    inflate64==1.0.1 \
    inquirerpy==0.3.4 \
    Jinja2==3.1.6 \
    jiter==0.9.0 \
    jsonpatch==1.33 \
    jsonpointer==2.1 \
    langcodes==3.5.0 \
    language_data==1.3.0 \
    lxml==5.4.0 \
    lyricsgenius==3.6.2 \
    marisa-trie==1.2.1 \
    markdown-it-py==2.2.0 \
    MarkupSafe==3.0.2 \
    mathparse==0.1.5 \
    mdurl==0.1.0 \
    moviepy==2.1.2 \
    mpmath==1.3.0 \
    multidict==6.4.3 \
    multivolumefile==0.2.3 \
    murmurhash==1.0.12 \
    networkx==3.4.2 \
    numpy==2.2.5 \
    nvidia-cublas-cu12==12.6.4.1 \
    nvidia-cuda-cupti-cu12==12.6.80 \
    nvidia-cuda-nvrtc-cu12==12.6.77 \
    nvidia-cuda-runtime-cu12==12.6.77 \
    nvidia-cudnn-cu12==9.5.1.17 \
    nvidia-cufft-cu12==11.3.0.4 \
    nvidia-cufile-cu12==1.11.1.6 \
    nvidia-curand-cu12==10.3.7.77 \
    nvidia-cusolver-cu12==11.7.1.2 \
    nvidia-cusparse-cu12==12.5.4.2 \
    nvidia-cusparselt-cu12==0.6.3 \
    nvidia-nccl-cu12==2.26.2 \
    nvidia-nvjitlink-cu12==12.6.85 \
    nvidia-nvtx-cu12==12.6.77 \
    openai==0.28.0 \
    opencv-python==4.11.0.86 \
    openpyxl==3.1.5 \
    openrouter==1.0 \
    packaging==24.2 \
    pfzy==0.3.4 \
    pillow==10.4.0 \
    platformdirs==3.10.0 \
    pluggy==1.5.0 \
    preshed==3.0.9 \
    proglog==0.1.12 \
    prompt_toolkit==3.0.51 \
    propcache==0.3.1 \
    psutil==7.0.0 \
    py7zr==0.22.0 \
    pybcj==1.0.6 \
    pycosat==0.6.6 \
    pycparser==2.21 \
    pycryptodomex==3.23.0 \
    pydantic==2.10.3 \
    pydantic_core==2.27.1 \
    pydub==0.25.1 \
    Pygments==2.15.1 \
    PyNaCl==1.5.0 \
    PyPDF2==3.0.1 \
    pyppmd==1.1.1 \
    PySocks==1.7.1 \
    python-dateutil==2.9.0.post0 \
    python-docx==1.1.2 \
    python-dotenv==1.1.0 \
    python-pptx==1.0.2 \
    PyYAML==6.0.2 \
    pyzstd==0.17.0 \
    regex==2024.11.6 \
    requests==2.32.3 \
    rich==13.9.4 \
    ruamel.yaml==0.18.6 \
    ruamel.yaml.clib==0.2.8 \
    rule34==1.8.1 \
    safetensors==0.5.3 \
    setuptools==75.8.0 \
    shellingham==1.5.4 \
    six==1.17.0 \
    smart-open==7.1.0 \
    sniffio==1.3.1 \
    soupsieve==2.7 \
    spacy==3.8.5 \
    spacy-legacy==3.0.12 \
    spacy-loggers==1.0.5 \
    SQLAlchemy==2.0.40 \
    srsly==2.5.1 \
    starlette==0.46.2 \
    sympy==1.14.0 \
    texttable==1.7.0 \
    thinc==8.3.6 \
    tokenizers==0.21.1 \
    torch==2.7.0 \
    tqdm==4.67.1 \
    transformers==4.51.3 \
    triton==3.3.0 \
    truststore==0.10.0 \
    typer==0.15.2 \
    typing_extensions==4.13.2 \
    urllib3==2.3.0 \
    uvicorn==0.34.2 \
    wasabi==1.1.3 \
    wcwidth==0.2.13 \
    weasel==0.4.1 \
    wheel==0.45.1 \
    whois==1.20240129.2 \
    wrapt==1.17.2 \
    XlsxWriter==3.2.3 \
    yarl==1.19.0 \
    youtube-dl==2021.12.17 \
    zstandard==0.23.0

echo "Changing directory to the cloned repository and starting the bot..."
cd wdiscordbot-internal-server-aws
python3 bot.py