summaryrefslogtreecommitdiff
path: root/src/bot/methods.lisp
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-10-09 21:58:43 +0300
committerGravatar Uko Kokņevičs2025-10-09 21:58:43 +0300
commit4da3ad1f569832845b58c3ce35149633a2bb665c (patch)
tree5a09a0de66df7ec2e77f0fc9cc68ccbabc190934 /src/bot/methods.lisp
downloadukkoclot-4da3ad1f569832845b58c3ce35149633a2bb665c.tar.gz
ukkoclot-4da3ad1f569832845b58c3ce35149633a2bb665c.tar.xz
ukkoclot-4da3ad1f569832845b58c3ce35149633a2bb665c.zip
Initial commit
Diffstat (limited to 'src/bot/methods.lisp')
-rw-r--r--src/bot/methods.lisp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/bot/methods.lisp b/src/bot/methods.lisp
new file mode 100644
index 0000000..b0eca5c
--- /dev/null
+++ b/src/bot/methods.lisp
@@ -0,0 +1,88 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/bot/methods
4 (:use :c2cl :ukkoclot/bot/impl :ukkoclot/tg-types :ukkoclot/tg-types/macros)
5 (:export :answer-callback-query :bot-id :bot-username :delete-message :edit-message-text :get-me :get-updates :send-message :set-my-name))
6(in-package :ukkoclot/bot/methods)
7
8(define-tg-method (answer-callback-query boolean "answerCallbackQuery" #'identity)
9 (callback-query-id string)
10 (text (or string null) nil)
11 (show-alert boolean nil)
12 (url (or string null) nil)
13 (cache-time (or integer null) nil))
14
15(defun bot-id (bot)
16 (or (bot-id% bot)
17 (progn
18 (get-me bot)
19 (bot-id% bot))))
20
21(defun bot-username (bot)
22 (or (bot-username% bot)
23 (progn
24 (get-me bot)
25 (bot-username% bot))))
26
27(define-tg-method (delete-message boolean "deleteMessage" #'identity)
28 (chat-id (or integer string))
29 (message-id integer))
30
31(define-tg-method (edit-message-text message "editMessageText" #'hash->message)
32 (business-connection-id (or string null) nil)
33 (chat-id (or integer string null) nil)
34 (message-id (or integer null) nil)
35 (inline-message-id (or string null) nil)
36 (text string)
37 (parse-mode (or string null) nil)
38 (entities (or (array message-entity) null) nil)
39 (link-preview-options (or link-preview-options null) nil)
40 (reply-markup (or inline-keyboard-markup null) nil))
41
42(define-tg-method (get-me% user "getMe" #'hash->user :GET))
43
44(defun get-me (bot)
45 (let ((res (get-me% bot)))
46 (setf (bot-id% bot) (user-id res))
47 (setf (bot-username% bot) (user-username res))
48 res))
49
50(define-tg-method (get-my-name bot-name "getMyName" #'hash->bot-name :GET)
51 (language-code (or string null) nil))
52
53(define-tg-method (get-updates (array update) "getUpdates" #'parse-update-array)
54 (offset (or integer null) nil)
55 (limit (or integer null) nil)
56 (timeout (or integer null) nil)
57 (allowed-updates (or string null) nil))
58
59(define-tg-method (send-message message "sendMessage" #'hash->message)
60 (business-connection-id (or string null) nil)
61 (chat-id (or integer string))
62 (message-thread-id (or integer null) nil)
63 (text string)
64 ;; TODO: parse-mode should maybe be keywords?
65 (parse-mode (or string null) nil)
66 (entities (or (array message-entity) null) nil)
67 (link-preview-options (or link-preview-options null) nil)
68 (disable-notification (or boolean null) nil)
69 (protect-content (or boolean null) nil)
70 (message-effect-id (or string null) nil)
71 (reply-parameters (or reply-parameters null) nil)
72 (reply-markup (or inline-keyboard-markup
73 ;; TODO: reply-keyboard-markup
74 ;; TODO: reply-keyboard-remove
75 force-reply null) nil))
76
77(define-tg-method (set-my-name% boolean "setMyName" #'identity)
78 (name (or string null) nil)
79 (language-code (or string null) nil))
80
81(defun set-my-name (bot &key (name nil) (language-code nil))
82 (block nil
83 (when name
84 (let ((curr-name (get-my-name bot :language-code language-code)))
85 (when (string= name (bot-name-name curr-name))
86 (return))))
87 (unless (set-my-name% bot :name name :language-code language-code)
88 (error "Failed to set name"))))