From ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e Mon Sep 17 00:00:00 2001 From: Christoph Lange Date: Mon, 30 Apr 2018 15:39:01 +0200 Subject: Abstract 'is-message?': returns #t for message and edited_message - in 'resolve-query': return '() instead of default #f from 'alist-ref': this way it doesn't fail when passed to 'fold' and didn't find anything, which expects a list and not a boolean; cleaner also: always returns what it found, even if it's nothing (empty list) - then: check for '() instead of #f - change 'update-predicate' to expect a list of lists: e.g. the update can have _either_ (message text) _or_ (edited_message text) to be a message of type text --- telebot.scm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/telebot.scm b/telebot.scm index 3970588..eda1a0e 100644 --- a/telebot.scm +++ b/telebot.scm @@ -57,7 +57,7 @@ cleaned-parameters))) (define (resolve-query query tree) - (fold (lambda (x y) (alist-ref x y)) + (fold (lambda (x y) (alist-ref x y eqv? '())) tree query)) @@ -246,18 +246,20 @@ next_offset)) ;;; framework + (define (is-update-type? type update) + (not (equal? '() (resolve-query type update)))) - (define (update-predicate type) + (define (update-predicate types) (lambda (update) - (not (equal? #f (resolve-query type update))))) + (any (lambda (type) (is-update-type? type update)) types))) - (define is-message? (update-predicate '(message))) - (define is-edited_message? (update-predicate '(edited_message))) - (define is-inline_query? (update-predicate '(inline_query))) - (define is-chosen_inline_result? (update-predicate '(chosen_inline_result))) + (define is-message? (update-predicate '((message) (edited_message)) )) + (define is-edited_message? (update-predicate '((edited_message)) )) + (define is-inline_query? (update-predicate '((inline_query)) )) + (define is-chosen_inline_result? (update-predicate '((chosen_inline_result)) )) - (define is-text? (update-predicate '(message text))) - (define is-location? (update-predicate '(message location))) + (define is-text? (update-predicate '((message text) (edited_message text)) )) + (define is-location? (update-predicate '((message location) (edited_message location)) )) (define (poll-updates token handler) (let ((offset 0)) -- cgit v1.2.3