eliza.lisp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. (in-package #:chatikbot)
  2. (defparameter *fuck-off*
  3. '((отъебись) (мне похуй) (ебаный ты нахуй!))
  4. "Fuck-off responses")
  5. (defun goto-p (input) (member input '(иди пошел вали)))
  6. (defun prep-p (i) (member i '(в на)))
  7. (defun dirty-p (i) (member i '(лох хуй мудак ебалай)))
  8. (defparameter *eliza-rules*
  9. `(
  10. (((?is ?g goto-p) (?is ?prep prep-p) (?* ?х))
  11. (а самому не пойти ?prep ?х ?) (мамку свою посылай ?prep ?х) (покомандуй тут еще) ,@*fuck-off*)
  12. (((?is ?g goto-p) (?* ?x))
  13. (сам иди ?x) (покомандуй тут еще) ,@*fuck-off*)
  14. (((?* ?a) (?or норм хорошо молодец) (?* ?b))
  15. (спасибо) (я старался) (как себе) ,@*fuck-off*)
  16. (((?or спасибо) (?* ?x))
  17. (всё для вас) (пожалуйста) (на здоровье) ,@*fuck-off*)
  18. (((?* ?x) (?or уровень) (?* ?y))
  19. (в жопу себе его засунь) (хуюровень) ,@*fuck-off*)
  20. (((?* ?a) (?is ?x ,(lambda (i) (search "ХАХА" (symbol-name i)))) (?* ?b))
  21. (очень смешно) (клоунов тут нашел?) (посмейся мне еще) ,@*fuck-off*)
  22. (((?* ?a) (?or ты бот) (?* ?x))
  23. (сам ?x) (сам ты ?x) (а по ебалу?) (сейчас мы разберемся кто еще тут ?x) ,@*fuck-off*)
  24. (((?* x))
  25. (:text . "И чё?")
  26. (:text . "Сам-то понял?")
  27. (:text . "Ну хуй знает")
  28. (:text . "Бля...")
  29. (:text . "В душе не ебу")
  30. (:text . "Мне похуй")
  31. (:text . "Eбаный ты нахуй")
  32. (:text . "Отъебись")
  33. (:sticker . "BQADAgADFAADOoERAAGoLKS_Vgs6GgI") ;; ЭЭ епта Чо
  34. (:sticker . "BQADAgADGQADOoERAAFDXJisD4fClgI") ;; Ну чё ты несёшь
  35. (:sticker . "BQADAgADFwADOoERAAHCw-fBiFjACgI") ;; А у меня собака, я не могу
  36. (:sticker . "BQADAgADEgADOoERAAFtU3uF9HvtQgI") ;; Бухнём?
  37. (:sticker . "BQADBAADQAEAAnscSQABqWydSKTnASoC"))))
  38. (defun punctuation-p (char)
  39. (find char ".,;:'!?#-()\\\""))
  40. (defun read-from-string-no-punct (input)
  41. "Read from an input string, ignoring punctuation."
  42. (read-from-string
  43. (concatenate 'string
  44. "("
  45. (substitute-if #\space #'punctuation-p input)
  46. ")")))
  47. (defun print-with-spaces (list)
  48. (format nil "~@(~{~a~^ ~}~)" list))
  49. (defun mappend (fn &rest lists)
  50. "Apply fn to each element of lists and append the results."
  51. (apply #'append (apply #'mapcar fn lists)))
  52. (defun random-elt (choices)
  53. "Choose an element from a list at random."
  54. (elt choices (random (length choices))))
  55. (defun flatten (the-list)
  56. "Append together elements (or lists) in the list."
  57. (mappend #'(lambda (x) (if (listp x) (flatten x) (list x))) the-list))
  58. (defun switch-viewpoint (words)
  59. "Change I to you and vice versa, and so on."
  60. (sublis '((I . you) (you . I) (me . you) (am . are)
  61. (я ты) (ты я) (меня тебя) (тебя меня))
  62. words))
  63. (defun use-eliza-rules (input)
  64. "Find some rule with which to transform the input."
  65. (rule-based-translator input *eliza-rules*
  66. :action #'(lambda (bindings responses)
  67. (sublis (switch-viewpoint bindings)
  68. (random-elt responses)))))
  69. (defun eliza (input)
  70. (let ((response (use-eliza-rules
  71. (read-from-string-no-punct input))))
  72. (when response
  73. (if (keywordp (first response))
  74. response
  75. (print-with-spaces (flatten response))))))