Add new dictcurl script. - 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 f1861dec786ba6af58ab4d9db17c63d388d65a60 DIR parent 1c9816b1574f11d4be5e92a7475acc79ca160d17 HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Wed, 3 Jan 2024 21:10:35 +0100 Add new dictcurl script. Thanks eidolon for the hint! Diffstat: M annna-message-common | 43 ++++++++++++------------------- A dictcurl | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 27 deletions(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -308,7 +308,7 @@ case "${text}" in "${ircuser}, how can I phlog on bitreich?") annna-say -s "${server}" -c "${channel}" "${user}, please read: gophers://bitreich.org/0/usr/20h/phlog/2017-08-26T20-04-02-482296.md and gophers://bitreich.org/0/usr/20h/phlog/2017-08-26T20-27-40-281825.md" ;; -"${ircuser}, what is my type?") +"${ircuser}, what's my type?") { cd /br/gopher usertype="$(find memecache/type-?.png -type f \ @@ -325,36 +325,25 @@ case "${text}" in ;; esac + dictserver="dict.org" case "${word}" in - "love") - puri="$(clippy-say "Baby don't hurt me no more!")" + dict.org*) + dictserver="dict.org" + word="$(printf "%s\n" "${word}" | cut -c 9-)" ;; - "my future") - puri="$(clippy-say "Did you mean _what's my horoscope?_?")" + parazy.de*) + dictserver="parazy.de" + word="$(printf "%s\n" "${word}" | cut -c 10-)" ;; - "my horoscope") - puri="$(clippy-say "Did you mean _what's my future?_?")" - ;; - "up") - puri="$(clippy-say "Did you mean _what's up?_?")" - ;; - *) - puri="" - dresult="$(printf '%s\n' "define * $word" QUIT | nc parazyd.org 2628)" - - if printf '%s\n' "$dresult" | grep -q '^150' - then - n="$(printf '%s\n' "$dresult" | grep -c '^151')" - nmessage="$n definition(s) found." - paste="$(printf '%s\n' "$dresult" | /br/bin/bitreich-paste)" - puri="$nmessage $paste" - elif printf '%s\n' "$dresult" | grep -q '^552' - then - puri="No match found." - else - puri="Server destroyed. Nothing to see here." - fi esac + + dresult="$(dictcurl "${dictserver}" "" "${word}")" + if [ -z "${dresult}" ]; + then + puri="No match found." + else + puri="$(printf "%s\n" "${dresult}" | /br/bin/bitreich-paste)" + fi annna-say -s "${server}" -c "${channel}" "${puri}" ;; "${ircuser}, cowsay "*) DIR diff --git a/dictcurl b/dictcurl @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ $# -lt 3 ]; +then + printf "usage: %s server[:port] db query\n" "$(basename "$0")" >&2 + exit 1 +fi + +server="${1}" +db="${2}" +query="${3:?}" + +curl -s "dict://${server}/d:${query}${db:+:$db}" \ +| awk '/^552 / { + print "No match for word." > "/dev/stderr" + exit 1 + } + /^151 /,/^\./ { + sub(/^151 |^\./, "") + print + } +'