summaryrefslogtreecommitdiff
path: root/src/tg
diff options
context:
space:
mode:
Diffstat (limited to 'src/tg')
-rw-r--r--src/tg/answer-callback-query.lisp2
-rw-r--r--src/tg/delete-message.lisp2
-rw-r--r--src/tg/edit-message-text.lisp2
-rw-r--r--src/tg/get-me.lisp2
-rw-r--r--src/tg/get-my-name.lisp2
-rw-r--r--src/tg/get-updates.lisp2
-rw-r--r--src/tg/method-macros.lisp72
-rw-r--r--src/tg/send-animation.lisp2
-rw-r--r--src/tg/send-message.lisp2
-rw-r--r--src/tg/set-my-name.lisp2
10 files changed, 81 insertions, 9 deletions
diff --git a/src/tg/answer-callback-query.lisp b/src/tg/answer-callback-query.lisp
index badd8a4..c7ecb5f 100644
--- a/src/tg/answer-callback-query.lisp
+++ b/src/tg/answer-callback-query.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/answer-callback-query 3(defpackage :ukkoclot/tg/answer-callback-query
4 (:use :c2cl :ukkoclot/bot/method-macros) 4 (:use :c2cl :ukkoclot/tg/method-macros)
5 (:export :answer-callback-query)) 5 (:export :answer-callback-query))
6(in-package :ukkoclot/tg/answer-callback-query) 6(in-package :ukkoclot/tg/answer-callback-query)
7 7
diff --git a/src/tg/delete-message.lisp b/src/tg/delete-message.lisp
index fd6f323..54cfc8b 100644
--- a/src/tg/delete-message.lisp
+++ b/src/tg/delete-message.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/delete-message 3(defpackage :ukkoclot/tg/delete-message
4 (:use :c2cl :ukkoclot/tg/message :ukkoclot/bot/method-macros :ukkoclot/tg/send-animation) 4 (:use :c2cl :ukkoclot/tg/message :ukkoclot/tg/method-macros :ukkoclot/tg/send-animation)
5 (:export :delete-message :try-delete-message)) 5 (:export :delete-message :try-delete-message))
6(in-package :ukkoclot/tg/delete-message) 6(in-package :ukkoclot/tg/delete-message)
7 7
diff --git a/src/tg/edit-message-text.lisp b/src/tg/edit-message-text.lisp
index a7db3a8..65e2cc7 100644
--- a/src/tg/edit-message-text.lisp
+++ b/src/tg/edit-message-text.lisp
@@ -7,7 +7,7 @@
7 :ukkoclot/tg/link-preview-options 7 :ukkoclot/tg/link-preview-options
8 :ukkoclot/tg/message 8 :ukkoclot/tg/message
9 :ukkoclot/tg/message-entity 9 :ukkoclot/tg/message-entity
10 :ukkoclot/bot/method-macros 10 :ukkoclot/tg/method-macros
11 :ukkoclot/tg/parse-mode) 11 :ukkoclot/tg/parse-mode)
12 (:export :edit-message-text)) 12 (:export :edit-message-text))
13(in-package :ukkoclot/tg/edit-message-text) 13(in-package :ukkoclot/tg/edit-message-text)
diff --git a/src/tg/get-me.lisp b/src/tg/get-me.lisp
index cfb1304..e4a6de5 100644
--- a/src/tg/get-me.lisp
+++ b/src/tg/get-me.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-me 3(defpackage :ukkoclot/tg/get-me
4 (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/user) 4 (:use :c2cl :ukkoclot/tg/method-macros :ukkoclot/tg/user)
5 (:import-from :ukkoclot/state :bot-id% :bot-username%) 5 (:import-from :ukkoclot/state :bot-id% :bot-username%)
6 (:export :bot-id :bot-username :get-me)) 6 (:export :bot-id :bot-username :get-me))
7(in-package :ukkoclot/tg/get-me) 7(in-package :ukkoclot/tg/get-me)
diff --git a/src/tg/get-my-name.lisp b/src/tg/get-my-name.lisp
index 59bb753..a597fe0 100644
--- a/src/tg/get-my-name.lisp
+++ b/src/tg/get-my-name.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-my-name 3(defpackage :ukkoclot/tg/get-my-name
4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/bot/method-macros) 4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/tg/method-macros)
5 (:export :get-my-name)) 5 (:export :get-my-name))
6(in-package :ukkoclot/tg/get-my-name) 6(in-package :ukkoclot/tg/get-my-name)
7 7
diff --git a/src/tg/get-updates.lisp b/src/tg/get-updates.lisp
index 15f5e3f..5192e3c 100644
--- a/src/tg/get-updates.lisp
+++ b/src/tg/get-updates.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-updates 3(defpackage :ukkoclot/tg/get-updates
4 (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/update) 4 (:use :c2cl :ukkoclot/tg/method-macros :ukkoclot/tg/update)
5 (:export :get-updates)) 5 (:export :get-updates))
6(in-package :ukkoclot/tg/get-updates) 6(in-package :ukkoclot/tg/get-updates)
7 7
diff --git a/src/tg/method-macros.lisp b/src/tg/method-macros.lisp
new file mode 100644
index 0000000..3599328
--- /dev/null
+++ b/src/tg/method-macros.lisp
@@ -0,0 +1,72 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/method-macros
4 (:use :c2cl :iterate)
5 (:import-from :ukkoclot/state :bot)
6 (:import-from :ukkoclot/strings :ends-with :lisp->camel-case)
7 (:import-from :ukkoclot/transport :do-call)
8 (:export :define-tg-method))
9(in-package :ukkoclot/tg/method-macros)
10
11(eval-when (:compile-toplevel :load-toplevel :execute)
12 (defstruct (param (:constructor make-param%)) name type default skip-if-default)
13
14 (defparameter +unique+ (gensym))
15
16 (defun make-param (name type &optional (default +unique+) &key (skip-if-default (not (eq default +unique+))))
17 (let ((default (if (eq default +unique+)
18 `(error ,(format nil "No value given for ~A" name))
19 default)))
20 (make-param% :name name
21 :type type
22 :default default
23 :skip-if-default skip-if-default)))
24
25 (defun parse-param-specs (param-specs)
26 (iter (for param-spec in param-specs)
27 (collect (apply #'make-param param-spec))))
28
29 (defun path-from-name (name)
30 (let ((str (lisp->camel-case (symbol-name name))))
31 (if (ends-with str "%")
32 (subseq str 0 (- (length str) 1))
33 str)))
34
35 (defun emit-append-to-args (param args)
36 `(setf ,args (acons ',(param-name param) ,(param-name param) ,args)))
37
38 (defun emit-arg-type (param)
39 `(,(intern (symbol-name (param-name param)) :keyword)
40 ,(param-type param)))
41
42 (defun emit-defun-arg (param)
43 `(,(param-name param) ,(param-default param)))
44
45 (defun emit-defun (name return-type params method)
46 (let ((revparams (reverse params))
47 (args (gensym "ARGS"))
48 (bot (gensym "BOT")))
49 `(defun ,name (,bot &key ,@(iter (for param in params)
50 (collect (emit-defun-arg param))))
51 (let (,args)
52 ,@(iter (for param in revparams)
53 (collect (if (param-skip-if-default param)
54 `(unless (equal ,(param-name param)
55 ,(param-default param))
56 ,(emit-append-to-args param args))
57 (emit-append-to-args param args))))
58 (do-call ,bot ,method ,(path-from-name name) ',return-type ,args)))))
59
60 (defun emit-ftype (name return-type params)
61 `(declaim (ftype (function (bot &key ,@(iter (for param in params)
62 (collect (emit-arg-type param))))
63 ,return-type)
64 ,name))))
65
66(defmacro define-tg-method (
67 (name type &optional (method :POST))
68 &body param-specs)
69 (let ((params (parse-param-specs param-specs)))
70 `(progn
71 ,(emit-ftype name type params)
72 ,(emit-defun name type params method))))
diff --git a/src/tg/send-animation.lisp b/src/tg/send-animation.lisp
index 97dd9f0..1fd7a89 100644
--- a/src/tg/send-animation.lisp
+++ b/src/tg/send-animation.lisp
@@ -7,7 +7,7 @@
7 :ukkoclot/tg/inline-keyboard-markup 7 :ukkoclot/tg/inline-keyboard-markup
8 :ukkoclot/tg/message 8 :ukkoclot/tg/message
9 :ukkoclot/tg/message-entity 9 :ukkoclot/tg/message-entity
10 :ukkoclot/bot/method-macros 10 :ukkoclot/tg/method-macros
11 :ukkoclot/tg/parse-mode 11 :ukkoclot/tg/parse-mode
12 :ukkoclot/tg/reply-keyboard-markup 12 :ukkoclot/tg/reply-keyboard-markup
13 :ukkoclot/tg/reply-keyboard-remove 13 :ukkoclot/tg/reply-keyboard-remove
diff --git a/src/tg/send-message.lisp b/src/tg/send-message.lisp
index 7cd91d9..164dd83 100644
--- a/src/tg/send-message.lisp
+++ b/src/tg/send-message.lisp
@@ -8,7 +8,7 @@
8 :ukkoclot/tg/link-preview-options 8 :ukkoclot/tg/link-preview-options
9 :ukkoclot/tg/message 9 :ukkoclot/tg/message
10 :ukkoclot/tg/message-entity 10 :ukkoclot/tg/message-entity
11 :ukkoclot/bot/method-macros 11 :ukkoclot/tg/method-macros
12 :ukkoclot/tg/parse-mode 12 :ukkoclot/tg/parse-mode
13 :ukkoclot/tg/reply-keyboard-markup 13 :ukkoclot/tg/reply-keyboard-markup
14 :ukkoclot/tg/reply-keyboard-remove 14 :ukkoclot/tg/reply-keyboard-remove
diff --git a/src/tg/set-my-name.lisp b/src/tg/set-my-name.lisp
index 5638a92..1c6b634 100644
--- a/src/tg/set-my-name.lisp
+++ b/src/tg/set-my-name.lisp
@@ -1,7 +1,7 @@
1;; SPDX-License-Identifier: EUPL-1.2 1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com> 2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/set-my-name 3(defpackage :ukkoclot/tg/set-my-name
4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/tg/get-my-name :ukkoclot/bot/method-macros) 4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/tg/get-my-name :ukkoclot/tg/method-macros)
5 (:export :set-my-name)) 5 (:export :set-my-name))
6(in-package :ukkoclot/tg/set-my-name) 6(in-package :ukkoclot/tg/set-my-name)
7 7