interjection-bot.scm 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (use-modules (8sync) ; 8sync's agenda and actors
  2. (8sync systems irc) ; the irc bot subsystem
  3. (oop goops) ; 8sync's actors use GOOPS
  4. (ice-9 format) ; basic string formatting
  5. (ice-9 match)) ; pattern matching
  6. (define-class <my-irc-bot> (<irc-bot>))
  7. (define-method (handle-line (irc-bot <my-irc-bot>) message
  8. speaker channel line emote?)
  9. (define my-name (irc-bot-username irc-bot))
  10. (define (looks-like-me? str)
  11. (or (equal? str my-name)
  12. (equal? str (string-concatenate (list my-name ":")))))
  13. (define (respond respond-line)
  14. (<- (actor-id irc-bot) 'send-line channel
  15. respond-line))
  16. (if [looks-like-me? (car (string-split line #\space))]
  17. [match (string-split line #\space)
  18. (((? looks-like-me? _) action action-args ...)
  19. (match action
  20. ;; The classic botsnack!
  21. ("botsnack"
  22. (respond "Yippie! *does a dance!*"))
  23. (_
  24. (respond "*stupid puppy look*"))))]
  25. [cond [(or (member "linux" (string-split line #\space))
  26. (member "Linux" (string-split line #\space)))
  27. (respond "I'd just like to interject for moment. What you're refering to as Linux, is in fact, GNU/Linux.")]
  28. [(and (member "open" (string-split line #\space))
  29. (member "source" (string-split line #\space)))
  30. (respond "I think you meant Free Software https://www.gnu.org/philosophy/open-source-misses-the-point.html not 'open source'")]
  31. [(or (equal? "noordinaryspider" speaker)
  32. (equal "noordinaryspider[m]" speaker))
  33. (respond "Please do not spam #lgn kid noordinaryspider")]]))
  34. (define* (run-bot #:key (username "examplebot")
  35. (server "irc.freenode.net")
  36. (channels '("##saratestlab")))
  37. (define hive (make-hive))
  38. (define irc-bot
  39. (pk 'bootstrapped
  40. (bootstrap-actor hive <my-irc-bot>
  41. #:username username
  42. #:server server
  43. #:channels channels)))
  44. (run-hive hive '()))
  45. (run-bot #:username "Sara") ; be creative!