vk.lisp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. (in-package #:chatikbot)
  2. (defparameter +vk-api-url+ "https://api.vk.com/method/~A?v=5.34" "VK.com API endpoint")
  3. (defun %vk-api-call (method &optional args)
  4. (handler-case
  5. (bordeaux-threads:with-timeout (5)
  6. (let* ((params (loop for (k . v) in args
  7. when v
  8. collect (cons
  9. (princ-to-string k)
  10. (princ-to-string v))))
  11. (response (yason:parse
  12. (flexi-streams:octets-to-string
  13. (drakma:http-request (format nil +vk-api-url+ method)
  14. :method :post
  15. :parameters params
  16. :external-format-out :utf8)
  17. :external-format :utf8)
  18. :object-as :alist)))
  19. (when (aget "error" response)
  20. (error (aget "error_msg" (aget "error" response))))
  21. (aget "response" response)))
  22. (bordeaux-threads:timeout (e)
  23. (declare (ignore e))
  24. (error "Timeout"))))
  25. (defun vk-wall-get (&key owner-id domain offset count filter extended)
  26. (%vk-api-call "wall.get"
  27. (list (cons "owner_id" owner-id)
  28. (cons "domain" domain)
  29. (cons "offset" offset)
  30. (cons "count" count)
  31. (cons "filter" filter)
  32. (cons "extended" extended))))