Add exclamatio module and script. - annna - Annna the nice friendly bot.
(HTM) git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
(DIR) commit c0655da913f533290a7600cc2c10507b9915e181
(DIR) parent b52d60cdecb35f5bd6834f0c5de11c556bbdbe2b
(HTM) Author: Annna Robert-Houdin <annna@bitreich.org>
Date: Sat, 7 Jan 2023 22:02:04 +0100
Add exclamatio module and script.
Diffstat:
A exclamatio | 54 +++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/exclamatio b/exclamatio
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+exclamatiomodbase="$HOME/bin/modules/exclamatio"
+exclamatiodb="${exclamatiomodbase}/exclamatio.txt"
+# time range for date(1)
+maxexclamatiotime="30 seconds"
+
+function cleanupexclamatiodb {
+ expirytime="$(date +%s -d "${maxexclamatiotime} ago")"
+ cat ${exclamatiodb} \
+ | while read -r line;
+ do
+ settime="$(printf "%s\n" "${line}" | cut -f 3)"
+ if [ ${settime} -ge ${expirytime} ];
+ then
+ printf "%s\n" "${line}"
+ fi
+ done > $exclamatiodb.new
+ mv $exclamatiodb.new $exclamatiodb
+}
+
+function setexclamatioval {
+ if [ -n "$(grep "^${1}" "${exclamatiodb}")" ];
+ then
+ sed -i "s,${1}\t.*\t\(.*\),${1}\t${2}\t\1," "${exclamatiodb}"
+ else
+ printf "%s\t%d\t%d\n" "${1}" "${2}" "$(date +%s)" >> "${exclamatiodb}"
+ fi
+}
+
+function getexclamatioval {
+ exclamatiotag="${1}"
+ exclamatioval="$(grep -P "^${exclamatiotag}\t" "${exclamatiodb}" | cut -f 2)"
+ [ -z "${exclamatioval}" ] && printf "0\n"
+ printf "%s\n" "${exclamatioval}"
+}
+
+function modifyexclamatio {
+ exclamatiotag="$1"
+ exclamatioval=$(getexclamatioval "${exclamatiotag}")
+ newexclamatioval="$(printf "%d%s\n" "${exclamatioval}" "$2" | bc)"
+ setexclamatioval "${exclamatiotag}" $newexclamatioval
+ printf "%s = %d\n" "$exclamatiotag" "$newexclamatioval"
+}
+
+function incexclamatio {
+ modifyexclamatio "$1" " + $2"
+}
+
+cleanupexclamatiodb
+exclamatiostr="$1"
+incexclamatio "${exclamatiostr}" "1"
+printf "%s\n" "$(getexclamatioval "${exclamatiostr}")"
+