merge two if [ "${text}" = "..." ] back to the main case ${text} - annna - Annna the nice friendly bot.
HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
---
DIR commit ea1854a310ae05275e392beb53a2ae35bcd36a50
DIR parent 9a192ffcabc9b67d60a1db9843ad8100397a6db4
HTML Author: Josuah Demangeon <me@josuah.net>
Date: Sat, 2 Jul 2022 14:08:18 +0200
merge two if [ "${text}" = "..." ] back to the main case ${text}
The randomtag logic is not made a special case anymore:
The script still executes the randomtag block,
calling shuf (absent from my system) to fetch a random tag:
$ sh -x ./annna-message-common server channel user "annna, please meme meme meme me."
[...]
+ text=annna, please meme meme meme me.
+ [ user = annna ]
+ randomtag=2
+ [ 2 -gt 0 ]
+ shuf -n 1
./annna-message-common[1003]: shuf: not found
+ hashtags
+ printf %s\n
+ rtag=
+ tagname=
+ taguri=
+ annna-say -s server -c channel :
-s server -c channel :
+ randomtag=1
[...]
Signed-off-by: Annna Robert-Houdin <annna@bitreich.org>
Diffstat:
M annna-message-common | 81 ++++++++++++++-----------------
1 file changed, 36 insertions(+), 45 deletions(-)
---
DIR diff --git a/annna-message-common b/annna-message-common
@@ -975,22 +975,49 @@ case "${text}" in
sleep 0.5
annna-say -s "${server}" -c "${user}" "»please help.« gives you this help listing, ${user}."
;;
-esac
-
-randomtag=0
-if [ "${text}" = "${botname}, please meme meme meme me." ];
-then
+"${botname}, please meme meme meme me.")
randomtag=2
-fi
+ while [ $randomtag -gt 0 ];
+ do
+ rtag="$(printf "%s\n" "$(hashtags)" | shuf -n 1)"
+ tagname=""
+ taguri=""
+ for tag in ${rtag};
+ do
+ [ -z "${tagname}" ] && tagname="${tag}" && continue
+ taguri="${tag}"
+ done
+
+ annna-say -s "${server}" -c "${channel}" "${tagname}: ${taguri}"
-if [ "${text}" = "${botname}, what's the wheelchair shooter meme again?" ];
-then
+ randomtag=$((randomtag - 1))
+ done
+ ;;
+"${botname}, what's the wheelchair shooter meme again?")
tagname="#scrollby"
tagline="$(printf "%s\n" "$(hashtags)" | grep "^${tagname} ")"
tagname="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 1)"
taguri="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 2-)"
annna-say -s "${server}" -c "${channel}" "${tagname}: ${taguri}"
-fi
+ ;;
+esac
+
+printf '%s' "$text" | awk -v taglimit="$printnhashtags" '
+$0 !~ /#nospoil/ {
+ while (match($0, /#[^# "'\'',?!;$\001]+/)) {
+ tag = substr($0, RSTART, RLENGTH)
+ $0 = substr($0, RSTART + RLENGTH)
+ sub(/[.]*$/, "", tag)
+ if (!uniq[tag]++ && taglimit-- > 0)
+ print tag
+ }
+}' | while read -r tag;
+do
+ if tagline="$(grep "${tag} " "${hashtagfile}")";
+ then
+ annna-say -s "${server}" -c "${channel}" "${tagline% *}: ${tagline#* }"
+ fi
+done
case "${text}" in
*\#nospoil*)
@@ -1005,42 +1032,6 @@ case "${text}" in
;;
esac
-if [ $randomtag -gt 0 ];
-then
- while [ $randomtag -gt 0 ];
- do
- rtag="$(printf "%s\n" "$(hashtags)" | shuf -n 1)"
- tagname=""
- taguri=""
- for tag in ${rtag};
- do
- [ -z "${tagname}" ] && tagname="${tag}" && continue
- taguri="${tag}"
- done
-
- annna-say -s "${server}" -c "${channel}" "${tagname}: ${taguri}"
-
- randomtag=$(($randomtag - 1))
- done
-else
- printf '%s' "$text" | awk -v taglimit="$printnhashtags" '
- $0 !~ /#nospoil/ {
- while (match($0, /#[^# "'\'',?!;$\001]+/)) {
- tag = substr($0, RSTART, RLENGTH)
- $0 = substr($0, RSTART + RLENGTH)
- sub(/[.]*$/, "", tag)
- if (!uniq[tag]++ && taglimit-- > 0)
- print tag
- }
- }' | while read -r tag;
- do
- if tagline="$(grep "${tag} " "${hashtagfile}")";
- then
- annna-say -s "${server}" -c "${channel}" "${tagline% *}: ${tagline#* }"
- fi
- done
-fi
-
# Always keep the karma / shame last!
case "${text}" in
*"-shaming"*)