Skip to content

Commit b07e977

Browse files
hypergonialnovanai
andauthored
Rewrite to use arc (#130)
* Start rewrite * Upgrade moderation Co-authored-by: nova <novanai@users.noreply.github.com> * Update deps * Resume rewrite * Update lockfile * Wrap up rewriting extensions * Make pyright strict (mostly) pass * Remove dead links * Fix uvloop * Convert remaining extensions to arc * Migrate to uv * Migrate to uv * Bump actions * Delete poetry lock * Replace custom context with ResponseProvider * Bump deps * Bump uv lock * Bump docker base image * Build config from env * Fix FF extension * Fix duplicate CI jobs * Fix lints * Include typechecking in CI * Use slim image for fmt check * Add publish workflow * Update README * Fix bugs --------- Co-authored-by: nova <novanai@users.noreply.github.com>
1 parent 0337456 commit b07e977

68 files changed

Lines changed: 4206 additions & 5519 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
.venv
5+
.env

.env_example

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
TOKEN=bot_token_here
22

3+
# Set to true if you want commands to only register in 'DEBUG_GUILDS'
4+
DEV_MODE=false
5+
# If set, tracebacks are sent to this channel
6+
ERROR_LOGGING_CHANNEL=956312277840171028
7+
# If set, DB backups are uploaded to this channel
8+
DB_BACKUP_CHANNEL=956312298941739079
9+
# Debug guilds which management commands will be registered to, comma-separated
10+
DEBUG_GUILDS=861603964642525204
11+
312
POSTGRES_USER=postgres
413
# Leave POSTGRES_HOST as sned-db to use included postgres instance, change if using docker-compose-nodb.
514
POSTGRES_HOST=sned-db
@@ -12,4 +21,4 @@ POSTGRES_VERSION=14
1221
# Used for toxicity filtering
1322
PERSPECTIVE_API_KEY=perspective_api_key_here
1423
# Merriam-Webster Dictionary API key
15-
DICTIONARYAPI_API_KEY=dictionaryapi_api_key_here
24+
DICTIONARYAPI_API_KEY=dictionaryapi_api_key_here

.github/workflows/checks.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
formatting:
13+
runs-on: ubuntu-slim
14+
name: "Check linting and formatting"
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v6
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v8.1.0
21+
with:
22+
version: "0.11"
23+
python-version: "3.14"
24+
25+
- name: Run ruff via nox
26+
run: |
27+
uv run nox -s format
28+
29+
pyright:
30+
runs-on: ubuntu-latest
31+
name: "Check types"
32+
steps:
33+
- uses: actions/checkout@v6
34+
35+
- name: Install uv
36+
uses: astral-sh/setup-uv@v8.1.0
37+
with:
38+
version: "0.11"
39+
python-version: "3.14"
40+
41+
- name: Run pyright via nox
42+
run: |
43+
uv run nox -s pyright

.github/workflows/publish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Publish to Github Container Registry
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
7+
jobs:
8+
push-to-ghcr:
9+
if: github.actor == github.repository_owner
10+
name: Push to Github Container Registry
11+
runs-on: ubuntu-latest
12+
permissions:
13+
packages: write
14+
steps:
15+
# Break up version into major, minor, and patch
16+
- name: Setup | Break up version
17+
id: version
18+
shell: bash
19+
env:
20+
VERSION: ${{ github.ref_name }}
21+
run: |
22+
echo "major=`echo "${VERSION:1}" | cut -d '.' -f 1`" >> $GITHUB_OUTPUT
23+
echo "minor=`echo "${VERSION:1}" | cut -d '.' -f 2`" >> $GITHUB_OUTPUT
24+
echo "patch=`echo "${VERSION:1}" | cut -d '.' -f 3`" >> $GITHUB_OUTPUT
25+
26+
- name: Setup | Login to GHCR
27+
uses: docker/login-action@v4
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ github.token }}
32+
33+
- name: Setup | QEMU
34+
uses: docker/setup-qemu-action@v4
35+
36+
- name: Setup | Docker Buildx
37+
uses: docker/setup-buildx-action@v4
38+
39+
- name: Build & Deploy | Docker image
40+
uses: docker/build-push-action@v7
41+
with:
42+
push: true
43+
tags: |
44+
ghcr.io/${{ github.repository }}:v${{ steps.version.outputs.major }}
45+
ghcr.io/${{ github.repository }}:v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}
46+
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
47+
ghcr.io/${{ github.repository }}:latest

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
# Bot configuration files
132-
config.py
133-
134131
# DB backup files
135132
*.pgdmp
136133
db/backup/
@@ -139,4 +136,4 @@ db/backup/
139136
.directory
140137

141138
# ruff
142-
.ruff_cache/
139+
.ruff_cache/

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
2+
"editor.tabCompletion": "onlySnippets",
23
"python.analysis.autoImportCompletions": true,
4+
"python.analysis.diagnosticMode": "workspace",
35
"editor.formatOnSave": true,
46
"[python]": {
57
"editor.defaultFormatter": "charliermarsh.ruff"
68
},
79
"autoDocstring.docstringFormat": "numpy",
10+
"python.testing.pytestArgs": [
11+
"tests"
12+
],
13+
"makefile.configureOnOpen": false,
814
}

