cl-telegram-bot/example.lisp

37 lines
1 KiB
Common Lisp
Raw Normal View History

2016-08-14 04:35:03 +02:00
(require 'cl-ppcre)
(require 'cl-telegram-bot)
(defpackage :example-bot
2016-08-17 19:55:19 +02:00
(:use #:cl-telegram-bot)
(:use #:cl))
2016-08-14 04:35:03 +02:00
(in-package :example-bot)
(defun match-command (regex text function)
(multiple-value-bind (msg match)
2016-08-18 04:24:09 +02:00
(cl-ppcre:scan-to-strings regex text)
2016-08-14 04:35:03 +02:00
(when match
(funcall function msg match))))
2016-08-18 04:24:09 +02:00
(let ((bot (make-bot "123456789:YOUR TOKEN HERE")))
2016-08-14 04:35:03 +02:00
(loop
2016-08-18 04:34:24 +02:00
(with-package :example-bot
2016-08-14 04:35:03 +02:00
(loop for update across (get-updates bot) do
2016-08-18 04:24:09 +02:00
(let* ((message (access update 'message))
2016-08-14 04:35:03 +02:00
(text (access message 'text))
(message-id (access message 'message--id))
(chat-id (access message 'chat 'id))
(first-name (access message 'from 'first--name)))
(format t "---~%ID: ~a~%chat: ~a~%user: ~a~%text: <<~a>>~%"
message-id
chat-id
first-name
text)
(when text
(match-command "^/echo (.*)$" text
(lambda (msg args)
2016-08-18 04:34:24 +02:00
(send-message bot
2016-08-14 04:35:03 +02:00
chat-id
2016-08-18 04:34:24 +02:00
(elt args 0))))))))
2016-08-14 04:35:03 +02:00
(sleep 1)))