Skip to content

Commit

Permalink
Add nix dev shell and simplify dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Jan 13, 2024
1 parent eeb7a40 commit c603c4f
Show file tree
Hide file tree
Showing 15 changed files with 416 additions and 367 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ polls.yaml
.env
poetry.lock
*/__pycache__
.devenv
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ repos:
rev: 23.7.0
hooks:
- id: black
args: [--line-length=88]
language_version: python3

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.280
hooks:
- id: ruff
args: [--line-length=100, --ignore=E501]
args: [--ignore=E501]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand Down
2 changes: 1 addition & 1 deletion .reuse/addheader
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# SPDX-License-Identifier: MPL-2.0
# https://git.joinemm.dev/miso-bot

reuse addheader --copyright="Joonas Rautiola <[email protected]>" --license="MPL-2.0" --template="header.jinja2" $@
reuse annotate --copyright="Joonas Rautiola <[email protected]>" --license="MPL-2.0" --template="header.jinja2" "$@"
4 changes: 2 additions & 2 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Files: downloads/* images/* data/*
Copyright: 2023 Joonas Rautiola <[email protected]>
License: CC0-1.0

Files: *.md .* requirements.* dev-requirements.*
Files: *.md .* *.lock
Copyright: 2023 Joonas Rautiola <[email protected]>
License: MPL-2.0
License: MPL-2.0
36 changes: 28 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@
# SPDX-License-Identifier: MPL-2.0
# https://git.joinemm.dev/miso-bot

FROM python:3.11
# The builder image, used to build the virtual environment
FROM python:3.11-buster as builder

RUN pip install poetry==1.4.2

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app

COPY pyproject.toml poetry.lock ./
RUN touch README.md

RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR

# The runtime image, used to just run the code provided its virtual environment
FROM python:3.11-slim-buster as runtime

RUN apt-get update -y
RUN apt-get install --no-install-recommends -y ffmpeg wget
RUN wget --progress=dot:giga https://github.com/isis-project/isis-fonts/blob/master/NanumGothic.ttf?raw=true -O NanumGothic.ttf
RUN apt-get update -y \
&& apt-get install --no-install-recommends -y ffmpeg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY . .

ENV PYTHONUNBUFFERED=1
CMD ["python", "-O", "main.py"]
109 changes: 55 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Miso Bot

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/84479f7c0f4c44a6aa2ba435e0215436)](https://app.codacy.com/manual/joinemm/miso-bot?utm_source=github.com&utm_medium=referral&utm_content=joinemm/miso-bot&utm_campaign=Badge_Grade_Dashboard)
[![DeepSource](https://deepsource.io/gh/joinemm/miso-bot.svg/?label=active+issues&show_trend=true&token=0E1BBh1I4k_HkqRvfRy86yMc)](https://deepsource.io/gh/joinemm/miso-bot/?ref=repository-badge)
Expand All @@ -8,78 +6,81 @@
[![Discord](https://img.shields.io/discord/652904322706833409.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/RzDW3Ne)
[![Patreon](https://img.shields.io/badge/Patreon-donate-orange.svg)](https://www.patreon.com/joinemm)
[![Sponsor](https://img.shields.io/github/sponsors/joinemm?color=%23db61a2)](https://github.com/sponsors/joinemm)

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B824LWC)


* * *

A discord bot with over 100 commands and features, including but not limited to:

- Fishing
- LastFM Integration
- Melon charts
- Youtube search
- Twitter media extractor
- Instagram media extractor
- TikTok media extractor
- Moderation (ban, mute, timeout, etc)
- Logs bans, leaves, joins, deleted messages
- Server and user information
- Customizable profiles
- Minecraft server status
- Starboard
- DuckDuckGo bangs
- Colors and color palettes
- Create and search gifs
- Horoscope
- Weather
- Keyword notifications
- Rolepicker
- Color roles
- Typing tests and Typeracer
- Papago Naver and google translator
- Wolfram alpha
- Reminders
- Custom commands
- Configurable prefix
- Cryptocurrency data
- Kpop idol database

...and much more. Visit <https://misobot.xyz> for more detailed overview of the features.
# Miso Bot

## Star History
Miso is a multipurpose Discord bot with over 100 commands and features.

[![Star History Chart](https://api.star-history.com/svg?repos=joinemm/miso-bot&type=Date)](https://star-history.com/#joinemm/miso-bot&Date)
For more information and command reference, visit <https://misobot.xyz>

## Contributor wall
## Development

[![Contributors](https://contrib.rocks/image?repo=joinemm/miso-bot)](https://github.com/joinemm/miso-bot/graphs/contributors)
A Nix development shell is included, using [devenv](https://github.com/cachix/devenv)

## Deployment using docker
This environment installs poetry and some useful packages.

First copy/rename `.env.example` to `.env` and fill it with your own keys.
Everything else should be handled by the `docker-compose.yml`
```sh
nix develop --impure
```

The dependencies are managed using [Poetry](https://python-poetry.org/)

```sh
poetry install
```

$ docker-compose up --build
The bot can then be run with

## Deploying locally
```sh
poetry run python main.py
```

The dependencies are compiled using pip-tools from `requirements.in` and `dev-requirements.in`. the dev file just adds linters and pre-commit.
but it will not function without a MariaDB database.
This makes using docker compose the easiest way to run the bot.

Installation using pip-tools:
## Contributing

$ pip-sync requirements.txt dev-requirements.txt
Your pull requests are welcome, as long as they meet the code standards enforced by the [pre-commit](https://pre-commit.com/) hooks.

Installation using pip:
- [Black](https://github.com/psf/black) and [isort](https://pycqa.github.io/isort/) for formatting.
- [Ruff](https://github.com/astral-sh/ruff), for linting.
- [Reuse](https://reuse.software/), for licensing.

$ pip install -r requirements.txt -r dev-requirements.txt
To install the hooks, run this command:

You need to have a mysql/mariadb database running, then run the migrations in `sql/init/...`. After this, you can run the bot:
```sh
pre-commit install
```

$ python main.py
Now your code should be automatically checked for issues when you commit.

> Note: Running this way, the HTML rendering will not work as it relies on an external docker container. You will have to run that separately.
## Deployment

First copy/rename `.env.example` to `.env` and fill it with your own keys.
Everything else should be handled by the dockerfile.

```sh
docker-compose up
```

The docker compose file bootstraps the entire miso infrastructure,
including prometheus metrics, grafana dashboards and nginx reverse proxy.

You likely don't want these if you're just running the bot.

To run only the containers needed for the functionality of the bot, you can specify the service names:

```sh
docker-compose up db image-server emojifier bot
```

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=joinemm/miso-bot&type=Date)](https://star-history.com/#joinemm/miso-bot&Date)

## Contributor wall

[![Contributors](https://contrib.rocks/image?repo=joinemm/miso-bot)](https://github.com/joinemm/miso-bot/graphs/contributors)
7 changes: 0 additions & 7 deletions dev-requirements.in

This file was deleted.

64 changes: 0 additions & 64 deletions dev-requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ services:
expose:
- 3000
volumes:
# Static files
- ./static:/app/static:ro
# Handlebar template files
- ./templates:/app/templates:ro

shlink:
Expand Down
Loading

0 comments on commit c603c4f

Please sign in to comment.