Introduction
Introduction Statistics Contact Development Disclaimer Help
use an empty case entry instead of checking [ -n "$x" ] before it - annna - Ann…
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit 9a192ffcabc9b67d60a1db9843ad8100397a6db4
parent cb97a0dd368eed35d9db94ffdc0c577788dfe168
Author: Josuah Demangeon <[email protected]>
Date: Sat, 2 Jul 2022 13:57:23 +0200
use an empty case entry instead of checking [ -n "$x" ] before it
This helps with flattening the script:
before:
if [ -n "$x" ]
then
case $x in
"content") ... ;;
"content") ... ;;
esac
fi
after
case $x in
"") ;;
"content") ... ;;
"content") ... ;;
esac
The patch is more readable when ignoring spaces: git diff -w
Signed-off-by: Annna Robert-Houdin <[email protected]>
Diffstat:
M annna-message-common | 271 +++++++++++++++--------------…
1 file changed, 135 insertions(+), 136 deletions(-)
---
diff --git a/annna-message-common b/annna-message-common
@@ -33,8 +33,6 @@ regeximatch() {
[ "$user" = "${botname}" ] && exit 0
-uri="$(printf "%s\n" "${text}" \
- | sed -n '/.*\(https\{0,1\}:\/\/[^ ]\{1,\}\).*/s//\1/p')"
case "${text}" in
*\#nospoil*)
;;
@@ -42,160 +40,161 @@ case "${text}" in
query=${text#**::} query=${query%%::*}
annna-say -s "${server}" -c "${channel}" "$(dalle-gen-emoji "${query}"…
;;
-*)
- if [ -n "${uri}" ]
- then
- tmpf=$(mktemp)
- fetch-uri "${uri}" > "${tmpf}"
- urititle="$(grabtitle < "${tmpf}")"
+*http*://*)
+ uri="$(printf "%s\n" "${text}" \
+ | sed -n '/.*\(https\{0,1\}:\/\/[^ ]\{1,\}\).*/s//\1/p')"
- # Set below and annna will concatenate at the end.
- # Subtitle URI.
- sturi=""
- # Replacement URI.
- nuri=""
- # Replacement URI display string.
- nuris=""
- # html2text content.
- curi=""
- # Set to 0, if some URI content should be shown.
- nocuri=1
- # Screenshot.
- suri=""
+ tmpf=$(mktemp)
+ fetch-uri "${uri}" > "${tmpf}"
+ urititle="$(grabtitle < "${tmpf}")"
- # titleend=1 will not output any further.
- titleend=0
- outputstr=""
+ # Set below and annna will concatenate at the end.
+ # Subtitle URI.
+ sturi=""
+ # Replacement URI.
+ nuri=""
+ # Replacement URI display string.
+ nuris=""
+ # html2text content.
+ curi=""
+ # Set to 0, if some URI content should be shown.
+ nocuri=1
+ # Screenshot.
+ suri=""
- if [ -n "$urititle" ];
- then
- case "${urititle}" in
- *Gunther*|*GUNTHER*|*Günther*)
- annna-say -s "${server}" -c "${channel}" "Oh G…
- ;;
- *\|\ Cloudflare*)
- annna-say -s "${server}" -c "${channel}" "Mind…
- titleend=1
- ;;
- esac
- fi
+ # titleend=1 will not output any further.
+ titleend=0
+ outputstr=""
- case "${uri}" in
- *github.com/*/blob/*)
- urltitle=""
- nuris="$(printf '%s' "${uri}" | sed 's/blob/raw/')"
- nocuri=0
- ;;
+ case "${urititle}" in
+ "")
+ ;;
+ *Gunther*|*GUNTHER*|*Günther*)
+ annna-say -s "${server}" -c "${channel}" "Oh Günther! ❤ �…
+ ;;
+ *\|\ Cloudflare*)
+ annna-say -s "${server}" -c "${channel}" "Mind your own busine…
+ titleend=1
+ ;;
+ esac
- *imgur.com/*)
- nuris="$(youtube-dl -g "${uri}")"
- if [ $? -gt 0 ];
- then
- nuris=""
- fi
- ;;
- *xkcd.com/*)
- nuris="$(xkcd-uri "${uri}")"
- ;;
- *imdb.com/title/*)
- movietitle="$(imdb2gopherbay "${uri}" | sed 's, ,+,g')"
- if [ -n "${movietitle}" ];
- then
- nuris="gopher://bay.parazy.de:666/1/q.dcgi?${m…
- fi
- ;;
- *themoviedb.org/movie/*)
- movietitle="$(themoviedb2gopherbay "${uri}" | sed 's, …
- if [ -n "${movietitle}" ];
- then
- nuris="gopher://bay.parazy.de:666/1/q.dcgi?${m…
- fi
- ;;
- *lichess.org/????????|*lichess.org/????????/|*lichess.org/????…
- nuris="$(printf "%s\n" "${uri}" \
- | sed 's,https://lichess.org\(/[^ ]*\)$,\1,; s…
- ;;
- *www.npr.org/*)
+ case "${uri}" in
+ "")
+ ;;
+ *github.com/*/blob/*)
+ urltitle=""
+ nuris="$(printf '%s' "${uri}" | sed 's/blob/raw/')"
+ nocuri=0
+ ;;
+
+ *imgur.com/*)
+ nuris="$(youtube-dl -g "${uri}")"
+ if [ $? -gt 0 ];
+ then
+ nuris=""
+ fi
+ ;;
+ *xkcd.com/*)
+ nuris="$(xkcd-uri "${uri}")"
+ ;;
+ *imdb.com/title/*)
+ movietitle="$(imdb2gopherbay "${uri}" | sed 's, ,+,g')"
+ if [ -n "${movietitle}" ];
+ then
+ nuris="gopher://bay.parazy.de:666/1/q.dcgi?${movietitl…
+ fi
+ ;;
+ *themoviedb.org/movie/*)
+ movietitle="$(themoviedb2gopherbay "${uri}" | sed 's, ,+,g')"
+ if [ -n "${movietitle}" ];
+ then
+ nuris="gopher://bay.parazy.de:666/1/q.dcgi?${movietitl…
+ fi
+ ;;
+ *lichess.org/????????|*lichess.org/????????/|*lichess.org/????????/bla…
+ nuris="$(printf "%s\n" "${uri}" \
+ | sed 's,https://lichess.org\(/[^ ]*\)$,\1,; s,^/\([^/…
+ ;;
+ *www.npr.org/*)
+ post="$(printf '%s\n' "${uri}" | cut -d / -f 7)"
+ if [ -n "${post}" ];
+ then
+ nuri="https://text.npr.org/s.php?sId=${post}"
+ nuris="text only: ${nuri}"
+ fi
+ ;;
+ *www.reddit.com*)
+ nuri="$(printf '%s\n' "${uri}" | sed "s;www.reddit.com;old.red…
+ nuris="old.reddit: ${nuri}"
+ fetch-uri "${nuri}" > "${tmpf}"
+ if [ -n "${uri#*www.reddit.com/r/*}" ];
+ then
+ subreddit="$(printf '%s\n' "${uri}" | cut -d / -f 5)"
post="$(printf '%s\n' "${uri}" | cut -d / -f 7)"
if [ -n "${post}" ];
then
- nuri="https://text.npr.org/s.php?sId=${post}"
- nuris="text only: ${nuri}"
+ guri="gopher://gopherddit.com/1/cgi-bin/reddit…
+ else
+ guri="gopher://gopherddit.com/1/cgi-bin/reddit…
fi
- ;;
- *www.reddit.com*)
- nuri="$(printf '%s\n' "${uri}" | sed "s;www.reddit.com…
- nuris="old.reddit: ${nuri}"
- fetch-uri "${nuri}" > "${tmpf}"
- if [ -n "${uri#*www.reddit.com/r/*}" ];
- then
- subreddit="$(printf '%s\n' "${uri}" | cut -d /…
- post="$(printf '%s\n' "${uri}" | cut -d / -f 7…
- if [ -n "${post}" ];
- then
- guri="gopher://gopherddit.com/1/cgi-bi…
- else
- guri="gopher://gopherddit.com/1/cgi-bi…
- fi
- nuris="${nuri} ; gopherdit: ${guri}"
- fi
- nocuri=0
- ;;
- *twitter.com*)
- ninstance="$(nitter-instance | sed 's,\.,\\\.,g')"
- nuri="$(printf "%s\n" "${uri}" | sed "s;\(mobile\.\)\{…
+ nuris="${nuri} ; gopherdit: ${guri}"
+ fi
+ nocuri=0
+ ;;
+ *twitter.com*)
+ ninstance="$(nitter-instance | sed 's,\.,\\\.,g')"
+ nuri="$(printf "%s\n" "${uri}" | sed "s;\(mobile\.\)\{0,1\}twi…
+ fetch-uri "${nuri}" > "${tmpf}"
+ urititle="$(curl-grabtitle "${nuri}")"
+ suri="$(screenshot-paste "${nuri}")"
+ nuris="nitter: ${nuri}"
+ nocuri=0
+ ;;
+ *en.wikipedia.org/wiki*)
+ if ! regeximatch "$uri" '\.(jpg,bmp,gif,png,tiff,avi,mp4,webm,…
+ then
+ nuri="$(printf '%s\n' "${uri}" | sed -e "s;.*en.wikipe…
+ nuris="$(printf 'gopherpedia: %s\n' "${nuri}")"
fetch-uri "${nuri}" > "${tmpf}"
- urititle="$(curl-grabtitle "${nuri}")"
- suri="$(screenshot-paste "${nuri}")"
- nuris="nitter: ${nuri}"
nocuri=0
- ;;
- *en.wikipedia.org/wiki*)
- if ! regeximatch "$uri" '\.(jpg,bmp,gif,png,tiff,avi,m…
- then
- nuri="$(printf '%s\n' "${uri}" | sed -e "s;.*e…
- nuris="$(printf 'gopherpedia: %s\n' "${nuri}")"
- fetch-uri "${nuri}" > "${tmpf}"
- nocuri=0
- fi
- ;;
- *youtube.com/*|*youtu.be/*)
- nuri="https://yewtu.be/${uri#https*://*/}"
- fetch-uri "${nuri}" > "${tmpf}"
- urititle="$(curl-grabtitle "${nuri}")"
- sturi="$(subtitle-paste "${uri}")"
- nuris="invidious: ${nuri}"
+ fi
+ ;;
+ *youtube.com/*|*youtu.be/*)
+ nuri="https://yewtu.be/${uri#https*://*/}"
+ fetch-uri "${nuri}" > "${tmpf}"
+ urititle="$(curl-grabtitle "${nuri}")"
+ sturi="$(subtitle-paste "${uri}")"
+ nuris="invidious: ${nuri}"
+ nocuri=0
+ ;;
+ *)
+ mimetype="$(file -b --mime-type "${tmpf}")"
+ case "${mimetype}" in
+ text/*)
nocuri=0
;;
- *)
- mimetype="$(file -b --mime-type "${tmpf}")"
- case "${mimetype}" in
- text/*)
- nocuri=0
- ;;
- esac
- ;;
esac
+ ;;
+ esac
- if [ $titleend -eq 0 ];
+ if [ $titleend -eq 0 ];
+ then
+ if [ $nocuri -eq 0 ];
then
- if [ $nocuri -eq 0 ];
+ if [ -z "${curi}" ];
then
- if [ -z "${curi}" ];
- then
- curi="$(html2text < "${tmpf}" | /br/bi…
- fi
- outputstr="${outputstr} content: ${curi} ;"
+ curi="$(html2text < "${tmpf}" | /br/bin/bitrei…
fi
-
- [ -n "${nuris}" ] && outputstr="${outputstr} ${nuris} …
- [ -n "${urititle}" ] && outputstr="${outputstr} title:…
- [ -n "${suri}" ] && outputstr="${outputstr} screen: ${…
- [ -n "${sturi}" ] && outputstr="${outputstr} subtitles…
- annna-say -s "${server}" -c "${channel}" "${outputstr}"
+ outputstr="${outputstr} content: ${curi} ;"
fi
- rm -f "${tmpf}"
+
+ [ -n "${nuris}" ] && outputstr="${outputstr} ${nuris} ;"
+ [ -n "${urititle}" ] && outputstr="${outputstr} title: ${uriti…
+ [ -n "${suri}" ] && outputstr="${outputstr} screen: ${suri} ;"
+ [ -n "${sturi}" ] && outputstr="${outputstr} subtitles: ${stur…
+ annna-say -s "${server}" -c "${channel}" "${outputstr}"
fi
+ rm -f "${tmpf}"
;;
esac
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.