bashy2 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env bash
  2. # This file is part of bashy2, an irc bot used on irc.sdf.org.
  3. # Copyright (C) 2015-2016 mlaine@sdfeu.org, grugly@sdf.org
  4. # Copyright (C) 2017-2018 mlaine@sdfeu.org
  5. # Permission is hereby granted, free of charge, to any person obtaining
  6. # a copy of this software and associated documentation files (the
  7. # "Software"), to deal in the Software without restriction, including
  8. # without limitation the rights to use, copy, modify, merge, publish,
  9. # distribute, sublicense, and/or sell copies of the Software, and to
  10. # permit persons to whom the Software is furnished to do so, subject to
  11. # the following conditions:
  12. # The above copyright notice and this permission notice shall be
  13. # included in all copies or substantial portions of the Software.
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #-----------------------------------------------------------------------
  22. ## Options 0 = on, 1 = off, logfile = file
  23. debug=1
  24. source './bits/conf.sh'
  25. source './bits/vitalbits.sh'
  26. source './bits/nonvitalbits.sh'
  27. function init {
  28. exec 3<&-
  29. exec 3<>"/dev/tcp/$irc_host/$irc_port" || return 1
  30. send 'user' "$bot_user" "$bot_real"
  31. send 'nick' "$bot_nick"
  32. declare -g quiet=1
  33. }
  34. function main {
  35. init
  36. while true; do
  37. ## the -t is the read timer, and needs to account for the server ping setting
  38. if IFS=$' \t\r' read -ru3 -a data -t 140; then
  39. debug 'IN:' "${data[@]}"
  40. if [[ "${data[0]}" = 'PING' ]]; then
  41. send 'pong' "${data[1]}"
  42. continue
  43. fi
  44. case "${data[1]}" in
  45. 'PRIVMSG')
  46. priv "${data[@]}" ;;
  47. 'JOIN')
  48. user_join "${data[@]}" ;;
  49. 'QUIT')
  50. user_quit "${data[@]}" ;;
  51. '001')
  52. send 'oper' "$bot_user" "$(awk 'NR==1' "$irc_pass")"
  53. serv 'join' ;;
  54. '332'|'331')
  55. chtopic "${data[@]}" ;;
  56. '352'|'315')
  57. upall "${data[@]}" ;;
  58. '311'|'319')
  59. up "${data[@]}" ;;
  60. esac
  61. else
  62. ## If we get here, it's cause bashy needs to restart/connect
  63. sleep 300
  64. init
  65. fi
  66. done
  67. }
  68. main