-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from satisfactorymodding/dev
v2.21.0
- Loading branch information
Showing
39 changed files
with
719 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Keep shell files as LF so Windows-host-machine users can still use Docker | ||
*.sh text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ celerybeat.pid | |
|
||
# Environments | ||
.env | ||
!example.env | ||
.venv | ||
.run/ | ||
env/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,73 @@ | ||
# FICSIT-Fred | ||
|
||
A Discord bot for the Satisfactory Modding Discord | ||
|
||
Thanks to Illya, creator of the bot ! | ||
## Development | ||
|
||
Want to contribute to Fred? Here's everything you need to know to get started. | ||
|
||
### Prerequisites | ||
|
||
#### A Discord token | ||
|
||
First of all, you'll need a Discord bot token for Fred to connect to Discord with. | ||
To get one, you can go to <https://discord.com/developers/applications>, register a new application, add a bot to the application and **activate the "message content intent"**. | ||
This intent is needed to receive the content of messages. | ||
Fred doesn't use slash commands so this is simply needed for him to function. | ||
|
||
#### Docker | ||
|
||
Docker is for making containers. If you're not sure what that means, look it up it's real cool! In our case, it helps use set up all needed dependencies for Fred without you needing to do anything other than install Docker. | ||
You can get docker [here](https://docs.docker.com/engine/install/). For Linux, make sure to **not** use Docker Desktop. For Windows, it is the easiest way. | ||
If you don't want to install Docker (especially on Windows where Docker Desktop can take up resources and requires virtualisation to be enabled), you can also manually set up a PostgreSQL DB and configure Fred to point to it. More on that later. | ||
|
||
#### (Optional) Dialogflow auth | ||
|
||
This is optional because this feature is currently disabled in Fred. | ||
You'll have get authentication information for dialogflow if you want to work on that. | ||
|
||
### Setup | ||
|
||
Two choices here: All through docker or hybrid local/docker. | ||
I recommend the hybrid way for ease of development. We don't have a proper devcontainer setup so debugging Fred when running in Docker is not great. | ||
Instead, in a hybrid setup, you'll use Docker for the postgres DB only and run Fred locally using Poetry. | ||
|
||
#### Docker-only | ||
|
||
Run `FRED_TOKEN=<your_token> docker compose up -d` and that's it! Fred should run. | ||
(Note: This command assumes you're using bash as your shell. For Powershell or other, set the environment variable differently). | ||
|
||
You can verify that the database was properly created and manage it by going to <http://localhost:8080> where pgadmin should show. | ||
You can use `[email protected]` for the user and `fred` for the password. All of this is customizable in `docker-compose.yml`. | ||
|
||
#### Hybrid | ||
|
||
For this, you'll need [poetry](https://python-poetry.org/) installed, as well as `libpq` for the connection to the postgres DB. | ||
For libpq, you can install `libpq-dev` (or equivalent) on linux and [install postgres](https://www.postgresql.org/download/windows/) on Windows (test without it first actually I'm not certain this is needed). | ||
|
||
Once Poetry is installed, run `poetry install`. This should create a `.venv` folder that contains the virtualenv with all the necessary packages. Activate it using `poetry shell` or manually. | ||
|
||
Now, run `docker compose up -d -f docker-compose-deps.yml`. This should spin up the postgres DB. | ||
You can verify that the database was properly created and manage it by going to <http://localhost:8080> where pgadmin should show. | ||
You can use `[email protected]` for the user and `fred` for the password. All of this is customizable in `docker-compose-deps.yml`. | ||
|
||
Almost there! You'll now have to configure Fred. This just means setting the following env vars (found in `fred/__main__.py`). | ||
|
||
```sh | ||
"FRED_IP", | ||
"FRED_PORT", | ||
"FRED_TOKEN", | ||
"FRED_SQL_DB", | ||
"FRED_SQL_USER", | ||
"FRED_SQL_PASSWORD", | ||
"FRED_SQL_HOST", | ||
"FRED_SQL_PORT", | ||
``` | ||
|
||
For convenience, a `.env` file is included and Fred will load them automatically. It includes defaults that will work with the config of the docker-compose-deps.yml. You'll only have to set `FRED_TOKEN` and maybe change the others if the defaults don't suit you. | ||
|
||
Finally, run `python fred/__main__.py`. Fred should run! You can now adapt this to your setup and run the script from your IDE instead. Don't forget to use the virtualenv python! | ||
|
||
## Thanks | ||
|
||
Massive thanks to Borketh, Mircea and everyone else that has contributed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// https://cspell.org/configuration/ | ||
{ | ||
// Version of the setting file. Always 0.2 | ||
"version": "0.2", | ||
// language - current active spelling language | ||
"language": "en", | ||
// words - list of words to be always considered correct | ||
"words": [ | ||
"FICSIT", | ||
"libpq", | ||
"Mircea", | ||
"pgadmin", | ||
"virtualenv" | ||
], | ||
// flagWords - list of words to be always considered incorrect | ||
// This is useful for offensive words and common spelling errors. | ||
// cSpell:disable (don't complain about the words we listed here) | ||
"flagWords": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
postgres: | ||
image: postgres:14.0-alpine | ||
environment: | ||
POSTGRES_PASSWORD: fred | ||
POSTGRES_USER: fred | ||
PGDATA: /var/lib/postgresql/data/pgdata | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- pgdata:/var/lib/postgresql/data/pgdata:z | ||
- ./docker/exampledb.sql:/docker-entrypoint-initdb.d/exampledb.sql | ||
|
||
pgadmin: | ||
depends_on: | ||
- postgres | ||
image: dpage/pgadmin4:6 | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: '[email protected]' | ||
PGADMIN_DEFAULT_PASSWORD: 'fred' | ||
ports: | ||
- "8080:80" | ||
|
||
volumes: | ||
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: '3' | ||
services: | ||
fred: | ||
depends_on: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
FROM python:3.10-slim as runtime | ||
FROM python:3.12-alpine AS runtime | ||
#FROM python:3.12-slim AS runtime | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
VOLUME /config | ||
WORKDIR /app | ||
|
||
COPY docker/runtime-deps.sh . | ||
RUN bash runtime-deps.sh 1> /dev/null && rm runtime-deps.sh | ||
RUN apk update; apk add --no-cache tesseract-ocr-data-eng | ||
#ENV DEBIAN_FRONTEND=noninteractive APT="apt-get -qq" | ||
#RUN $APT update; \ | ||
# $APT install tesseract-ocr; \ | ||
# $APT clean; \ | ||
# rm -rf /var/lib/apt/lists/* | ||
|
||
FROM python:3.10-slim as build | ||
FROM python:3.12-alpine AS build | ||
#FROM python:3.12-slim AS build | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get -qq update && apt-get -qq install curl libpq-dev gcc 1> /dev/null | ||
WORKDIR /deps | ||
|
||
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr/local python3 - | ||
RUN pip --no-cache-dir install --progress-bar=off "poetry==1.8" | ||
|
||
COPY pyproject.toml . | ||
RUN poetry install -nvvv --no-dev && mv $(poetry env info --path) /app/venv | ||
COPY poetry.lock . | ||
RUN poetry install -nvvv --only main --no-root; mv $(poetry env info --path) ./venv | ||
|
||
FROM runtime | ||
|
||
COPY --from=build /app/venv /app/venv | ||
COPY fred *.env ./fred/ | ||
COPY --from=build /deps/venv ./venv | ||
COPY fred ./fred/ | ||
COPY *.env . | ||
|
||
CMD ./venv/bin/python3 -m fred |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FRED_IP=:: | ||
FRED_PORT=80 | ||
FRED_SQL_DB=fred | ||
FRED_SQL_USER=fred | ||
FRED_SQL_PASSWORD=fred | ||
FRED_SQL_HOST=0.0.0.0 | ||
FRED_SQL_PORT=5432 | ||
FRED_LOG_LEVEL=DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
from .fred import __version__ | ||
import logging | ||
from os import getenv | ||
|
||
from dotenv import load_dotenv | ||
|
||
logging.root = logging.getLogger("FRED") | ||
logging.basicConfig(level=getenv("FRED_LOG_LEVEL", logging.DEBUG)) | ||
|
||
from .fred import __version__ # noqa | ||
|
||
logging.root.debug(f"HELLO WORLD!!! FRED version: {__version__}") | ||
|
||
ENVVARS = ( | ||
"FRED_IP", | ||
"FRED_PORT", | ||
"FRED_TOKEN", | ||
"FRED_SQL_DB", | ||
"FRED_SQL_USER", | ||
"FRED_SQL_PASSWORD", | ||
"FRED_SQL_HOST", | ||
"FRED_SQL_PORT", | ||
# "DIALOGFLOW_AUTH", | ||
) | ||
|
||
load_dotenv() | ||
|
||
for var in ENVVARS: | ||
if getenv(var) is None: | ||
raise EnvironmentError(f"The ENV variable '{var}' isn't set") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.