puppy-bot.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. (srfi srfi-1)) ; list manipulation (find)
  7. (load "guiletime.scm") ; For countdown til next #LGN
  8. (define list->string
  9. (lambda(lis)
  10. (cond [(null? lis) ""]
  11. [else (string-append (car lis)
  12. " "
  13. (list->string (cdr lis)))])))
  14. (define-class <my-irc-bot> (<irc-bot>))
  15. (define* (run-bot #:key (username "examplebot")
  16. (server "irc.freenode.net")
  17. (channels '("#lgn")))
  18. (define hive (make-hive))
  19. (define irc-bot
  20. (bootstrap-actor hive <my-irc-bot>
  21. #:username username
  22. #:server server
  23. #:channels channels))
  24. (run-hive hive '()))
  25. (define-method (handle-line (irc-bot <my-irc-bot>) message
  26. speaker channel line emote?)
  27. (define my-name (irc-bot-username irc-bot))
  28. (define (looks-like-me? str)
  29. (or (equal? str my-name)
  30. (equal? str (string-concatenate (list my-name ":")))))
  31. (define (respond respond-line)
  32. (<- (actor-id irc-bot) 'send-line channel
  33. respond-line))
  34. (cond ((not (or (equal? speaker "1noordinaryspider[m]")
  35. (equal? speaker "1noordinaryspider")))
  36. (match (string-split line #\space)
  37. (((? looks-like-me? _) action action-args ...)
  38. (match action
  39. ;;; BOT TALKING
  40. ;;; STRING -> STRING
  41. ;;; (STRING (respond STRING))
  42. ;;; Takes a string as a first argument (given by speaker)
  43. ;;; If it matches it calls (respond STRING) as an anwser
  44. ;;; COMMON BOT COMMANDS
  45. ;; Repeat everything
  46. ;; (respond (list->string (cdr (string-split line #\space))))
  47. ;; ("what" (respond (car action-args)))
  48. ("echo" (respond (string-join action-args " ")))
  49. ;; The classic botsnack!
  50. ("botsnack" (respond "Yippie! *does a dance!*"))
  51. ;; Return greeting
  52. ((or "hello" "hello!" "hello." "greetings" "greetings." "greetings!" "Hi" "Hello"
  53. "hei" "hei." "hei!" "hi" "hi!") (respond (format #f "Oh hi ~a!" speaker)))
  54. ((or "hola" "Hola" "saludos." "saludos")
  55. (respond (format #f "Oh hola!! ~a! me gusta hablar español :)" speaker)))
  56. ;; Help speaker
  57. ("help" (respond (format #f "I am not a helper bot, help yourself ~a!" speaker)))
  58. ;; Give time
  59. ((or "time" "Time") (respond (format #f "It is: ~a UTC" (strftime "%Y-%m-%d %H:%M" (localtime (current-time) "UTC")))))
  60. ;;; #LibreGameNight BOT COMMANDS
  61. ;; Ask noordinaryspider to be quiet
  62. ((or "noordinaryspider" "noordinaryspider[m]") (respond "noordinaryspider I am tired please be quiet"))
  63. ;;Info about next LibreGameNight
  64. ((or "game" "#lgn" "lgn")
  65. (respond (format #f "We’ll play Annex-CTW 2017–11–18 @ 00:30 Current time is: ~a UTC For more information please visit https://libregamenight.xyz" (strftime "%Y-%m-%d %H:%M" (localtime (current-time) "UTC")))))
  66. ; Time until next LibreGameNight
  67. ; countdown from guiletime.scm
  68. ("countdown" (respond (countdown "2017-11-18 00:30")))
  69. ;;; PUPPY BOT COMMANDS
  70. ;; if called in capital letters by speaker
  71. ("PUPPY" (respond (format #f "DO NOT YELL AT ME ~a!!" (string-upcase speaker))))
  72. ; If speaker wants to give belly rubs
  73. ("belly" (cond [(equal? "rub?" (car action-args))
  74. (if (= 0 (random 2))
  75. (respond "YES! I LIVE FOR BELLY RUBS!!")
  76. (respond "Nooo!! I am tired :C"))]
  77. [(equal? "rub" (car action-args))
  78. (if (= 0 (random 2))
  79. (respond "aaaaaahhhhh =W=")
  80. (respond "I don't want belly rubs, I told you I am tired!"))]))
  81. ("belly" (cond [(equal? "rub?" (car action-args))
  82. (if (= 0 (random 2))
  83. (respond "YES! I LIVE FOR BELLY RUBS!!")
  84. (respond "Nooo!! I am tired :C"))]
  85. [(equal? "rub" (car action-args))
  86. (if (= 0 (random 2))
  87. (respond "aaaaaahhhhh =W=")
  88. (respond "I don't want belly rubs, I told you I am tired!"))]))
  89. ("Los" (cond [(equal? "Patos" (car action-args))
  90. (respond (format #f "Hi ~a Me gusta perseguir patos :)" speaker))]
  91. [(equal? "patos" (car action-args))
  92. (respond (format #f "Hi ~a Me gusta perseguir patos :)" speaker))]))
  93. ((or "hug" "Hug" "hugs" "Hugs")
  94. (respond (format #f "*wags tail pant pant pant thanks ~a!! i love you too!*" speaker)))
  95. ("say" (if (equal? "to" (car action-args))
  96. (respond (format #f "~a from ~a" (list->string (cdr action-args)) speaker))
  97. (respond (string-join action-args " "))))
  98. ;; Default
  99. (_ (respond (if (= 0 (random 2))
  100. "*stupid puppy look*"
  101. "*happily wags tail*")))))))))
  102. (run-bot #:username "Puppy_Bot"); be creative!