aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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!")))))