diff options
author | Christoph Lange | 2018-04-30 15:39:01 +0200 |
---|---|---|
committer | Christoph Lange | 2018-04-30 15:50:14 +0200 |
commit | ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e (patch) | |
tree | ed8b72b905586311ed9d38bef7f84907df9325f6 | |
parent | 94f572847c844608adf43bbac2bfc52838fc226b (diff) | |
download | Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar.gz Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar.bz2 Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar.lz Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar.xz Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.tar.zst Telebot-ebc0c51cdf832bb8a0fe0e4b9cc9bff8fab28e4e.zip |
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
-rw-r--r-- | telebot.scm | 20 |
1 files 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)) |