add simulation simulator - 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 4d6d4eaa7f3062b998498a2f9ee90e830805a42f DIR parent 38772dee8f3c08afff361dc904b4fda097b2e67e HTML Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Tue, 11 Jan 2022 20:52:06 +0100 add simulation simulator Signed-off-by: Annna Robert-Houdin <annna@bitreich.org> Diffstat: M annna-message-common | 12 ++++++++++++ A imgsearch.sh | 61 +++++++++++++++++++++++++++++++ A simulate.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 0 deletions(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -856,6 +856,18 @@ case "${text}" in } & exit 0 ;; +"${botname}, please simulate "*" simulator") + q="${text#* please simulate }" + q="${q% simulator*}" + outpath="/br/gopher/p/" + { + if outfile="$(./simulate.sh "$q")" + then + mv "${outfile}" "${outpath}/" + annna-say -s "${server}" -c "${channel}" "${user}, gopher://bitreich.org/I/p/${outfile}" + fi + } & + ;; "${botname}, please help.") # Help Message. # TODO: Add multiple line support to annna-say -s "${server}" -c(1) with sleep. DIR diff --git a/imgsearch.sh b/imgsearch.sh @@ -0,0 +1,61 @@ +#!/bin/sh +searxbase="https://search.stinpriza.org" +maxtries=10 + +die() { + printf '%s: error: %s\n' "${0%%*/}" "$1" + exit "${2:-1}" +} + +get_image() { + q="$(printf '%s' "$1" | sed 's/ /%20/g')" + s="$(printf '%s' "$1" | sed 's/ /_/g')" + searxuri="${searxbase}/search?q=${q}&categories=images" + curl -s "${searxuri}" \ + | xml2tsv 2>/dev/null \ + | grep img \ + | cut -f 2 \ + | grep ^src \ + | cut -d'=' -f 2- \ + | while read -r uri; + do + case "${uri}" in + /*) + uri="${searxbase}${uri}" + ;; + esac + + out="${s}.jpg" + if curl -s "${uri}" -o "$out" + then + printf '%s\n' "$out" + case "$(file -ib "$out")" in + image/jpeg) + return + ;; + image/*) + convert "$out" "${out}.tmp.jpg" + mv "${out}.tmp.jpg" "$out" + return + ;; + esac + fi + + if test "$i" -gt 0 + then + sleep 1 + fi + i=$((i + 1)) + done +} + +if test $# -lt 1 +then + exit 0 +fi + +i=0 +for q in "$@" +do + get_image "$q" +done DIR diff --git a/simulate.sh b/simulate.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +die() { + printf '%s: error: %s\n' "${0%%*/}" "$1" + exit "${2:-1}" +} + +for q in "$@" +do + year="$(( RANDOM / 1000 + 1990 ))" + if ! img="$(./imgsearch.sh "$q")" + then + die "could not find a image for '$q'" + fi + out="${img%.*}-simulator.jpg" + convert -gravity NorthWest \ + -font "Helvetica-Narrow-Oblique" -pointsize 70 \ + -stroke '#000C' -strokewidth 2 -annotate +0+10 "$q" \ + -stroke none -fill white -annotate +0+10 "$q" \ + -stroke '#000C' -strokewidth 2 -annotate +0+80 "Simulator" \ + -stroke none -fill white -annotate +0+80 "Simulator" \ + -stroke '#000C' -strokewidth 2 -annotate +0+150 "$year" \ + -stroke none -fill white -annotate +0+150 "$year" \ + "$img" "$out" + printf '%s\n' "$out" +done