eliza.lisp 3.9 KB

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