Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more flexibility in discord webhooks #490

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RUN case ${TARGETARCH} in \
&& chmod +x supercronic \
&& mv supercronic /usr/local/bin/supercronic

# hadolint ignore=DL3044
ENV HOME=/home/steam \
PORT= \
PUID=1000 \
Expand Down Expand Up @@ -103,12 +104,41 @@ ENV HOME=/home/steam \
DISCORD_CONNECT_TIMEOUT=30 \
DISCORD_MAX_TIMEOUT=30 \
DISCORD_PRE_UPDATE_BOOT_MESSAGE="Server is updating..." \
DISCORD_PRE_UPDATE_BOOT_MESSAGE_URL= \
DISCORD_PRE_UPDATE_BOOT_MESSAGE_ENABLED=true \
DISCORD_POST_UPDATE_BOOT_MESSAGE="Server update complete!" \
DISCORD_POST_UPDATE_BOOT_MESSAGE_URL= \
DISCORD_POST_UPDATE_BOOT_ENABLED=true \
DISCORD_PRE_START_MESSAGE="Server has been started!" \
DISCORD_PRE_START_MESSAGE_URL= \
DISCORD_PRE_START_MESSAGE_ENABLED=true \
DISCORD_PRE_SHUTDOWN_MESSAGE="Server is shutting down..." \
DISCORD_PRE_SHUTDOWN_MESSAGE_URL= \
DISCORD_PRE_SHUTDOWN_MESSAGE_ENABLED=true \
DISCORD_POST_SHUTDOWN_MESSAGE="Server has been stopped!" \
DISCORD_POST_SHUTDOWN_MESSAGE_URL= \
DISCORD_POST_SHUTDOWN_MESSAGE_ENABLED=true \
DISCORD_PLAYER_JOIN_MESSAGE="\${player_name} has joined Palworld!" \
DISCORD_PLAYER_JOIN_MESSAGE_URL= \
DISCORD_PLAYER_JOIN_MESSAGE_ENABLED=true \
DISCORD_PLAYER_LEAVE_MESSAGE="\${player_name} has left Palworld." \
DISCORD_PLAYER_LEAVE_MESSAGE_URL= \
DISCORD_PLAYER_LEAVE_MESSAGE_ENABLED=true \
DISCORD_PRE_BACKUP_MESSAGE="Creating backup..." \
DISCORD_PRE_BACKUP_MESSAGE_URL= \
DISCORD_PRE_BACKUP_MESSAGE_ENABLED=true \
DISCORD_POST_BACKUP_MESSAGE="Backup created at \${FILE_PATH}" \
DISCORD_POST_BACKUP_MESSAGE_URL= \
DISCORD_POST_BACKUP_MESSAGE_ENABLED=true \
DISCORD_PRE_BACKUP_DELETE_MESSAGE="Removing backups older than \${OLD_BACKUP_DAYS} days" \
DISCORD_PRE_BACKUP_DELETE_URL= \
DISCORD_PRE_BACKUP_DELETE_ENABLED=true \
DISCORD_POST_BACKUP_DELETE_MESSAGE="Removed backups older than \${OLD_BACKUP_DAYS} days" \
DISCORD_POST_BACKUP_DELETE_URL= \
DISCORD_POST_BACKUP_DELETE_ENABLED=true \
DISCORD_ERR_BACKUP_DELETE_MESSAGE="Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=\${OLD_BACKUP_DAYS}" \
DISCORD_ERR_BACKUP_DELETE_URL= \
DISCORD_ERR_BACKUP_DELETE_ENABLED=true \
ENABLE_PLAYER_LOGGING=true \
PLAYER_LOGGING_POLL_PERIOD=5 \
ARM_COMPATIBILITY_MODE=false \
Expand Down
247 changes: 138 additions & 109 deletions README.md

Large diffs are not rendered by default.

121 changes: 75 additions & 46 deletions docusaurus/docs/getting-started/configuration/server-settings.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

DiscordMessage "Backup" "Creating backup..." "in-progress"
DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_MESSAGE}" "in-progress" "${DISCORD_PRE_BACKUP_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_MESSAGE_URL}"
if [ "${RCON_ENABLED,,}" = true ]; then
save_server
fi
Expand All @@ -18,7 +18,7 @@ if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$FILE_PATH"
fi
LogInfo "Backup created at ${FILE_PATH}"
DiscordMessage "Backup" "Backup created at ${FILE_PATH}" "success"
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_MESSAGE_URL}"

if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then
exit 0
Expand All @@ -33,11 +33,11 @@ fi
if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then
LogAction "Removing Old Backups"
LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days"
DiscordMessage "Backup" "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress"
DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "in-progress" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_URL}"
find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete
DiscordMessage "Backup" "Removed backups older than ${OLD_BACKUP_DAYS} days" "success"
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_URL}"
exit 0
fi

LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}"
DiscordMessage "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure"
DiscordMessage "Backup" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE//\$\{OLD_BACKUP_DAYS\}/${OLD_BACKUP_DAYS}}}" "failure" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_URL}"
14 changes: 12 additions & 2 deletions scripts/discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ DISCORD_GREEN=52224
TITLE=$1
MESSAGE=$2
LEVEL=$3
ENABLED=$4
URL=$5

