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

Add max toot length check / toot truncation #13

Merged
merged 23 commits into from
Jun 17, 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
4 changes: 2 additions & 2 deletions buildnow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
[[ "$ARCHS" == "" ]] && ARCHS="linux/armhf,linux/arm64,linux/amd64"

BASETARGET1=ghcr.io/sdr-enthusiasts
BASETARGET2=kx1t
#BASETARGET2=kx1t

IMAGE1="$BASETARGET1/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"
IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"
#IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"


echo "press enter to start building $IMAGE1 from $BRANCH"
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/10-container-init
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091
# shellcheck shell=bash disable=SC1091,SC2154
source /scripts/common

"${s6wrap[@]}" echo "[INFO] Starting VesselAlert version $(cat /.CONTAINER_VERSION)"
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/40-check-ais-notify
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091
# shellcheck shell=bash disable=SC1091,SC2154

# Check to make sure the correct parameters are defined.
#---------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/60-check-mastodon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC2015,SC1091
#shellcheck shell=bash disable=SC2015,SC1091,SC2154

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/80-tropoalert-init
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091
# shellcheck shell=bash disable=SC1091,SC2154
source /scripts/common

if ! chk_enabled "${TROPOALERT:-enabled}"; then
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/ais-collect
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck disable=SC2016,SC2068,SC2076,SC2086,SC2015,SC2164,SC1090,SC1091
#shellcheck disable=SC2016,SC2068,SC2076,SC2086,SC2015,SC2164,SC1090,SC1091,SC2154

# AIS-Collect:
# read AIS data from a AIS-Catcher web service and
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/tropo-alert
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck disable=SC2015,SC1090,SC2164,SC2001,SC1091
#shellcheck disable=SC2015,SC1090,SC2164,SC2001,SC1091,SC2154

# AIS Tropo Alert
# Based on, and improved upon AISTropoAlert by Jeffrey Luszcz
Expand Down
1 change: 1 addition & 0 deletions rootfs/healthcheck/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/command/with-contenv bash
# shellcheck shell=bash

#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
Expand Down
4 changes: 2 additions & 2 deletions rootfs/opt/data/masto-l10n-de_DE.db
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ MASTO_TERM[SPEED]="Geschwindigkeit"
MASTO_TERM[HEADING]="Richtung"
MASTO_TERM[DESTINATION]="Reiseziel"
MASTO_TERM[SIGNAL]="Signal"
MASTO_TERM[LOCATION]="Schiffsstandort"
MASTO_TERM[LOCATION]="Schiffsangaben"
MASTO_TERM[ISMOVING]="is unterwegs"
MASTO_TERM[ISSEENON]="beobachtet um"
MASTO_TERM[AGAIN]="Wiederholung:"
MASTO_TERM[NEW2]="Neu:"
MASTO_TERM[DIST_SINCE_LAST]="hat sich seit der letzten Meldung um %.1f sm bewegt"
MASTO_TERM[DISTANCE]="Entfernung vom Empfänger"
MASTO_TERM[DISTANCE]="Entfernung"
4 changes: 2 additions & 2 deletions rootfs/opt/data/masto-l10n-en_US.db
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ MASTO_TERM[SPEED]="Speed"
MASTO_TERM[HEADING]="Heading"
MASTO_TERM[DESTINATION]="Destination"
MASTO_TERM[SIGNAL]="Signal"
MASTO_TERM[LOCATION]="Vessel location"
MASTO_TERM[LOCATION]="Details"
MASTO_TERM[ISMOVING]="is on the move"
MASTO_TERM[ISSEENON]="is seen on"
MASTO_TERM[AGAIN]="Again:"
MASTO_TERM[NEW2]="New:"
MASTO_TERM[DIST_SINCE_LAST]="moved %.1f nm since last notification"
MASTO_TERM[DISTANCE]="Distance from receiver"
MASTO_TERM[DISTANCE]="Distance"
6 changes: 3 additions & 3 deletions rootfs/opt/data/masto-l10n-es_ES.db
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ MASTO_TERM[CALLSIGN]="Indicativo"
MASTO_TERM[SHIPTYPE]="Tipo"
MASTO_TERM[FLAG]="Bandera"
MASTO_TERM[MSGS_RECVD]="Mensajes Recibidos"
MASTO_TERM[SEEN_ON]="Visto últimamente"
MASTO_TERM[SEEN_ON]="Visto últ."
MASTO_TERM[STATUS]="Estado"
MASTO_TERM[SPEED]="Velocidad"
MASTO_TERM[HEADING]="Rumbo"
MASTO_TERM[DESTINATION]="Destino"
MASTO_TERM[SIGNAL]="Señal"
MASTO_TERM[LOCATION]="Ubicacion del barco"
MASTO_TERM[LOCATION]="Detalles"
MASTO_TERM[ISMOVING]="está en marcha"
MASTO_TERM[ISSEENON]="fue visto a la hora"
MASTO_TERM[AGAIN]="Nuevamente:"
MASTO_TERM[NEW2]="Nuevo:"
MASTO_TERM[DIST_SINCE_LAST]="se ha transladado %.1f nm desde la última notificación"
MASTO_TERM[DISTANCE]="Distancia del receptor"
MASTO_TERM[DISTANCE]="Distancia"
4 changes: 2 additions & 2 deletions rootfs/opt/data/masto-l10n-fr_FR.db
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ MASTO_TERM[SPEED]="Vitesse"
MASTO_TERM[HEADING]="Cap"
MASTO_TERM[DESTINATION]="Destination"
MASTO_TERM[SIGNAL]="Signal"
MASTO_TERM[LOCATION]="Localisation du navire"
MASTO_TERM[LOCATION]="Détails"
MASTO_TERM[ISMOVING]="est en mouvement"
MASTO_TERM[ISSEENON]="est vu à"
MASTO_TERM[AGAIN]="A nouveau:"
MASTO_TERM[NEW2]="Nouveau:"
MASTO_TERM[DIST_SINCE_LAST]="déplacé de %.1f nm depuis la dernière notification"
MASTO_TERM[DISTANCE]="Distance du récepteur"
MASTO_TERM[DISTANCE]="Distance"
4 changes: 2 additions & 2 deletions rootfs/opt/data/masto-l10n-nl_NL.db
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ MASTO_TERM[SPEED]="Snelheid"
MASTO_TERM[HEADING]="Richting"
MASTO_TERM[DESTINATION]="Doel"
MASTO_TERM[SIGNAL]="Signaal"
MASTO_TERM[LOCATION]="Schip locatie"
MASTO_TERM[LOCATION]="Details"
MASTO_TERM[ISMOVING]="is onderweg"
MASTO_TERM[ISSEENON]="is gezien om"
MASTO_TERM[AGAIN]="Herhaling:"
MASTO_TERM[NEW2]="Nieuw:"
MASTO_TERM[DIST_SINCE_LAST]="%.1f nm verplaatst sinds de vorige notificatie"
MASTO_TERM[DISTANCE]="Afstand van ontvanger"
MASTO_TERM[DISTANCE]="Afstand"
2 changes: 1 addition & 1 deletion rootfs/tools/force_notify
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/command/with-contenv bash
#shellcheck shell=bash
#shellcheck disable=SC1090,SC2015,SC1091
#shellcheck disable=SC1090,SC2015,SC1091,SC2302,SC2303

