Introduction
Introduction Statistics Contact Development Disclaimer Help
Add exclamatio module and script. - annna - Annna the nice friendly bot.
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit c0655da913f533290a7600cc2c10507b9915e181
parent b52d60cdecb35f5bd6834f0c5de11c556bbdbe2b
Author: Annna Robert-Houdin <[email protected]>
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(-)
---
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)" >> "${exclam…
+ fi
+}
+
+function getexclamatioval {
+ exclamatiotag="${1}"
+ exclamatioval="$(grep -P "^${exclamatiotag}\t" "${exclamatiodb}" | cut…
+ [ -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}")"
+
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.