exclamatio - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
exclamatio (1358B) | |
--- | |
1 #!/bin/sh | |
2 | |
3 exclamatiomodbase="$HOME/bin/modules/exclamatio" | |
4 exclamatiodb="${exclamatiomodbase}/exclamatio.txt" | |
5 # time range for date(1) | |
6 maxexclamatiotime="30 seconds" | |
7 | |
8 function cleanupexclamatiodb { | |
9 expirytime="$(date +%s -d "${maxexclamatiotime} ago")" | |
10 cat ${exclamatiodb} \ | |
11 | while read -r line; | |
12 do | |
13 settime="$(printf "%s\n" "${line}" | cut -f 3)" | |
14 if [ ${settime} -ge ${expirytime} ]; | |
15 then | |
16 printf "%s\n" "${line}" | |
17 fi | |
18 done > $exclamatiodb.new | |
19 mv $exclamatiodb.new $exclamatiodb | |
20 } | |
21 | |
22 function setexclamatioval { | |
23 if [ -n "$(grep "^${1}" "${exclamatiodb}")" ]; | |
24 then | |
25 sed -i "s,${1}\t.*\t\(.*\),${1}\t${2}\t\1," "${exclamati… | |
26 else | |
27 printf "%s\t%d\t%d\n" "${1}" "${2}" "$(date +%s)" >> "${… | |
28 fi | |
29 } | |
30 | |
31 function getexclamatioval { | |
32 exclamatiotag="${1}" | |
33 exclamatioval="$(grep -P "^${exclamatiotag}\t" "${exclamatiodb}"… | |
34 [ -z "${exclamatioval}" ] && printf "0\n" | |
35 printf "%s\n" "${exclamatioval}" | |
36 } | |
37 | |
38 function modifyexclamatio { | |
39 exclamatiotag="$1" | |
40 exclamatioval=$(getexclamatioval "${exclamatiotag}") | |
41 newexclamatioval="$(printf "%d%s\n" "${exclamatioval}" "$2" | bc… | |
42 setexclamatioval "${exclamatiotag}" $newexclamatioval | |
43 } | |
44 | |
45 function incexclamatio { | |
46 modifyexclamatio "$1" " + $2" | |
47 } | |
48 | |
49 cleanupexclamatiodb | |
50 exclamatiostr="$1" | |
51 incexclamatio "${exclamatiostr}" "1" | |
52 printf "%s\n" "$(getexclamatioval "${exclamatiostr}")" | |
53 |