pil - 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
---
pil (1463B)
---
1 #!/bin/sh
2
3 nick="${1}"
4 purposes="${2}"
5 pilmodbase="$HOME/bin/modules/pil"
6 pildb="${pilmodbase}/pil.txt"
7
8 # Make sure there's a file to store the PILs
9 if [ ! -f "${pildb}" ];
10 then
11 mkdir -p "${pilmodbase}"
12 touch "${pildb}"
13 fi
14
15 # Make sure file is writable.
16 if [ ! -w "${pildb}" ];
17 then
18 exit 1
19 fi
20
21 # Clean up the purposes string.
22 purposes="$(printf "%s" "${purposes}" \
23 | tr -d [:cntrl:] \
24 | sed 's,\n, ,g')"
25
26 # Check to see if its already been purposes.
27 already_purposes_entry="$(grep -m 1 "${purposes}" "${pildb}")"
28 if [ $? -eq 0 ]; # Match found (grep exit status of 0)
29 then
30 timestamp="$(printf "%s" "${already_purposes_entry}" \
31 | tr "\t" "\n" \
32 | tail -n 1)"
33 user="$(printf "%s" "${already_purposes_entry}" \
34 | tr "\t" "\n" \
35 | head -n 1)"
36 purposes_text="$(printf "%s" "${already_purposes_entry}" \
37 | tr "\t" "\n" \
38 | tail -n 2 \
39 | head -n 1)"
40 paste="$(printf '%s\n%s purposes %s\n' \
41 '${timestamp}' \
42 '${user}' \
43 '${purposes_text}' \
44 | /br/bin/bitreich-paste)"
45 printf "looks like that's already an purpose by %s on %s! %s" \
46 "${user:-someone}" \
47 "$(date -d "${timestamp}" +"%B %d, %Y")" \
48 '${paste}'
49 exit
50 fi
51
52 # Add the new TIL to the database.
53 timestamp=$(date -u)
54 printf "%s\n" "${nick} ${purposes} $(date -u)" \
55 >> "${pildb}"
56
57 # Count users TILs
58 pil_count="$(grep -cP "^${nick}\t" "${pildb}")"
59
60 # Successful return message.
61 printf "you have ${pil_count} purposes in life so far! :-)"
62 exit 0