diff options
author | Adrian Kummerlaender | 2016-03-13 12:26:15 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-03-13 12:26:15 +0100 |
commit | cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0 (patch) | |
tree | 4d38210edd1aa356e1cc77889853e42ef017dbf8 | |
parent | 5f641ea6e243dc070e3e041d513a9d02996337c2 (diff) | |
download | Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar.gz Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar.bz2 Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar.lz Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar.xz Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.tar.zst Telebot-cbe9488ff46b05f196708c25d15bfa3c0b5ab0a0.zip |
Move basic update polling into `pollUpdates` framework function
-rw-r--r-- | bot.scm | 21 | ||||
-rw-r--r-- | telebot.scm | 18 |
2 files changed, 21 insertions, 18 deletions
@@ -1,8 +1,6 @@ (include "telebot.scm") (import (prefix telebot telebot:)) -(use loops) -(use vector-lib) (use data-structures) (define (resolve-query query tree) @@ -10,11 +8,6 @@ tree query)) -(define (updates-for-each func updates) - (vector-for-each (lambda (i u) (func u)) - updates)) - -(define offset 0) (define token (car (command-line-arguments))) (define (print-message msg) @@ -32,13 +25,7 @@ chat_id: chat_id text: text))) -(do-forever - (updates-for-each (lambda (u) - (begin (print-message u) - (echo-message u) - (set! offset - (+ 1 (resolve-query '(update_id) u))))) - (resolve-query '(result) - (telebot:getUpdates token - offset: offset - timeout: 60)))) +(telebot:pollUpdates token + (lambda (u) + (begin (print-message u) + (echo-message u)))) diff --git a/telebot.scm b/telebot.scm index 7453cb1..d419c79 100644 --- a/telebot.scm +++ b/telebot.scm @@ -4,12 +4,15 @@ sendLocation sendChatAction forwardMessage - getUserProfilePhotos) + getUserProfilePhotos + pollUpdates) (import chicken scheme) (use srfi-1) (use openssl) (use http-client) (use medea) + (use loops) + (use vector-lib) (define-constant api-base "https://api.telegram.org/bot") @@ -70,4 +73,17 @@ (wrap-api-method getUserProfilePhotos(user_id offset limit)) + + ;;; framework + + (define (pollUpdates token handler) + (define offset 0) + (define process (lambda (i u) + (begin (handler u) + (set! offset (+ 1 (cdr (assv 'update_id u))))))) + (do-forever + (vector-for-each process + (cdr (assv 'result (getUpdates token + offset: offset + timeout: 60)))))) ) |