Cog-Creators / Cog-Creators/Red-DiscordBot

Auto Updating application.yml for unmanaged lavalink

Open
#6,554 1 comment 0 reactions 0 assignees View on GitHub
Category: Cogs - Audio Category: Docs - User Guides Status: Needs Triage Type: Enhancement
Dominant language
Python
Stars
5.7k
Forks
2.5k
Avg merge
6d 16h
Merged PRs (30d)
1

Description

### What component of Red (cog, command, API) would you like to see improvements on?

Audio (unmanaged lavalink instance)

### Describe the enhancement you're suggesting.

I've been using Red for a few years now, and as of the last 1-2 years, I've noticed that the application.yml constantly needs updating for lavalink. This can be a headache if you are running an unmanaged instance of lavalink. I have two proposals, of how to fix this, both with logging. This would be an update to auto_update.sh mentioned in the docs.

Option 1:

```bash
#!/bin/bash
set -e
cd "$(dirname "$0")"

LOGFILE="./auto_update.log"

echo "[$(date)] --- Starting Lavalink auto-update ---" >> "$LOGFILE"

# Download Lavalink if newer
echo "[$(date)] Checking Lavalink.jar..." >> "$LOGFILE"
curl -s -LOz Lavalink.jar https://github.com/Cog-Creators/Lavalink-Jars/releases/latest/download/Lavalink.jar && \
echo "[$(date)] Lavalink.jar checked/downloaded." >> "$LOGFILE"

# Get latest version from GitHub API
LATEST_VERSION=$(curl -s https://api.github.com/repos/Cog-Creators/Red-DiscordBot/releases/latest | grep '"tag_name":' | cut -d '"' -f4)

# Build YML URL
YML_URL="https://github.com/Cog-Creators/Red-DiscordBot/releases/download/${LATEST_VERSION}/Red-DiscordBot-${LATEST_VERSION}-default-lavalink-application.yml"

echo "[$(date)] Fetching application.yml from $YML_URL" >> "$LOGFILE"
curl -s -L -o application.yml "$YML_URL" && \
echo "[$(date)] application.yml updated to ${LATEST_VERSION}" >> "$LOGFILE"

echo "[$(date)] --- Update complete ---" >> "$LOGFILE"
```

Option 2:

```bash
#!/bin/bash
set -e
cd "$(dirname "$0")"

LOGFILE="./auto_update.log"

echo "[$(date)] --- Starting Lavalink & plugin auto-update ---" >> "$LOGFILE"

# Download Lavalink if it's newer
echo "[$(date)] Checking for updated Lavalink.jar..." | tee -a "$LOGFILE"
curl -s -LOz Lavalink.jar https://github.com/Cog-Creators/Lavalink-Jars/releases/latest/download/Lavalink.jar && \
echo "[$(date)] Lavalink.jar checked/downloaded." | tee -a "$LOGFILE"

# Get the latest YouTube plugin version
LATEST_PLUGIN_VERSION=$(curl -s "https://maven.lavalink.dev/releases/dev/lavalink/youtube/youtube-plugin/maven-metadata.xml" | grep '' | sed -E 's/.*([^<]+)<\/latest>.*/\1/')

YML_FILE="./application.yml"

if [[ -n "$LATEST_PLUGIN_VERSION" ]]; then
echo "[$(date)] Found latest plugin version: $LATEST_PLUGIN_VERSION" | tee -a "$LOGFILE"

CURRENT_VERSION=$(grep -oP 'dev.lavalink.youtube:youtube-plugin:\K[0-9.]+' "$YML_FILE" || echo "none")

if [[ "$CURRENT_VERSION" != "$LATEST_PLUGIN_VERSION" ]]; then
echo "[$(date)] Updating plugin version from $CURRENT_VERSION to $LATEST_PLUGIN_VERSION" | tee -a "$LOGFILE"
sed -i "s|dev.lavalink.youtube:youtube-plugin:.*|dev.lavalink.youtube:youtube-plugin:${LATEST_PLUGIN_VERSION}|" "$YML_FILE"
echo "[$(date)] application.yml updated." | tee -a "$LOGFILE"
else
echo "[$(date)] Plugin version already up-to-date ($CURRENT_VERSION)." | tee -a "$LOGFILE"
fi
else
echo "[$(date)] Failed to retrieve latest plugin version!" | tee -a "$LOGFILE"
fi

echo "[$(date)] --- Update complete ---" | tee -a "$LOGFILE"```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.