Procházet zdrojové kódy

VK wall parse links

Innokenty Enikeev před 10 roky
rodič
revize
831187efe4
2 změnil soubory, kde provedl 6 přidání a 1 odebrání
  1. 1 0
      chatikbot.asd
  2. 5 1
      chatikbot.lisp

+ 1 - 0
chatikbot.asd

@@ -7,6 +7,7 @@
                #:adw-charting-vecto
                #:bordeaux-threads
                #:cl-date-time-parser
+               #:cl-ppcre
                #:clon
                #:drakma
                #:flexi-streams

+ 5 - 1
chatikbot.lisp

@@ -471,10 +471,14 @@
     ((equal "photo" (aget "type" item))
      (%vk-find-best-photo (aget "photo" item)))))
 
+(defparameter +vk-link-scanner+ (cl-ppcre:create-scanner "\\[((id|club)\\d+)\\|([^\\]]*?)\\]") "vk linking regex")
+(defun %vk-format-text (text)
+  (cl-ppcre:regex-replace-all +vk-link-scanner+ text "[\\3](https://vk.com/\\1)"))
+
 (defun %vk-post-text (post)
   (alexandria:when-let (reposts (aget "copy_history" post))
     (setf post (car (last reposts))))
-  (let ((text (aget "text" post))
+  (let ((text (%vk-format-text (aget "text" post)))
         (attachs (format nil "~{~A~^~%~}"
                          (remove nil (mapcar #'%format-attachment
                                              (aget "attachments" post))))))