|
@@ -1,6 +1,21 @@
|
|
|
(in-package #:chatikbot)
|
|
(in-package #:chatikbot)
|
|
|
|
|
|
|
|
-(defparameter +vk-api-url+ "https://api.vk.com/method/~A?v=5.40" "VK.com API endpoint")
|
|
|
|
|
|
|
+(defparameter +vk-api-ver+ "5.53" "vk api version to use")
|
|
|
|
|
+(defparameter +vk-api-url+ "https://api.vk.com/method/~A?v=~A" "vk.com API endpoint")
|
|
|
|
|
+(defparameter +vk-oauth-authorize+ "https://oauth.vk.com/authorize" "vk.com OAuth authrization endpoint")
|
|
|
|
|
+(defsetting *vk-app-client-id* nil "vk app to authenticate against")
|
|
|
|
|
+(defsetting *vk-app-client-secret* nil "vk app secret")
|
|
|
|
|
+
|
|
|
|
|
+(defparameter +vk-scope-mapping+
|
|
|
|
|
+ '((:notify . 1) (:friends . 2) (:photos . 4) (:audio . 8) (:video . 16) (:docs . 131072) (:notes . 2048)
|
|
|
|
|
+ (:pages . 128) (:pages-left . 256) (:status . 1024) (:offers . 32) (:questions . 64) (:wall . 8192)
|
|
|
|
|
+ (:groups . 262144) (:messages . 4096) (:email . 4194304) (:notifications . 524288) (:stats . 1048576)
|
|
|
|
|
+ (:ads . 32768) (:market . 134217728) (:offline . 65536)))
|
|
|
|
|
+
|
|
|
|
|
+(defun vk-get-authorization-url (&optional state &rest scopes)
|
|
|
|
|
+ (let ((scope (apply #'+ (mapcar #'(lambda (k) (cdr (assoc k +vk-scope-mapping+))) scopes))))
|
|
|
|
|
+ (format nil "~A?v=~A&client_id=~A&redirect_uri=~A/oauth~@[&scope=~A~]~@[&state=~A~]"
|
|
|
|
|
+ +vk-oauth-authorize+ +vk-api-ver+ *vk-app-client-id* *web-path* (unless (zerop scope) scope) state)))
|
|
|
|
|
|
|
|
(defun %vk-api-call (method &optional args)
|
|
(defun %vk-api-call (method &optional args)
|
|
|
(handler-case
|
|
(handler-case
|
|
@@ -10,7 +25,7 @@
|
|
|
collect (cons
|
|
collect (cons
|
|
|
(princ-to-string k)
|
|
(princ-to-string k)
|
|
|
(princ-to-string v))))
|
|
(princ-to-string v))))
|
|
|
- (response (json-request (format nil +vk-api-url+ method)
|
|
|
|
|
|
|
+ (response (json-request (format nil +vk-api-url+ method +vk-api-ver+)
|
|
|
:method :post
|
|
:method :post
|
|
|
:parameters params)))
|
|
:parameters params)))
|
|
|
(when (aget "error" response)
|
|
(when (aget "error" response)
|