diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2018-09-01 05:47:26 +0000 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2018-09-28 23:30:26 -0400 |
commit | c439f4898dc8ff3142f215ae084ced5315ca4aad (patch) | |
tree | 9721e88042b9c93100b4127920f5904c38da0d50 | |
parent | e646b4dcdb8f4b46de683f7cf823e3b1b3ce6503 (diff) |
refactor memo reminder
-rw-r--r-- | lib/main.sh | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/main.sh b/lib/main.sh index 47585e3..2e8fb26 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -533,30 +533,28 @@ while true; do person="${sender%%!*}" personoslash="${person//\/}" declare -l personoslashlower="${personoslash}" + person_dir=announcements/people/${personoslashlower} the_time_now=$(date +%s) # If someone has sent this person a message then tell them. - if [[ -f "announcements/people/${personoslashlower}/messages" ]] + if [[ -f "${person_dir}/messages" ]] then - yepyep=1 - - # Make sure they have not already been - # told they have a message less than 1 - # hour ago - if [[ -f "announcements/people/${personoslashlower}/seen" ]] && (( ( $( stat -c %Y "announcements/people/${personoslashlower}/you_have_mail" 2> /dev/null ) + 3600 ) > the_time_now )) + # Remind this person they have a message not more often than once per 1 hour + if [[ -f "${person_dir}/seen" ]] then - yepyep=0 - fi + last_notice_time=$(stat -c %Y "${person_dir}/you_have_mail" 2> /dev/null) + should_remind=$(( ${last_notice_time} + 0 < the_time_now - 3600 )) - if (( yepyep )) - then - if (( $(wc -l "announcements/people/${personoslashlower}/messages" | cut -d ' ' -f 1) > 1 )) + if (( ${should_remind} )) then - send_msg "${channel}" "${personoslash}: you have messages, type something to see them." - else - send_msg "${channel}" "${personoslash}: you have a message, type something to see it." + n_memos=$(wc -l "${person_dir}/messages" | cut -d ' ' -f 1) + memo_msg="${personoslash}: you have , type something to see " + (( ${n_memos} > 1 )) && memo_msg="${memo_msg/,/(${n_memos}) memos,}them." || \ + memo_msg="${memo_msg/,/a memo,}it." + + send_msg "${channel}" "${memo_msg}" + touch "${person_dir}/you_have_mail" fi - touch "announcements/people/${personoslashlower}/you_have_mail" fi fi |