summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-10-13 06:32:57 +0300
committerGravatar Uko Kokņevičs2025-10-13 06:32:57 +0300
commit9e424b351da370630924e32d0a84eba6fdb8c05e (patch)
tree60999a1b91e73c8aa74e43085e3c0be39d5ec8cf
parentImprove define-tg-method (diff)
downloadukkoclot-9e424b351da370630924e32d0a84eba6fdb8c05e.tar.gz
ukkoclot-9e424b351da370630924e32d0a84eba6fdb8c05e.tar.xz
ukkoclot-9e424b351da370630924e32d0a84eba6fdb8c05e.zip
Move bot/methods to tg/*
-rw-r--r--src/bot/advanced.lisp2
-rw-r--r--src/bot/methods.lisp97
-rw-r--r--src/inline-bots.lisp2
-rw-r--r--src/main.lisp2
-rw-r--r--src/tg.lisp9
-rw-r--r--src/tg/answer-callback-query.lisp13
-rw-r--r--src/tg/delete-message.lisp10
-rw-r--r--src/tg/edit-message-text.lisp25
-rw-r--r--src/tg/get-me.lisp15
-rw-r--r--src/tg/get-my-name.lisp9
-rw-r--r--src/tg/get-updates.lisp12
-rw-r--r--src/tg/send-animation.lisp40
-rw-r--r--src/tg/send-message.lisp31
-rw-r--r--src/tg/set-my-name.lisp19
14 files changed, 186 insertions, 100 deletions
diff --git a/src/bot/advanced.lisp b/src/bot/advanced.lisp
index c18b574..3763151 100644
--- a/src/bot/advanced.lisp
+++ b/src/bot/advanced.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/bot/advanced 3(defpackage :ukkoclot/bot/advanced
4 (:use :c2cl :ukkoclot/bot/methods :ukkoclot/tg) 4 (:use :c2cl :ukkoclot/tg)
5 (:import-from :ukkoclot/state :bot-id% :bot-username%) 5 (:import-from :ukkoclot/state :bot-id% :bot-username%)
6 (:export :bot-id :bot-username :reply-animation :reply-message :try-delete-message)) 6 (:export :bot-id :bot-username :reply-animation :reply-message :try-delete-message))
7(in-package :ukkoclot/bot/advanced) 7(in-package :ukkoclot/bot/advanced)
diff --git a/src/bot/methods.lisp b/src/bot/methods.lisp
deleted file mode 100644
index 6f01cae..0000000
--- a/src/bot/methods.lisp
+++ /dev/null
@@ -1,97 +0,0 @@
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/method-macros :ukkoclot/tg)
5 (:import-from :ukkoclot/state :bot-id% :bot-username%)
6 (:export :answer-callback-query :delete-message :send-animation :edit-message-text :get-me :get-updates :send-message :set-my-name))
7(in-package :ukkoclot/bot/methods)
8
9(define-tg-method (answer-callback-query boolean)
10 (callback-query-id string)
11 (text (or string null) nil)
12 (show-alert boolean nil)
13 (url (or string null) nil)
14 (cache-time (or integer null) nil))
15
16(define-tg-method (delete-message boolean)
17 (chat-id (or integer string))
18 (message-id integer))
19
20;; TODO: Add a way to simply specify :message msg :)
21(define-tg-method (edit-message-text message)
22 (business-connection-id (or string null) nil)
23 (chat-id (or integer string null) nil)
24 (message-id (or integer null) nil)
25 (inline-message-id (or string null) nil)
26 (text string)
27 (parse-mode (or parse-mode null) nil)
28 (entities (or (array message-entity) null) nil)
29 (link-preview-options (or link-preview-options null) nil)
30 (reply-markup (or inline-keyboard-markup null) nil))
31
32(define-tg-method (get-me% user :GET))
33
34(defun get-me (bot)
35 (let ((res (get-me% bot)))
36 (setf (bot-id% bot) (user-id res))
37 (setf (bot-username% bot) (user-username res))
38 res))
39
40(define-tg-method (get-my-name bot-name :GET)
41 (language-code (or string null) nil))
42
43(define-tg-method (get-updates (array update))
44 (offset (or integer null) nil)
45 (limit (or integer null) nil)
46 (timeout (or integer null) nil)
47 (allowed-updates (or string null) nil))
48
49(define-tg-method (send-animation message)
50 (business-connection-id (or string null) nil)
51 (chat-id (or integer string))
52 (message-thread-id (or integer null) nil)
53 (direct-messages-topic-id (or integer null) nil)
54 (animation (or pathname string))
55 (duration (or integer null) nil)
56 (width (or integer null) nil)
57 (height (or integer null) nil)
58 (thumbnail (or pathname string null) nil)
59 (caption (or string null) nil)
60 (parse-mode (or parse-mode null) nil)
61 (caption-entities (or (array message-entity) null) nil)
62 (show-caption-above-media boolean nil)
63 (has-spoiler boolean nil)
64 (disable-notification boolean nil)
65 (protect-content boolean nil)
66 (allow-paid-broadcast boolean nil)
67 (message-effect-id (or string null) nil)
68 (suggested-post-parameters (or suggested-post-parameters null) nil)
69 (reply-parameters (or reply-parameters null) nil)
70 (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil))
71
72(define-tg-method (send-message message)
73 (business-connection-id (or string null) nil)
74 (chat-id (or integer string))
75 (message-thread-id (or integer null) nil)
76 (text string)
77 (parse-mode (or parse-mode null) nil)
78 (entities (or (array message-entity) null) nil)
79 (link-preview-options (or link-preview-options null) nil)
80 (disable-notification (or boolean null) nil)
81 (protect-content (or boolean null) nil)
82 (message-effect-id (or string null) nil)
83 (reply-parameters (or reply-parameters null) nil)
84 (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil))
85
86(define-tg-method (set-my-name% boolean)
87 (name (or string null) nil)
88 (language-code (or string null) nil))
89
90(defun set-my-name (bot &key (name nil) (language-code nil))
91 (block nil
92 (when name
93 (let ((curr-name (get-my-name bot :language-code language-code)))
94 (when (string= name (bot-name-name curr-name))
95 (return))))
96 (unless (set-my-name% bot :name name :language-code language-code)
97 (error "Failed to set name"))))
diff --git a/src/inline-bots.lisp b/src/inline-bots.lisp
index 1d0d8ff..1c44fd4 100644
--- a/src/inline-bots.lisp
+++ b/src/inline-bots.lisp
@@ -4,7 +4,7 @@
4 (:use :c2cl :ukkoclot/config :ukkoclot/tg) 4 (:use :c2cl :ukkoclot/config :ukkoclot/tg)
5 (:import-from :log) 5 (:import-from :log)
6 (:import-from :ukkoclot/bot/advanced :try-delete-message) 6 (:import-from :ukkoclot/bot/advanced :try-delete-message)
7 (:import-from :ukkoclot/bot/methods :send-message) 7 (:import-from :ukkoclot/tg :send-message)
8 (:import-from :ukkoclot/state :bot-config :bot-db) 8 (:import-from :ukkoclot/state :bot-config :bot-db)
9 (:local-nicknames (:db :ukkoclot/db)) 9 (:local-nicknames (:db :ukkoclot/db))
10 (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot)) 10 (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot))
diff --git a/src/main.lisp b/src/main.lisp
index 522fb1b..1111100 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -2,7 +2,7 @@
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/main 3(defpackage :ukkoclot/main
4 (:nicknames :ukkoclot) 4 (:nicknames :ukkoclot)
5 (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg :ukkoclot/bot/methods :ukkoclot/bot/advanced) 5 (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg :ukkoclot/bot/advanced)
6 (:import-from :anaphora :acond :awhen :it) 6 (:import-from :anaphora :acond :awhen :it)
7 (:import-from :log) 7 (:import-from :log)
8 (:import-from :swank) 8 (:import-from :swank)
diff --git a/src/tg.lisp b/src/tg.lisp
index e12f04a..1ee7da0 100644
--- a/src/tg.lisp
+++ b/src/tg.lisp
@@ -4,6 +4,7 @@
4 (:use) 4 (:use)
5 (:use-reexport 5 (:use-reexport
6 :ukkoclot/tg/animation 6 :ukkoclot/tg/animation
7 :ukkoclot/tg/answer-callback-query
7 :ukkoclot/tg/bot-name 8 :ukkoclot/tg/bot-name
8 :ukkoclot/tg/business-bot-rights 9 :ukkoclot/tg/business-bot-rights
9 :ukkoclot/tg/business-connection 10 :ukkoclot/tg/business-connection
@@ -11,7 +12,12 @@
11 :ukkoclot/tg/chat 12 :ukkoclot/tg/chat
12 :ukkoclot/tg/chat-type 13 :ukkoclot/tg/chat-type
13 :ukkoclot/tg/chat-administrator-rights 14 :ukkoclot/tg/chat-administrator-rights
15 :ukkoclot/tg/delete-message
16 :ukkoclot/tg/edit-message-text
14 :ukkoclot/tg/force-reply 17 :ukkoclot/tg/force-reply
18 :ukkoclot/tg/get-me
19 :ukkoclot/tg/get-my-name
20 :ukkoclot/tg/get-updates
15 :ukkoclot/tg/inline-keyboard-button 21 :ukkoclot/tg/inline-keyboard-button
16 :ukkoclot/tg/inline-keyboard-markup 22 :ukkoclot/tg/inline-keyboard-markup
17 :ukkoclot/tg/keyboard-button 23 :ukkoclot/tg/keyboard-button
@@ -32,6 +38,9 @@
32 :ukkoclot/tg/reply-keyboard-markup 38 :ukkoclot/tg/reply-keyboard-markup
33 :ukkoclot/tg/reply-keyboard-remove 39 :ukkoclot/tg/reply-keyboard-remove
34 :ukkoclot/tg/reply-parameters 40 :ukkoclot/tg/reply-parameters
41 :ukkoclot/tg/send-animation
42 :ukkoclot/tg/send-message
43 :ukkoclot/tg/set-my-name
35 :ukkoclot/tg/suggested-post-parameters 44 :ukkoclot/tg/suggested-post-parameters
36 :ukkoclot/tg/suggested-post-price 45 :ukkoclot/tg/suggested-post-price
37 :ukkoclot/tg/update 46 :ukkoclot/tg/update
diff --git a/src/tg/answer-callback-query.lisp b/src/tg/answer-callback-query.lisp
new file mode 100644
index 0000000..badd8a4
--- /dev/null
+++ b/src/tg/answer-callback-query.lisp
@@ -0,0 +1,13 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/answer-callback-query
4 (:use :c2cl :ukkoclot/bot/method-macros)
5 (:export :answer-callback-query))
6(in-package :ukkoclot/tg/answer-callback-query)
7
8(define-tg-method (answer-callback-query boolean)
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))
diff --git a/src/tg/delete-message.lisp b/src/tg/delete-message.lisp
new file mode 100644
index 0000000..3e79de7
--- /dev/null
+++ b/src/tg/delete-message.lisp
@@ -0,0 +1,10 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/delete-message
4 (:use :c2cl :ukkoclot/bot/method-macros)
5 (:export :delete-message))
6(in-package :ukkoclot/tg/delete-message)
7
8(define-tg-method (delete-message boolean)
9 (chat-id (or integer string))
10 (message-id integer))
diff --git a/src/tg/edit-message-text.lisp b/src/tg/edit-message-text.lisp
new file mode 100644
index 0000000..a7db3a8
--- /dev/null
+++ b/src/tg/edit-message-text.lisp
@@ -0,0 +1,25 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/edit-message-text
4 (:use
5 :c2cl
6 :ukkoclot/tg/inline-keyboard-markup
7 :ukkoclot/tg/link-preview-options
8 :ukkoclot/tg/message
9 :ukkoclot/tg/message-entity
10 :ukkoclot/bot/method-macros
11 :ukkoclot/tg/parse-mode)
12 (:export :edit-message-text))
13(in-package :ukkoclot/tg/edit-message-text)
14
15;; TODO: Add a way to simply specify :message msg :)
16(define-tg-method (edit-message-text message)
17 (business-connection-id (or string null) nil)
18 (chat-id (or integer string null) nil)
19 (message-id (or integer null) nil)
20 (inline-message-id (or string null) nil)
21 (text string)
22 (parse-mode (or parse-mode null) nil)
23 (entities (or (array message-entity) null) nil)
24 (link-preview-options (or link-preview-options null) nil)
25 (reply-markup (or inline-keyboard-markup null) nil))
diff --git a/src/tg/get-me.lisp b/src/tg/get-me.lisp
new file mode 100644
index 0000000..ae00717
--- /dev/null
+++ b/src/tg/get-me.lisp
@@ -0,0 +1,15 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-me
4 (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/user)
5 (:import-from :ukkoclot/state :bot-id% :bot-username%)
6 (:export :get-me))
7(in-package :ukkoclot/tg/get-me)
8
9(define-tg-method (get-me% user :GET))
10
11(defun get-me (bot)
12 (let ((res (get-me% bot)))
13 (setf (bot-id% bot) (user-id res))
14 (setf (bot-username% bot) (user-username res))
15 res))
diff --git a/src/tg/get-my-name.lisp b/src/tg/get-my-name.lisp
new file mode 100644
index 0000000..59bb753
--- /dev/null
+++ b/src/tg/get-my-name.lisp
@@ -0,0 +1,9 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-my-name
4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/bot/method-macros)
5 (:export :get-my-name))
6(in-package :ukkoclot/tg/get-my-name)
7
8(define-tg-method (get-my-name bot-name :GET)
9 (language-code (or string null) nil))
diff --git a/src/tg/get-updates.lisp b/src/tg/get-updates.lisp
new file mode 100644
index 0000000..15f5e3f
--- /dev/null
+++ b/src/tg/get-updates.lisp
@@ -0,0 +1,12 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/get-updates
4 (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/update)
5 (:export :get-updates))
6(in-package :ukkoclot/tg/get-updates)
7
8(define-tg-method (get-updates (array update))
9 (offset (or integer null) nil)
10 (limit (or integer null) nil)
11 (timeout (or integer null) nil)
12 (allowed-updates (or string null) nil))
diff --git a/src/tg/send-animation.lisp b/src/tg/send-animation.lisp
new file mode 100644
index 0000000..e9558fa
--- /dev/null
+++ b/src/tg/send-animation.lisp
@@ -0,0 +1,40 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/send-animation
4 (:use
5 :c2cl
6 :ukkoclot/tg/force-reply
7 :ukkoclot/tg/inline-keyboard-markup
8 :ukkoclot/tg/message
9 :ukkoclot/tg/message-entity
10 :ukkoclot/bot/method-macros
11 :ukkoclot/tg/parse-mode
12 :ukkoclot/tg/reply-keyboard-markup
13 :ukkoclot/tg/reply-keyboard-remove
14 :ukkoclot/tg/reply-parameters
15 :ukkoclot/tg/suggested-post-parameters)
16 (:export :send-animation))
17(in-package :ukkoclot/tg/send-animation)
18
19(define-tg-method (send-animation message)
20 (business-connection-id (or string null) nil)
21 (chat-id (or integer string))
22 (message-thread-id (or integer null) nil)
23 (direct-messages-topic-id (or integer null) nil)
24 (animation (or pathname string))
25 (duration (or integer null) nil)
26 (width (or integer null) nil)
27 (height (or integer null) nil)
28 (thumbnail (or pathname string null) nil)
29 (caption (or string null) nil)
30 (parse-mode (or parse-mode null) nil)
31 (caption-entities (or (array message-entity) null) nil)
32 (show-caption-above-media boolean nil)
33 (has-spoiler boolean nil)
34 (disable-notification boolean nil)
35 (protect-content boolean nil)
36 (allow-paid-broadcast boolean nil)
37 (message-effect-id (or string null) nil)
38 (suggested-post-parameters (or suggested-post-parameters null) nil)
39 (reply-parameters (or reply-parameters null) nil)
40 (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil))
diff --git a/src/tg/send-message.lisp b/src/tg/send-message.lisp
new file mode 100644
index 0000000..d2e7248
--- /dev/null
+++ b/src/tg/send-message.lisp
@@ -0,0 +1,31 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/send-message
4 (:use
5 :c2cl
6 :ukkoclot/tg/force-reply
7 :ukkoclot/tg/inline-keyboard-markup
8 :ukkoclot/tg/link-preview-options
9 :ukkoclot/tg/message
10 :ukkoclot/tg/message-entity
11 :ukkoclot/bot/method-macros
12 :ukkoclot/tg/parse-mode
13 :ukkoclot/tg/reply-keyboard-markup
14 :ukkoclot/tg/reply-keyboard-remove
15 :ukkoclot/tg/reply-parameters)
16 (:export :send-message))
17(in-package :ukkoclot/tg/send-message)
18
19(define-tg-method (send-message message)
20 (business-connection-id (or string null) nil)
21 (chat-id (or integer string))
22 (message-thread-id (or integer null) nil)
23 (text string)
24 (parse-mode (or parse-mode null) nil)
25 (entities (or (array message-entity) null) nil)
26 (link-preview-options (or link-preview-options null) nil)
27 (disable-notification (or boolean null) nil)
28 (protect-content (or boolean null) nil)
29 (message-effect-id (or string null) nil)
30 (reply-parameters (or reply-parameters null) nil)
31 (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil))
diff --git a/src/tg/set-my-name.lisp b/src/tg/set-my-name.lisp
new file mode 100644
index 0000000..5638a92
--- /dev/null
+++ b/src/tg/set-my-name.lisp
@@ -0,0 +1,19 @@
1;; SPDX-License-Identifier: EUPL-1.2
2;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
3(defpackage :ukkoclot/tg/set-my-name
4 (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/tg/get-my-name :ukkoclot/bot/method-macros)
5 (:export :set-my-name))
6(in-package :ukkoclot/tg/set-my-name)
7
8(define-tg-method (set-my-name% boolean)
9 (name (or string null) nil)
10 (language-code (or string null) nil))
11
12(defun set-my-name (bot &key (name nil) (language-code nil))
13 (block nil
14 (when name
15 (let ((curr-name (get-my-name bot :language-code language-code)))
16 (when (string= name (bot-name-name curr-name))
17 (return))))
18 (unless (set-my-name% bot :name name :language-code language-code)
19 (error "Failed to set name"))))