Skip to content

Commit e8cbdcd

Browse files
committed
Release version 4.0.0
2 parents 4d455a2 + 9299d14 commit e8cbdcd

27 files changed

+1523
-2826
lines changed

.dockerignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ cython_debug/
146146
.dbeaver
147147
.project
148148
/gallery-dl
149+
.ruff_cache
149150

150151
# Docker Extras
151152
Dockerfile
152153
compose.yaml
153-
poetry.lock
154154
.github
155155
.dockerignore
156156
.env.example
157157
/test
158-
.ruff_cache
158+
.python-version
159+
.gitignore

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DISCORD_TOKEN=<YOUR_TOKEN_HERE>
55
PREFIX=>>
66

77
# Maximum file upload size (in MiB), used by command like /pixiv
8-
MAX_FILE_SIZE=25
8+
MAX_FILE_SIZE=10
99

1010
# Lavalink parameters, used by the Music module
1111
# The Music module will be disabled if LAVALINK_URL is empty
@@ -14,7 +14,7 @@ LAVALINK_PASSWORD=youshallnotpass
1414

1515
# AI related parameters
1616
# The AI module will be disabled if OPENAI_API_KEY or OPENAI_MODEL_NAME is empty
17-
# You can use a random string for OPENAI_API_KEY if you are using text-generation-webui
17+
# You can use a random string for OPENAI_API_KEY if you are using an custom OpenAI-compatible API server
1818
OPENAI_API_KEY=
1919
OPENAI_MODEL_NAME=gpt-3.5-turbo
2020
# If OPENAI_BASE_URL is empty, use OpenAI API endpoint instead

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM python:3.11 AS compile-image
3+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS compile-image
44

55
WORKDIR /app
66

7-
COPY init.sh requirements.txt ./
7+
COPY . .
88

99
RUN chmod u+x ./init.sh && \
1010
./init.sh
1111

1212
FROM python:3.11-slim AS build-image
13-
COPY --from=compile-image /opt/venv /opt/venv
1413
COPY --from=compile-image /bin/ffmpeg /bin/ffmpeg
15-
16-
# Override system Python with the one in venv
17-
ENV PATH=/opt/venv/bin:$PATH \
18-
XDG_CACHE_HOME=/app/volume
14+
COPY --from=compile-image /app /app
1915

2016
WORKDIR /app
2117

22-
COPY . .
18+
# Set XDG_CACHE_HOME for gallery-dl usage
19+
ENV XDG_CACHE_HOME=/app/volume
2320

2421
RUN useradd nonroot && \
2522
printf "[safe]\ndirectory = /app" >/etc/gitconfig && \
2623
mkdir gallery-dl && \
24+
# Use `chmod 777` here instead of `chown nonroot` in case user wants to use their own docker user
2725
chmod -R 777 ./
2826

2927
USER nonroot
3028

31-
CMD ["python", "-u", "main.py"]
29+
CMD ["/app/.venv/bin/python", "-m", "my_discord_bot"]

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,33 @@ This Discord bot is developed with Python 3.11. Use the same Python version to e
1212

1313
2. Rename `.env.example` to `.env` and put your Discord token inside.
1414

15-
3. Create a virtual python environment and install dependencies from `requirements.txt`.
15+
3. Create a virtual python environment, activate it, then install dependencies with `pip install -e .`.
1616

17-
4. Run `python main.py` in your console to start up the bot.
17+
4. Run `python -m my_discord_bot` in your console to start up the bot.
1818