# AIS-Collect:
# read AIS data from a AIS-Catcher web service and
Expand Down
2 changes: 1 addition & 1 deletion rootfs/usr/share/vesselalert/save_databases
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC2015
#shellcheck shell=bash disable=SC2015,SC2154,SC1091
#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
Expand Down
21 changes: 16 additions & 5 deletions rootfs/usr/share/vesselalert/send_mastodon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC2015,SC2164,SC1090,SC1091,SC2154
#shellcheck shell=bash disable=SC2015,SC2164,SC1090,SC1091,SC2154,SC2001
#---------------------------------------------------------------------------------------------
# Copyright (C) 2022-2023, Ramon F. Kolb (kx1t)
#
Expand Down Expand Up @@ -104,18 +104,29 @@ if [[ -n "${VESSELS[$1:lat]}" ]] && [[ -n "${VESSELS[$1:lon]}" ]] && [[ -n "$LAT
fi

mast_str+="${MASTO_TERM[SIGNAL]} #RSSI: $(printf "%.1f dBFS" "${VESSELS[$1:level]}")\n"
[[ -n "${links}" ]] && mast_str+="${links}\n" || true

[[ -n "${NOTIFICATION_MAPURL}" ]] && [[ "${NOTIFICATION_MAPURL:0:4}" != "http" ]] && mast_str+="${MASTO_TERM[LOCATION]}: ${AIS_URL}?mmsi=${VESSELS[$1:mmsi]}\n" || true
[[ -n "${NOTIFICATION_MAPURL}" ]] && [[ "${NOTIFICATION_MAPURL:0:4}" == "http" ]] && mast_str+="${MASTO_TERM[LOCATION]}: ${NOTIFICATION_MAPURL}?mmsi=${VESSELS[$1:mmsi]}\n" || true
[[ -n "${links}" ]] && mast_str+="${links}\n" || true

[[ -n "$MASTODON_CUSTOM_FIELD" ]] && mast_str+="\n$MASTODON_CUSTOM_FIELD" || true
mast_str+="\n"

mast_str+="\n#Ship #Vessel #AIS"
mast_str+="\n#VesselAlert © 2023-2024 kx1t"
[[ -n "$MASTODON_CUSTOM_FIELD" ]] && mast_str+="$MASTODON_CUSTOM_FIELD\n" || true

mast_str+="#Ship #Vessel #AIS\n"
mast_str+="#VesselAlert © 2023-2024 kx1t"

#shellcheck disable=SC2001
mast_str="$(sed -e 's|\\n|\n|g' <<< "$mast_str")"

# test and correct if max toot length is exceeded
toot_length="$(sed 's/http[^ ]*/xxxxxxxxxxxxxxxxxxxxxxxx/g' <<<"${mast_str//$'\n'/ }" | wc -m)"
if (( toot_length >= 500 )); then
new_length="$(( ${#mast_str} - toot_length + 496 ))"
mast_str="${mast_str:0:$new_length}..."
"${s6wrap[@]}" echo "[WARNING] Mastodon Notification Truncated: it was $(( toot_length - 499)) characters too long"
fi

# Now we have the notification string, lets upload an image if one exists:

# If the image still exists, then upload it to Mastodon:
Expand Down