diff options
author | Adrian Kummerlaender | 2016-03-11 12:23:55 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-03-11 12:23:55 +0100 |
commit | 4de7383ed16f9908c34afb893374f4dd01fbfc06 (patch) | |
tree | ed6ab70cac64a0f823132c835572d39b0a6f7bcc | |
parent | cfa925fb53107178c3e346a212c75a77d6c04357 (diff) | |
download | Telebot-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.scm | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -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 |