tescort.lisp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. (:photos . ("td:nth-of-type(5) a" :attr :href :multiple t))))
  33. (:init . (("https://www.6annonce.com/private/signin")
  34. ".signin-box form"
  35. (("username" . annonce-login)
  36. ("password" . annonce-pass))))
  37. (:validate . "#header .sitemenu-logged"))))
  38. (defvar *tescort-login*)
  39. (defvar *tescort-pass*)
  40. (defvar *annonce-login*)
  41. (defvar *annonce-pass*)
  42. (defun get-common-context ()
  43. `((tescort-login . ,*tescort-login*)
  44. (tescort-pass . ,*tescort-pass*)
  45. (annonce-login . ,*annonce-login*)
  46. (annonce-pass . ,*annonce-pass*)))
  47. (defun search-blacklists (query)
  48. (let ((context (append (get-common-context)
  49. `((q . ,query)))))
  50. (labels ((f (info)
  51. (destructuring-bind (name . params) info
  52. (cons name (ignore-errors (scrape-list params context))))))
  53. (pmapcar #'f +blacklists+))))
  54. (defun merge-results (results)
  55. (loop for (name . res) in results append res))
  56. (defun format-blacklist (item)
  57. (format nil "~A, ~A: ~A *~A*~%~A~@[~%~A~]"
  58. (agets item :date) (agets item :city)
  59. (agets item :name) (agets item :phone)
  60. (agets item :comment)
  61. (when (agets item :photos)
  62. (format nil "~{[pic~A](~A)~^, ~}"
  63. (loop for i from 1 for p in (agets item :photos)
  64. append (list i p))))))
  65. (defun handle-blacklist (chat-id query)
  66. (with-chat-cookies (chat-id *chat-cookie-jars*)
  67. (telegram-send-chat-action chat-id "typing")
  68. (let ((results (merge-results (search-blacklists query))))
  69. (bot-send-message chat-id (if results
  70. (text-chunks (mapcar #'format-blacklist results)
  71. :pre-pre "" :pre-post "")
  72. "Not found")
  73. :parse-mode "markdown"))))
  74. (def-message-cmd-handler handler-cmd-blacklist (:blacklist :bl)
  75. (cond
  76. ((null args) (bot-send-message chat-id "Enter query")
  77. (on-next-message chat-id
  78. (handle-blacklist chat-id text)))
  79. (:otherwise (handle-blacklist chat-id (spaced args)))))