Skip to content

Commit

Permalink
Merge pull request #455 from thijsvanloef/add-support-for-mentions
Browse files Browse the repository at this point in the history
Discord: Add support for Mentions
  • Loading branch information
thijsvanloef authored Feb 27, 2024
2 parents 63ff093 + a7f2d03 commit 2066bf0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
4 changes: 4 additions & 0 deletions docusaurus/docs/guides/discord/discord-webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ send discord messages with docker compose:
- DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1234567890/abcde
- DISCORD_PRE_UPDATE_BOOT_MESSAGE=Server is updating...
```
:::tip
You can mention people in the messages by adding `<@user_id>` in the message!
:::
12 changes: 6 additions & 6 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 "Creating backup..." "in-progress"
DiscordMessage "Backup" "Creating backup..." "in-progress"
if [ "${RCON_ENABLED,,}" = true ]; then
save_server
fi
Expand All @@ -18,26 +18,26 @@ if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$FILE_PATH"
fi
LogInfo "Backup created at ${FILE_PATH}"
DiscordMessage "Backup created at ${FILE_PATH}" "success"
DiscordMessage "Backup" "Backup created at ${FILE_PATH}" "success"

if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then
exit 0
fi

if [ -z "${OLD_BACKUP_DAYS}" ]; then
LogWarn "Unable to delete old backups, OLD_BACKUP_DAYS is empty."
DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn"
DiscordMessage "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn"
exit 0
fi

if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then
LogAction "Removing Old Backups"
LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days"
DiscordMessage "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress"
DiscordMessage "Backup" "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress"
find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete
DiscordMessage "Removed backups older than ${OLD_BACKUP_DAYS} days" "success"
DiscordMessage "Backup" "Removed backups older than ${OLD_BACKUP_DAYS} days" "success"
exit 0
fi

LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}"
DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure"
DiscordMessage "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure"
7 changes: 4 additions & 3 deletions scripts/discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ DISCORD_RED=14614528
DISCORD_GREEN=52224

# Parse arguments
MESSAGE=$1
LEVEL=$2
TITLE=$1
MESSAGE=$2
LEVEL=$3

if [ -n "${DISCORD_CONNECT_TIMEOUT}" ] && [[ "${DISCORD_CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then
CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT
Expand Down Expand Up @@ -56,6 +57,6 @@ else
COLOR=$DISCORD_BLUE
fi

JSON=$(jo embeds[]="$(jo title="$MESSAGE" color=$COLOR)")
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"
7 changes: 4 additions & 3 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ Log() {
# Send Discord Message
# Level is optional variable defaulting to info
DiscordMessage() {
local message="$1"
local level="$2"
local title="$1"
local message="$2"
local level="$3"
if [ -z "$level" ]; then
level="info"
fi
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "$message" "$level" &
/home/steam/server/discord.sh "$title" "$message" "$level" &
fi
}

Expand Down
12 changes: 6 additions & 6 deletions scripts/helper_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ UpdateRequired() {

if [ "$http_code" -ne 200 ]; then
LogError "There was a problem reaching the Steam api. Unable to check for updates!"
DiscordMessage "There was a problem reaching the Steam api. Unable to check for updates!" "failure"
DiscordMessage "Install" "There was a problem reaching the Steam api. Unable to check for updates!" "failure"
rm "$temp_file"
return 2
fi
Expand All @@ -75,7 +75,7 @@ UpdateRequired() {

if [ -z "$LATEST_MANIFEST" ]; then
LogError "The server response does not contain the expected BuildID. Unable to check for updates!"
DiscordMessage "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure"
DiscordMessage "Install" "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure"
return 2
fi

Expand Down Expand Up @@ -115,19 +115,19 @@ UpdateRequired() {
InstallServer() {

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

local targetManifest
targetManifest="${TARGET_MANIFEST_ID}"

LogWarn "Installing Target Version: $targetManifest"
DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress"
DiscordMessage "Install" "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress"
/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 "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success"
DiscordMessage "Install" "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success"
}
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 "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress"
DiscordMessage "Shutdown" "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress"

if ! shutdown_server; then
# Does not save
Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ if [ "${ENABLE_PLAYER_LOGGING,,}" = true ] && [[ "${PLAYER_LOGGING_POLL_PERIOD}"
fi

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

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

DiscordMessage "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure"
DiscordMessage "Start" "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure"
exit 0
6 changes: 3 additions & 3 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ fi

if [ "${UPDATE_ON_BOOT,,}" != true ]; then
LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating"
DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn"
DiscordMessage "Update" "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn"
exit 1
fi

if [ "${RCON_ENABLED,,}" != true ]; then
LogWarn "An update is available however auto updating without rcon is not supported"
DiscordMessage "An update is available however auto updating without rcon is not supported" "warn"
DiscordMessage "Update" "An update is available however auto updating without rcon is not supported" "warn"
exit 1
fi

if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
DiscordMessage "Update" "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
fi

countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server will update"
Expand Down

0 comments on commit 2066bf0

Please sign in to comment.