Dockerfile

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
FROM python:3.11-bookworm
1+
FROM ghcr.io/astral-sh/uv:python3.14-bookworm
22

33
ARG postgres_version=14
44

5-
RUN curl -sSL https://install.python-poetry.org | python3 -
6-
ENV PATH "$PATH:/root/.local/bin"
7-
5+
# Install Postgres CLI tools
86
RUN apt-get update && apt-get -y full-upgrade && apt-get install -y lsb-release
97
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
108
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
119
RUN apt-get update
1210
RUN apt-get install -y postgresql-client-${postgres_version}
1311

14-
COPY pyproject.toml poetry.lock ./
12+
WORKDIR /app
13+
14+
# Enable bytecode compilation
15+
ENV UV_COMPILE_BYTECODE=1
16+
17+
# Copy from the cache instead of linking since it's a mounted volume
18+
ENV UV_LINK_MODE=copy
19+
20+
# Install the project's dependencies using the lockfile and settings
21+
RUN --mount=type=cache,target=/root/.cache/uv \
22+
--mount=type=bind,source=uv.lock,target=uv.lock \
23+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
24+
uv sync --frozen --no-install-project --no-dev
25+
26+
# Then, add the rest of the project source code and install it
27+
# Installing separately from its dependencies allows optimal layer caching
28+
ADD . /app
29+
RUN --mount=type=cache,target=/root/.cache/uv \
30+
uv sync --frozen --no-dev
31+
32+
# Place executables in the environment at the front of the path
33+
ENV PATH="/app/.venv/bin:$PATH"
1534

16-
RUN poetry config virtualenvs.create false
17-
RUN poetry install -n --only main --no-root
35+
# Reset the entrypoint, don't invoke `uv`
36+
ENTRYPOINT []
1837

19-
COPY . ./
20-
CMD ["python3.11", "-O", "-m", "src"]
38+
CMD ["python3.14", "-O", "-m", "src"]

Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
55
### [Add it to your server!](https://discord.com/oauth2/authorize?client_id=817730141722902548&permissions=1494984682710&scope=applications.commands%20bot)
66

7-
### Main features:
7+
### Main features
8+
89
- Powerful moderation commands
910
- Intuitive settings menu
1011
- AutoMod
@@ -18,26 +19,21 @@
1819
- Fun commands such as tic-tac-toe and typeracer
1920
- Much much more!
2021

21-
### Sned in action:
22+
### Configuration
2223

23-
| Moderation tools | Settings & configuration | Rolebuttons | Reminders |
24-
| ----------- | ----------- | ----------- | ----------- |
25-
| ![Powerful moderation commands!](https://cdn.discordapp.com/attachments/836300326172229672/952785998138466364/unknown.png) | ![Intuitive Settings and Configuration](https://cdn.discordapp.com/attachments/836300326172229672/952786784666931300/unknown.png) | ![Rolebuttons in action](https://cdn.discordapp.com/attachments/836300326172229672/952789779471294464/unknown.png) | ![Reminder snoozing in action](https://cdn.discordapp.com/attachments/836300326172229672/952790270150320228/unknown.png) |
24+
To get started with setting up the bot on a server you have `Manage Server` permissions on, simply type `/settings`!
2625

27-
### Configuration:
26+
### Selfhosting
2827

29-
To get started with setting up the bot on a server you have `Manage Server` permissions on, simply type `/settings`!
28+
If you'd like to host it locally, install [`docker`](https://www.docker.com/get-started/) and [`docker compose`](https://docs.docker.com/compose/install/). Then, create and fill out `.env`, you can see an example in `.env_example`. Finally, run `docker compose up --build -d` to start the bot in the background along with it's database.
3029

31-
### Development:
30+
### Development
3231

33-
If you'd like to contribute to Sned, or host it locally, you need the following utilities:
32+
You will need the following utilities installed:
3433

35-
- [`make`](https://www.gnu.org/software/make/)
36-
- [`docker`](https://www.docker.com/get-started/)
37-
- [`python`](https://www.python.org/downloads/) - 3.10 or higher
38-
- [`poetry`](https://python-poetry.org/docs/) - for managing python dependencies
34+
- [Python 3.14](https://www.python.org/downloads/)
35+
- [uv](https://docs.astral.sh/uv/getting-started/installation/)
3936

40-
To deploy the bot, create and fill out `.env`, you can see an example in `.env_example`, along with `config.py`, for which you can find an example in `config_example.py`.
41-
Then simply run `make deploy` to start the bot in the background along with it's database.
37+
Install the project with all dependencies by running `uv sync --dev` in the project folder. Then, activate the venv via `source .venv/bin/activate`.
4238

4339
If you'd like to contribute, please make sure to run [`nox`](https://nox.thea.codes/en/stable/index.html) in the project folder before submitting your changes. This should format all your code to match the project.

0 commit comments

Comments
 (0)