bashy2 2.6 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 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. debug=1
  23. quiet=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. }
  33. function main {
  34. init
  35. while true; do
  36. if IFS=$' \t\r' read -ru3 -a data -t 100; then
  37. debug 'IN:' "${data[@]}"
  38. if [[ "${data[0]}" = 'PING' ]]; then
  39. send 'pong' "${data[1]}"
  40. continue
  41. fi
  42. case "${data[1]}" in
  43. 'PRIVMSG')
  44. priv "${data[@]}" ;;
  45. 'JOIN')
  46. user_join "${data[@]}" ;;
  47. 'QUIT')
  48. user_quit "${data[@]}" ;;
  49. '001')
  50. send 'oper' "$bot_user" "$(awk 'NR==1' "$irc_pass")"
  51. join
  52. sleep 10 && chmode &&
  53. sleep 10 && chtopic &&
  54. sleep 10 && serv 'upall' & ;;
  55. '332'|'331')
  56. chtopic "${data[@]}" ;;
  57. '352'|'315')
  58. upall "${data[@]}" ;;
  59. '311'|'319')
  60. up "${data[@]}" ;;
  61. esac
  62. else
  63. sleep 300
  64. init
  65. fi
  66. done
  67. }
  68. main