|
|
@@ -1,38 +1,62 @@
|
|
|
(in-package :cl-user)
|
|
|
(defpackage chatikbot.plugins.tescort
|
|
|
- (:use :cl :chatikbot.common :chatikbot.scraping))
|
|
|
+ (:use :cl :chatikbot.common :chatikbot.scraping :eager-future2))
|
|
|
(in-package :chatikbot.plugins.tescort)
|
|
|
|
|
|
-(defparameter +login-form+
|
|
|
- '(("http://www.tescort.com/private/signin")
|
|
|
- ".signin-box form"
|
|
|
- (("username" . login)
|
|
|
- ("password" . pass))))
|
|
|
-
|
|
|
-(defparameter +blacklist-search+
|
|
|
- '(("http://www.tescort.com/panel/client-blacklist" :parameters (("client_criterias" . q)
|
|
|
- ("search" . "search")))
|
|
|
- ".black_list_table tbody tr"
|
|
|
- ((:date . ("td:nth-of-type(1)"))
|
|
|
- (:name . ("td:nth-of-type(2)"))
|
|
|
- (:city . ("td:nth-of-type(3)"))
|
|
|
- (:phone . ("td:nth-of-type(4)"))
|
|
|
- (:comment . ("td:nth-of-type(5)")))))
|
|
|
-
|
|
|
-(defvar *login*)
|
|
|
-(defvar *pass*)
|
|
|
-(defun login ()
|
|
|
- (let ((dom (do-form +login-form+ `((login . ,*login*) (pass . ,*pass*)))))
|
|
|
- (when (zerop (length (clss:select "#header .sitemenu-logged" dom)))
|
|
|
- (error "bad password"))
|
|
|
- dom))
|
|
|
-
|
|
|
-(defvar *tescort-cookie-jar* (cl-cookie:make-cookie-jar))
|
|
|
-(defun search-blacklist (query)
|
|
|
- (let ((*cookie-jar* *tescort-cookie-jar*))
|
|
|
- (unless (have-cookies (car +blacklist-search+))
|
|
|
- (login))
|
|
|
- (scrape-list +blacklist-search+ `((q . ,query)))))
|
|
|
+(defvar *chat-cookie-jars* (make-hash-table))
|
|
|
+
|
|
|
+(defparameter +blacklists+
|
|
|
+ '((:tescort
|
|
|
+ (:scrape (:request . ("http://www.tescort.com/panel/client-blacklist"
|
|
|
+ :parameters (("client_criterias" . q)
|
|
|
+ ("search" . "search"))))
|
|
|
+ (:items . ".black_list_table tbody tr")
|
|
|
+ (:info (:date . ("td:nth-of-type(1)"))
|
|
|
+ (:name . ("td:nth-of-type(2)"))
|
|
|
+ (:city . ("td:nth-of-type(3)"))
|
|
|
+ (:phone . ("td:nth-of-type(4)"))
|
|
|
+ (:comment . ("td:nth-of-type(5)"))))
|
|
|
+ (:init . (("http://www.tescort.com/private/signin")
|
|
|
+ ".signin-box form"
|
|
|
+ (("username" . tescort-login)
|
|
|
+ ("password" . tescort-pass))))
|
|
|
+ (:validate . "#header .sitemenu-logged"))
|
|
|
+ (:annonce
|
|
|
+ (:scrape (:request . ("https://www.6annonce.com/private-v2/client-blacklist"
|
|
|
+ :parameters (("client_criterias" . q)
|
|
|
+ ("search" . "search"))))
|
|
|
+ (:items . ".black_list_table tbody tr")
|
|
|
+ (:info (:date . ("td:nth-of-type(1)"))
|
|
|
+ (:name . ("td:nth-of-type(2)"))
|
|
|
+ (:city . ("td:nth-of-type(3)"))
|
|
|
+ (:phone . ("td:nth-of-type(4)"))
|
|
|
+ (:comment . ("td:nth-of-type(5)"))))
|
|
|
+ (:init . (("https://www.6annonce.com/private/signin")
|
|
|
+ ".signin-box form"
|
|
|
+ (("username" . annonce-login)
|
|
|
+ ("password" . annonce-pass))))
|
|
|
+ (:validate . "#header .sitemenu-logged"))))
|
|
|
+
|
|
|
+(defvar *tescort-login*)
|
|
|
+(defvar *tescort-pass*)
|
|
|
+(defvar *annonce-login*)
|
|
|
+(defvar *annonce-pass*)
|
|
|
+(defun get-common-context ()
|
|
|
+ `((tescort-login . ,*tescort-login*)
|
|
|
+ (tescort-pass . ,*tescort-pass*)
|
|
|
+ (annonce-login . ,*annonce-login*)
|
|
|
+ (annonce-pass . ,*annonce-pass*)))
|
|
|
+
|
|
|
+(defun search-blacklists (query)
|
|
|
+ (let ((context (append (get-common-context)
|
|
|
+ `((q . ,query)))))
|
|
|
+ (labels ((f (info)
|
|
|
+ (destructuring-bind (name . params) info
|
|
|
+ (cons name (ignore-errors (scrape-list params context))))))
|
|
|
+ (pmapcar #'f +blacklists+))))
|
|
|
+
|
|
|
+(defun merge-results (results)
|
|
|
+ (loop for (name . res) in results append res))
|
|
|
|
|
|
(defun format-blacklist (blacklist)
|
|
|
(with-output-to-string (s)
|
|
|
@@ -43,12 +67,13 @@
|
|
|
(agets item :comment)))))
|
|
|
|
|
|
(defun handle-blacklist (chat-id query)
|
|
|
- (telegram-send-chat-action chat-id "typing")
|
|
|
- (let ((results (search-blacklist query)))
|
|
|
- (bot-send-message chat-id (if results (format-blacklist results) "Not found")
|
|
|
- :parse-mode "markdown" :disable-web-preview "true")))
|
|
|
+ (with-chat-cookies (chat-id *chat-cookie-jars*)
|
|
|
+ (telegram-send-chat-action chat-id "typing")
|
|
|
+ (let ((results (merge-results (search-blacklists query))))
|
|
|
+ (bot-send-message chat-id (if results (format-blacklist results) "Not found")
|
|
|
+ :parse-mode "markdown" :disable-web-preview "true"))))
|
|
|
|
|
|
-(def-message-cmd-handler handler-cmd-blacklist (:blacklist)
|
|
|
+(def-message-cmd-handler handler-cmd-blacklist (:blacklist :bl)
|
|
|
(cond
|
|
|
((null args) (bot-send-message chat-id "Enter query")
|
|
|
(on-next-message chat-id
|