aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-03-16 13:26:19 +0100
committerAdrian Kummerlaender2016-03-16 13:26:19 +0100
commite5a1beddb41bd5341baf5237e331e472db94a23a (patch)
tree5feaeb46a1631c2bb24d8ab895c6ee941eb232ae /example
parenta6dbf20faf95ae892a805b8e83c131a4733f564f (diff)
downloadTelebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar.gz
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar.bz2
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar.lz
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar.xz
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.tar.zst
Telebot-e5a1beddb41bd5341baf5237e331e472db94a23a.zip
Simplified _guess_ example logging
Diffstat (limited to 'example')
-rw-r--r--example/guess.scm34
1 files changed, 13 insertions, 21 deletions
diff --git a/example/guess.scm b/example/guess.scm
index c3267ff..2215380 100644
--- a/example/guess.scm
+++ b/example/guess.scm
@@ -14,42 +14,34 @@
(define conversations (make-hash-table))
(define (send chat_id text)
+ (print chat_id " <- \"" text "\"")
(telebot:sendMessage token
chat_id: chat_id
text: text))
-(define (print-failed-guess chat_id answer guess)
- (print "User " chat_id " guessed " guess " instead of " answer))
-
(define (make-conversation chat_id)
- (let ((chat_id chat_id)
- (answer (random 100)))
+ (let ((chat_id chat_id)
+ (answer (random 100)))
(lambda (text)
(let ((guess (string->number text)))
- (if (equal? #f guess)
- (send chat_id
- "This is not a number - please provide your guess in base 10.")
+ (if (number? guess)
(cond ((= guess answer)
- (begin (send chat_id
- "Correct! Feel free to guess the next number.")
- (print "User " chat_id " correctly guessed " answer)
+ (begin (send chat_id "Correct! Feel free to guess the next number.")
(set! answer (random 100))))
- ((< guess answer)
- (begin (send chat_id
- "Too small. Try again.")
- (print-failed-guess chat_id answer guess)))
- ((> guess answer)
- (begin (send chat_id
- "Too large. Try again.")
- (print-failed-guess chat_id answer guess)))))))))
+ ((< guess answer) (send chat_id "Too small. Try again."))
+ ((> guess answer) (send chat_id "Too large. Try again.")))
+ (send chat_id
+ "This is not a number - please provide your guess in base 10."))))))
(define (handle-message m)
(let ((chat_id (resolve-query '(message from id) m))
(text (resolve-query '(message text) m)))
+ (print chat_id " -> \"" text "\"")
(if (hash-table-exists? conversations chat_id)
((hash-table-ref conversations chat_id) text)
- (begin (hash-table-set! conversations chat_id (make-conversation chat_id))
- (print "Started talking to user " chat_id)
+ (begin (hash-table-set! conversations
+ chat_id
+ (make-conversation chat_id))
(send chat_id
"Hi there! I just generated a random number for you to guess!")))))