discord*.sh will now break chunks at nearest newline, when input is large.

This commit is contained in:
2023-09-13 13:00:59 +00:00
parent c3a27071de
commit 98e6447899
2 changed files with 19 additions and 0 deletions
+9
View File
@@ -18,6 +18,15 @@ EXTRA="${MESSAGE:1800}"
if [ -n "${EXTRA}" ]; then
MESSAGE="${MESSAGE:0:1800}"
# as an added elegance, when spliting into pieces, find the last \n newline,
# and break there instead, but only if the new smaller chunk is of sufficient size
chunk1=`echo "$MESSAGE" | head -n -1`
chunks=`echo "$MESSAGE" | tail -n 1`
if (( "${#chunk1}" >= 1000 )); then
MESSAGE="$chunk1"
EXTRA="${chunks}${EXTRA}"
fi
fi
# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead
+10
View File
@@ -14,8 +14,18 @@ EXTRA="${MESSAGE:1800}"
if [ -n "${EXTRA}" ]; then
MESSAGE="${MESSAGE:0:1800}"
# as an added elegance, when spliting into pieces, find the last \n newline,
# and break there instead, but only if the new smaller chunk is of sufficient size
chunk1=`echo "$MESSAGE" | head -n -1`
chunks=`echo "$MESSAGE" | tail -n 1`
if (( "${#chunk1}" >= 1000 )); then
MESSAGE="$chunk1"
EXTRA="${chunks}${EXTRA}"
fi
fi
# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead
# linux is fine with the missing zero, but discord needs it
MESSAGE=`echo "${MESSAGE}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'`