tescort.lisp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 (blacklist)
  56. (with-output-to-string (s)
  57. (loop for item in blacklist
  58. do (format s "~A, ~A: ~A *~A*~%~A~%~%"
  59. (agets item :date) (agets item :city)
  60. (agets item :name) (agets item :phone)
  61. (agets item :comment)))))
  62. (defun handle-blacklist (chat-id query)
  63. (with-chat-cookies (chat-id *chat-cookie-jars*)
  64. (telegram-send-chat-action chat-id "typing")
  65. (let ((results (merge-results (search-blacklists query))))
  66. (bot-send-message chat-id (if results (format-blacklist results) "Not found")
  67. :parse-mode "markdown" :disable-web-preview "true"))))
  68. (def-message-cmd-handler handler-cmd-blacklist (:blacklist :bl)
  69. (cond
  70. ((null args) (bot-send-message chat-id "Enter query")
  71. (on-next-message chat-id
  72. (handle-blacklist chat-id text)))
  73. (:otherwise (handle-blacklist chat-id (spaced args)))))