if [ -n "${DISCORD_CONNECT_TIMEOUT}" ] && [[ "${DISCORD_CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then
CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT
Expand Down Expand Up @@ -58,5 +60,13 @@ else
fi

JSON=$(jo embeds[]="$(jo title="$TITLE" description="$MESSAGE" color=$COLOR)")
LogInfo "Sending Discord json: ${JSON}"
curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK_URL"

if [ "$ENABLED" = true ]; then
if [ "$URL" == "" ]; then
DISCORD_URL="$DISCORD_WEBHOOK_URL"
else
DISCORD_URL="$URL"
fi
LogInfo "Sending Discord json: ${JSON}"
curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_URL"
fi
4 changes: 3 additions & 1 deletion scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ DiscordMessage() {
local title="$1"
local message="$2"
local level="$3"
local enabled="$4"
local webhook_url="$5"
if [ -z "$level" ]; then
level="info"
fi
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "$title" "$message" "$level" &
/home/steam/server/discord.sh "$title" "$message" "$level" "$enabled" "$webhook_url" &
fi
}

Expand Down
8 changes: 4 additions & 4 deletions scripts/helper_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ InstallServer() {
fi

if [ -z "${TARGET_MANIFEST_ID}" ]; then
DiscordMessage "Install" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress"
DiscordMessage "Install" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE_ENABLED}" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE_URL}"
/home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit
DiscordMessage "Install" "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success"
DiscordMessage "Install" "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" "${DISCORD_POST_UPDATE_BOOT_MESSAGE_ENABLED}" "${DISCORD_POST_UPDATE_BOOT_MESSAGE_URL}"
return
fi

local targetManifest
targetManifest="${TARGET_MANIFEST_ID}"

LogWarn "Installing Target Version: $targetManifest"
DiscordMessage "Install" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress"
DiscordMessage "Install" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE_ENABLED}" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE_URL}"
/home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +download_depot 2394010 2394012 "$targetManifest" +quit
cp -vr "/home/steam/steamcmd/linux32/steamapps/content/app_2394010/depot_2394012/." "/palworld/"
CreateACFFile "$targetManifest"
DiscordMessage "Install" "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success"
DiscordMessage "Install" "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" "${DISCORD_POST_UPDATE_BOOT_MESSAGE_ENABLED}" "${DISCORD_POST_UPDATE_BOOT_MESSAGE_URL}"
}
2 changes: 1 addition & 1 deletion scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mkdir -p /palworld/backups

# shellcheck disable=SC2317
term_handler() {
DiscordMessage "Shutdown" "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress"
DiscordMessage "Shutdown" "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" "${DISCORD_PRE_SHUTDOWN_MESSAGE_ENABLED}" "${DISCORD_PRE_SHUTDOWN_MESSAGE_URL}"

if ! shutdown_server; then
# Does not save
Expand Down
4 changes: 2 additions & 2 deletions scripts/player_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ while true; do
broadcast_command "${player_name} has left"

# Replace ${player_name} with actual player's name
DiscordMessage "Player Left" "${DISCORD_PLAYER_LEAVE_MESSAGE//\$\{player_name\}/${player_name}}" "failure"
DiscordMessage "Player Left" "${DISCORD_PLAYER_LEAVE_MESSAGE//\$\{player_name\}/${player_name}}" "failure" "${DISCORD_PLAYER_LEAVE_MESSAGE_ENABLED}" "${DISCORD_PLAYER_LEAVE_MESSAGE_URL}"
done

# Notify Discord and log all players who have joined
Expand All @@ -58,7 +58,7 @@ while true; do
broadcast_command "${player_name} has joined"

# Replace ${player_name} with actual player's name
DiscordMessage "Player Joined" "${DISCORD_PLAYER_JOIN_MESSAGE//\$\{player_name\}/${player_name}}" "success"
DiscordMessage "Player Joined" "${DISCORD_PLAYER_JOIN_MESSAGE//\$\{player_name\}/${player_name}}" "success" "${DISCORD_PLAYER_JOIN_MESSAGE_ENABLED}" "${DISCORD_PLAYER_JOIN_MESSAGE_URL}"
done

old_player_list=("${current_player_list[@]}")
Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ if [ "${ENABLE_PLAYER_LOGGING,,}" = true ] && [[ "${PLAYER_LOGGING_POLL_PERIOD}"
fi

LogAction "Starting Server"
DiscordMessage "Start" "${DISCORD_PRE_START_MESSAGE}" "success"
DiscordMessage "Start" "${DISCORD_PRE_START_MESSAGE}" "success" "${DISCORD_PRE_START_MESSAGE_ENABLED}" "${DISCORD_PRE_START_MESSAGE_URL}"

echo "${STARTCOMMAND[*]}"
"${STARTCOMMAND[@]}"

DiscordMessage "Stop" "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure"
DiscordMessage "Stop" "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" "${DISCORD_POST_SHUTDOWN_MESSAGE_ENABLED}" "${DISCORD_POST_SHUTDOWN_MESSAGE_URL}"
exit 0