diff options
author | Adrian Kummerlaender | 2016-03-12 22:14:15 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-03-12 22:17:38 +0100 |
commit | 5f641ea6e243dc070e3e041d513a9d02996337c2 (patch) | |
tree | 20b5ec45752befc3554277606ba9ed8882f7d1cb | |
parent | c5dbb98ee5639883676414e4948923de46ba0a5d (diff) | |
download | Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar.gz Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar.bz2 Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar.lz Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar.xz Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.tar.zst Telebot-5f641ea6e243dc070e3e041d513a9d02996337c2.zip |
Remove unnecessary complexity in demo bot message parsing logic
-rw-r--r-- | bot.scm | 25 | ||||
-rw-r--r-- | telebot.scm | 2 |
2 files changed, 11 insertions, 16 deletions
@@ -5,15 +5,10 @@ (use vector-lib) (use data-structures) -(define (assure-list value) - (if (list? value) - value - (list))) - (define (resolve-query query tree) - (fold-right (lambda (x y) (alist-ref x (assure-list y))) - tree - (reverse query))) + (fold (lambda (x y) (alist-ref x y)) + tree + query)) (define (updates-for-each func updates) (vector-for-each (lambda (i u) (func u)) @@ -23,16 +18,16 @@ (define token (car (command-line-arguments))) (define (print-message msg) - (print (resolve-query (list 'message 'from 'first_name) msg) + (print (resolve-query '(message from first_name) msg) ": " - (resolve-query (list 'message 'text) msg) + (resolve-query '(message text) msg) " (" - (resolve-query (list 'update_id) msg) + (resolve-query '(update_id) msg) ")")) (define (echo-message msg) - (let ((chat_id (resolve-query (list 'message 'from 'id) msg)) - (text (resolve-query (list 'message 'text) msg))) + (let ((chat_id (resolve-query '(message from id) msg)) + (text (resolve-query '(message text) msg))) (telebot:sendMessage token chat_id: chat_id text: text))) @@ -42,8 +37,8 @@ (begin (print-message u) (echo-message u) (set! offset - (+ 1 (resolve-query (list 'update_id) u))))) - (resolve-query (list 'result) + (+ 1 (resolve-query '(update_id) u))))) + (resolve-query '(result) (telebot:getUpdates token offset: offset timeout: 60)))) diff --git a/telebot.scm b/telebot.scm index 294244d..7453cb1 100644 --- a/telebot.scm +++ b/telebot.scm @@ -11,7 +11,7 @@ (use http-client) (use medea) - (define api-base "https://api.telegram.org/bot") + (define-constant api-base "https://api.telegram.org/bot") ;;; helper functions |