mirror of
https://github.com/vale981/cl-telegram-bot
synced 2025-03-04 17:21:41 -05:00
Use accessors for bot class slots (id & endpoint).
This commit is contained in:
parent
a24b2b55b2
commit
7bb9cfa849
1 changed files with 13 additions and 11 deletions
|
@ -29,19 +29,21 @@
|
|||
(defclass bot ()
|
||||
((id
|
||||
:documentation "Update id"
|
||||
:initform 0)
|
||||
:initform 0
|
||||
:accessor id)
|
||||
(token
|
||||
:initarg :token
|
||||
:documentation "Bot token given by BotFather"
|
||||
:initform Nil)
|
||||
:initform nil)
|
||||
(endpoint
|
||||
:initarg :endpoint
|
||||
:accessor endpoint
|
||||
:documentation "HTTPS endpoint"
|
||||
:initform Nil)))
|
||||
:initform nil)))
|
||||
|
||||
(defmethod initialize-instance :after ((b bot) &key)
|
||||
(setf (slot-value b 'endpoint)
|
||||
(concatenate 'string +telegram-api-uri+ (slot-value b 'token) "/")))
|
||||
(setf (endpoint b)
|
||||
(concatenate 'string +telegram-api-uri+ (endpoint b) "/")))
|
||||
|
||||
(defun make-bot (token)
|
||||
"Create a new bot instance. Takes a token string."
|
||||
|
@ -57,7 +59,7 @@
|
|||
(defun make-request (b name options)
|
||||
"Perform HTTP request to 'name API method with 'options JSON-encoded object."
|
||||
(drakma:http-request
|
||||
(concatenate 'string (slot-value b 'endpoint) name)
|
||||
(concatenate 'string (endpoint b) name)
|
||||
:method :post
|
||||
:want-stream t
|
||||
:content-type "application/json"
|
||||
|
@ -95,7 +97,7 @@
|
|||
|
||||
(defun get-updates (b &key limit timeout)
|
||||
"https://core.telegram.org/bots/api#getupdates"
|
||||
(let* ((current-id (slot-value b 'id))
|
||||
(let* ((current-id (id b))
|
||||
(cl-json:*json-symbols-package* :tl-bot)
|
||||
(request
|
||||
(decode (make-request b "getUpdates"
|
||||
|
@ -110,8 +112,8 @@
|
|||
(let* ((last-update (elt results (- (length results) 1)))
|
||||
(id (slot-value last-update 'update--id)))
|
||||
(when (= current-id 0)
|
||||
(setf (slot-value b 'id) id))
|
||||
(incf (slot-value b 'id))))
|
||||
(setf (id b) id))
|
||||
(incf (id b))))
|
||||
results))
|
||||
|
||||
(defun set-webhook (b &key url certificate)
|
||||
|
|
Loading…
Add table
Reference in a new issue