summaryrefslogtreecommitdiff
path: root/src/bot/advanced.lisp
blob: 376315176bd572f169653b9738dd37b65ad30658 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;; SPDX-License-Identifier: EUPL-1.2
;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
(defpackage :ukkoclot/bot/advanced
  (:use :c2cl :ukkoclot/tg)
  (:import-from :ukkoclot/state :bot-id% :bot-username%)
  (:export :bot-id :bot-username :reply-animation :reply-message :try-delete-message))
(in-package :ukkoclot/bot/advanced)

(defun bot-id (bot)
  (or (bot-id% bot)
      (progn
        (get-me bot)
        (bot-id% bot))))

(defun bot-username (bot)
  (or (bot-username% bot)
      (progn
        (get-me bot)
        (bot-username% bot))))

;; TODO: Some kind of caching for files?
(defun reply-animation (bot msg animation &key allow-sending-without-reply text parse-mode caption-above)
  (send-animation bot
                  :chat-id (message-chat-id msg)
                  :animation animation
                  :caption text
                  :parse-mode parse-mode
                  :show-caption-above-media caption-above
                  :reply-parameters
                  (make-reply-parameters
                   :allow-sending-without-reply allow-sending-without-reply
                   :message-id (message-id msg)
                   :chat-id (message-chat-id msg))))

(defun reply-message (bot msg text &key parse-mode allow-sending-without-reply)
  (send-message bot
                :chat-id (message-chat-id msg)
                :text text
                :parse-mode parse-mode
                :reply-parameters
                (make-reply-parameters
                 :allow-sending-without-reply allow-sending-without-reply
                 :message-id (message-id msg)
                 :chat-id (message-chat-id msg))))

(defun try-delete-message (bot msg)
  (handler-case
      (delete-message bot
                      :chat-id (message-chat-id msg)
                      :message-id (message-id msg))
    (error ()
      (handler-case
          (reply-animation bot msg #P"blob/do-not.mp4"
                           :allow-sending-without-reply nil)
        (error () nil)))))