1919
5. To use the music player, you need to run a [Lavalink](https://github.com/freyacodes/Lavalink) instance alongside the bot. Set `LAVALINK_URL` and `LAVALINK_PASSWORD` in `.env`.
2020

2121
Example config file (`application.yml`) for Lavalink:
2222

2323
```yaml
24-
server:
24+
server:
2525
port: 2333
2626
address: 0.0.0.0
2727
plugins:
2828
youtube:
2929
enabled: true
30-
clients:
31-
- MUSIC
32-
- ANDROID
33-
- WEB
34-
- TVHTML5EMBEDDED
30+
clients: ["MUSIC", "WEB", "MWEB", "WEBEMBEDDED", "ANDROID_MUSIC", "ANDROID_VR", "TV", "TVHTML5EMBEDDED"]
31+
oauth:
32+
enabled: true
33+
refreshToken: <Redacted>
3534
lavalink:
3635
plugins:
3736
# See https://github.com/lavalink-devs/youtube-source for the latest version of the plugin
38-
- dependency: "dev.lavalink.youtube:youtube-plugin:1.3.0"
37+
- dependency: "dev.lavalink.youtube:youtube-plugin:1.11.4"
3938
server:
4039
password: "youshallnotpass"
4140
sources:
42-
youtube: false
41+
youtube: fals
4342
```
4443
4544
6. To use the AI chat command, set `OPENAI_API_KEY` and `OPENAI_MODEL_NAME` in `.env`.
@@ -53,7 +52,7 @@ Note: The `latest` tag refers to the latest stable version.
5352
## Features
5453

5554
1. A music player to play Youtube videos in any voice channel (requires a Lavalink server)
56-
2. Chat with AI (requires an OpenAI compatible API endpoint, e.g. [text-generation-webui](https://github.com/oobabooga/text-generation-webui))
55+
2. Chat with AI (requires an OpenAI compatible API server, e.g. [tabbyAPI](https://github.com/theroyallab/tabbyAPI))
5756
3. A bunch of other commands I created for my needs...
5857

5958
## TODO List
@@ -64,6 +63,7 @@ Note: The `latest` tag refers to the latest stable version.
6463
- [ ] AI.draw: Add [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) support
6564
- [ ] Allow passing arguments to FFMPEG (for hardware acceleration)
6665
- [ ] Allow bot owner to run every command (including admin only commands)
66+
- [ ] Setup migration with alembic
6767

6868
## Notable commands
6969

compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ services:
77
# Used by old style prefix commands; this bot only has the <PREFIX>sync prefix command
88
PREFIX: ">>"
99
# Maximum file upload size (in MiB), used by command like /pixiv
10-
MAX_FILE_SIZE: 25
10+
MAX_FILE_SIZE: 10
1111
# Lavalink parameters, used by the Music module
1212
# The Music module will be disabled if LAVALINK_URL is empty
1313
LAVALINK_URL: http://lavalink:2333
1414
LAVALINK_PASSWORD: youshallnotpass
1515
# AI related parameters
1616
# The AI module will be disabled if OPENAI_API_KEY or OPENAI_MODEL_NAME is empty
17-
# You can use a random string for OPENAI_API_KEY if you are using text-generation-webui
17+
# You can use a random string for OPENAI_API_KEY if you are using an custom OpenAI-compatible API server
1818
OPENAI_API_KEY:
1919
OPENAI_MODEL_NAME: gpt-3.5-turbo
2020
# If OPENAI_BASE_URL is empty, use OpenAI API endpoint instead

init.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ apt -y update
66
apt install -y --no-install-recommends curl xz-utils
77

88
dir_name=ffmpeg
9-
mkdir $dir_name
10-
pushd $dir_name
9+
mkdir ../$dir_name
10+
pushd ../$dir_name
1111

12-
# Download compiled binaries and perform filehash checking
12+
# Download compiled FFMPEG binary and perform filehash checking
1313
# TODO: Build a static FFMPEG instead of downloading
1414
xz_name=$(
1515
curl -JOL https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz \
@@ -21,19 +21,13 @@ md5_name=$(
2121
)
2222
md5sum -c "$md5_name"
2323

24-
# Extract the archive
25-
mkdir $dir_name
26-
tar xvf "$xz_name" -C "$dir_name" --strip-components 1
27-
cd $dir_name
28-
29-
# Move it to PATH
24+
# Extract the archive and move FFMPEG to PATH
25+
tar xvf "$xz_name" --strip-components 1
3026
mv ffmpeg /bin/ffmpeg
3127

3228
popd
3329

3430
# Install Python dependencies
35-
python -m venv /opt/venv
36-
PATH=/opt/venv/bin:$PATH
37-
pip install -r requirements.txt --no-cache-dir
31+
uv sync
3832

3933
exit 0

0 commit comments

Comments
 (0)