aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-03-11 12:23:55 +0100
committerAdrian Kummerlaender2016-03-11 12:23:55 +0100
commit4de7383ed16f9908c34afb893374f4dd01fbfc06 (patch)
treeed6ab70cac64a0f823132c835572d39b0a6f7bcc
parentcfa925fb53107178c3e346a212c75a77d6c04357 (diff)
downloadTelebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar.gz
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar.bz2
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar.lz
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar.xz
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.tar.zst
Telebot-4de7383ed16f9908c34afb893374f4dd01fbfc06.zip
Simplify JSON result interpretation logic
-rw-r--r--bot.scm31
1 files changed, 14 insertions, 17 deletions
diff --git a/bot.scm b/bot.scm
index 1802277..bbd658d 100644
--- a/bot.scm
+++ b/bot.scm
@@ -1,42 +1,39 @@
(include "telebot.scm")
(import (prefix telebot telebot:))
-(use vector-lib)
(use loops)
+(use vector-lib)
+(use data-structures)
(define (assure-list value)
(if (list? value)
value
(list)))
-(define (find-pair symbol nodes)
- (find (lambda (x) (equal? symbol (car x)))
- (filter pair? nodes)))
-
(define (resolve-query query tree)
- (fold-right (lambda (x y) (find-pair x (assure-list y)))
+ (fold-right (lambda (x y) (alist-ref x (assure-list y)))
tree
(reverse query)))
(define (updates-for-each func updates)
(vector-for-each (lambda (i u) (func u))
- (cdr updates)))
+ updates))
(define offset 0)
(define token (car (command-line-arguments)))
(define (print-message msg)
- (print (cdr (resolve-query (list 'message 'from 'first_name) msg))
- ": "
- (cdr (resolve-query (list 'message 'text) msg))
- " ("
- (cdr (resolve-query (list 'update_id) msg))
- ")"))
+ (print (resolve-query (list 'message 'from 'first_name) msg)
+ ": "
+ (resolve-query (list 'message 'text) msg)
+ " ("
+ (resolve-query (list 'update_id) msg)
+ ")"))
(define (echo-message msg)
- (let ((chat_id (cdr (resolve-query (list 'message 'from 'id) msg)))
- (text (cdr (resolve-query (list 'message 'text) msg)))
- (message_id (cdr (resolve-query (list 'message 'message_id) msg))))
+ (let ((chat_id (resolve-query (list 'message 'from 'id) msg))
+ (text (resolve-query (list 'message 'text) msg))
+ (message_id (resolve-query (list 'message 'message_id) msg)))
(telebot:sendMessage token
chat_id: chat_id
text: text
@@ -47,7 +44,7 @@
(begin (print-message u)
(echo-message u)
(set! offset
- (+ 1 (cdr (resolve-query (list 'update_id) u))))))
+ (+ 1 (resolve-query (list 'update_id) u)))))
(resolve-query (list 'result)
(telebot:getUpdates token
offset: offset