Add talk back from annna for TIL - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 9ae0629d20eb0854f1195f93ad27803c1d13750e | |
parent cb81412efa9ed5137013987f5b676d9f8785917a | |
Author: Scarlett McAllister <[email protected]> | |
Date: Mon, 23 Oct 2023 22:56:00 -0300 | |
Add talk back from annna for TIL | |
Signed-off-by: Annna Robert-Houdin <[email protected]> | |
Diffstat: | |
M annna-message-common | 6 ++++++ | |
A til-user | 40 +++++++++++++++++++++++++++++… | |
2 files changed, 46 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/annna-message-common b/annna-message-common | |
@@ -1255,6 +1255,12 @@ case "${text}" in | |
fi | |
fi | |
;; | |
+"${ircuser}, what have I learned?") | |
+ if result=$(til-user ${user}); | |
+ then | |
+ annna-say -s "${server}" -c "${channel}" "${user}, ${result}" | |
+ fi | |
+ ;; | |
esac | |
diff --git a/til-user b/til-user | |
@@ -0,0 +1,40 @@ | |
+#!/bin/sh | |
+ | |
+nick="${1}" | |
+tilmodbase="$HOME/bin/modules/til" | |
+tilmodbase="." #remove before commit | |
+tildb="${tilmodbase}/til.txt" | |
+ | |
+# Make sure there's a file to parse. | |
+if [ ! -f "${tildb}" ]; | |
+then | |
+ exit 1 | |
+fi | |
+ | |
+format_user_tils() { | |
+ awk -v nick="${nick}" \ | |
+'BEGIN { | |
+ FS="\t" | |
+ print nick "\n" | |
+} | |
+$1 ~ nick { | |
+ print $3 | |
+ print "\nTIL" $2 "\n\n" | |
+}' "${tildb}" | |
+} | |
+ | |
+if user_learned_count="$(grep -cP "^${nick}\t" "${tildb}")"; | |
+then | |
+ results=$(format_user_tils "${nick}" \ | |
+ | fmt -w 69 \ | |
+ | /br/bin/bitreich-paste) | |
+ printf ", here is all your learning: %s" "${results}" | |
+ exit 0 | |
+else | |
+ printf ", you haven't learned anything yet :o" | |
+ exit 0 | |
+fi | |
+ | |
+ | |
+ | |
+ |