nonvitalbits.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Nonvital bits of bashy2
  2. # This file is part of bashy2, an irc bot used on irc.sdf.org.
  3. # Copyright (C) 2016-2018 mlaine@sdfeu.org
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. # The above copyright notice and this permission notice shall be
  12. # included in all copies or substantial portions of the Software.
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  17. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  18. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  19. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. #-----------------------------------------------------------------------
  21. function welcome {
  22. # Sends a help message to a user not in the seen database.
  23. local db='./data/seen'
  24. if [[ "$quiet" -eq 1 && "${chan:1}" = '#helpdesk' &&
  25. -z "$(grep "^$nick " "$db")" ]]; then
  26. ( cd "$cmd_dir" && './help' "$nick" ) &
  27. fi
  28. }
  29. function seen {
  30. # Based on PRIVMSG events, updates a database of seen users. The
  31. # command seen depends on this database.
  32. local db='./data/seen'
  33. if [[ ! -f "$db" ]]; then
  34. printf '%s\n' "$bot_nick a secret mission /sys/" > "$db"
  35. fi
  36. local time="$(date -u +%x\ %R\ %Z)"
  37. local old="$(grep "^$nick " "$db")"
  38. local new="$nick $time $chan"
  39. if [[ -n "$old" ]]; then
  40. perl -i -pe "s~$old~$new~" "$db"
  41. else
  42. printf '%s\n' "$new" >> "$db"
  43. fi
  44. }