tescort.lisp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (in-package :cl-user)
  2. (defpackage chatikbot.plugins.tescort
  3. (:use :cl :chatikbot.common :chatikbot.scraping :eager-future2))
  4. (in-package :chatikbot.plugins.tescort)
  5. (defvar *chat-cookie-jars* (make-hash-table))
  6. (defparameter +blacklists+
  7. '((:tescort
  8. (:scrape (:request . ("http://www.tescort.com/panel/client-blacklist"
  9. :parameters (("client_criterias" . q)
  10. ("search" . "search"))))
  11. (:items . ".black_list_table tbody tr")
  12. (:info (:date . ("td:nth-of-type(1)"))
  13. (:name . ("td:nth-of-type(2)"))
  14. (:city . ("td:nth-of-type(3)"))
  15. (:phone . ("td:nth-of-type(4)"))
  16. (:comment . ("td:nth-of-type(5)"))))
  17. (:init . (("http://www.tescort.com/private/signin")
  18. ".signin-box form"
  19. (("username" . tescort-login)
  20. ("password" . tescort-pass))))
  21. (:validate . "#header .sitemenu-logged"))
  22. (:annonce
  23. (:scrape (:request . ("https://www.6annonce.com/private-v2/client-blacklist"
  24. :parameters (("client_criterias" . q)
  25. ("search" . "search"))))
  26. (:items . ".black_list_table tbody tr")
  27. (:info (:date . ("td:nth-of-type(1)"))
  28. (:name . ("td:nth-of-type(2)"))
  29. (:city . ("td:nth-of-type(3)"))
  30. (:phone . ("td:nth-of-type(4)"))
  31. (:comment . ("td:nth-of-type(5)"))))
  32. (:init . (("https://www.6annonce.com/private/signin")
  33. ".signin-box form"
  34. (("username" . annonce-login)
  35. ("password" . annonce-pass))))
  36. (:validate . "#header .sitemenu-logged"))))
  37. (defvar *tescort-login*)
  38. (defvar *tescort-pass*)
  39. (defvar *annonce-login*)
  40. (defvar *annonce-pass*)
  41. (defun get-common-context ()
  42. `((tescort-login . ,*tescort-login*)
  43. (tescort-pass . ,*tescort-pass*)
  44. (annonce-login . ,*annonce-login*)
  45. (annonce-pass . ,*annonce-pass*)))
  46. (defun search-blacklists (query)
  47. (let ((context (append (get-common-context)
  48. `((q . ,query)))))
  49. (labels ((f (info)
  50. (destructuring-bind (name . params) info
  51. (cons name (ignore-errors (scrape-list params context))))))
  52. (pmapcar #'f +blacklists+))))
  53. (defun merge-results (results)
  54. (loop for (name . res) in results append res))
  55. (defun format-blacklist (item)
  56. (format nil "~A, ~A: ~A *~A*~%~A"
  57. (agets item :date) (agets item :city)
  58. (agets item :name) (agets item :phone)
  59. (agets item :comment)))
  60. (defun handle-blacklist (chat-id query)
  61. (with-chat-cookies (chat-id *chat-cookie-jars*)
  62. (telegram-send-chat-action chat-id "typing")
  63. (let ((results (merge-results (search-blacklists query))))
  64. (bot-send-message chat-id (if results
  65. (text-chunks (mapcar #'format-blacklist results)
  66. :pre-pre "" :pre-post "")
  67. "Not found")
  68. :parse-mode "markdown" :disable-web-preview "true"))))
  69. (def-message-cmd-handler handler-cmd-blacklist (:blacklist :bl)
  70. (cond
  71. ((null args) (bot-send-message chat-id "Enter query")
  72. (on-next-message chat-id
  73. (handle-blacklist chat-id text)))
  74. (:otherwise (handle-blacklist chat-id (spaced args)))))