diff options
Diffstat (limited to 'src/tg')
| -rw-r--r-- | src/tg/delete-message.lisp | 9 | ||||
| -rw-r--r-- | src/tg/get-me.lisp | 30 | ||||
| -rw-r--r-- | src/tg/method-macros.lisp | 14 | ||||
| -rw-r--r-- | src/tg/send-animation.lisp | 7 | ||||
| -rw-r--r-- | src/tg/send-message.lisp | 7 | ||||
| -rw-r--r-- | src/tg/set-my-name.lisp | 10 |
6 files changed, 44 insertions, 33 deletions
diff --git a/src/tg/delete-message.lisp b/src/tg/delete-message.lisp index cc52371..2b332df 100644 --- a/src/tg/delete-message.lisp +++ b/src/tg/delete-message.lisp | |||
| @@ -1,6 +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/src/tg/delete-message | 3 | (defpackage :ukkoclot/src/tg/delete-message |
| 4 | (:documentation "deleteMessage Telegram method") | ||
| 4 | (:use :c2cl :ukkoclot/src/tg/message :ukkoclot/src/tg/method-macros :ukkoclot/src/tg/send-animation) | 5 | (:use :c2cl :ukkoclot/src/tg/message :ukkoclot/src/tg/method-macros :ukkoclot/src/tg/send-animation) |
| 5 | (:export :delete-message :try-delete-message)) | 6 | (:export :delete-message :try-delete-message)) |
| 6 | (in-package :ukkoclot/src/tg/delete-message) | 7 | (in-package :ukkoclot/src/tg/delete-message) |
| @@ -9,13 +10,13 @@ | |||
| 9 | (chat-id (or integer string)) | 10 | (chat-id (or integer string)) |
| 10 | (message-id integer)) | 11 | (message-id integer)) |
| 11 | 12 | ||
| 12 | (defun try-delete-message (bot msg) | 13 | (defun try-delete-message (msg) |
| 14 | "Attempt to delete the MSG, on failure reply with a GIF of the DO NOT cat." | ||
| 13 | (handler-case | 15 | (handler-case |
| 14 | (delete-message bot | 16 | (delete-message :chat-id (message-chat-id msg) |
| 15 | :chat-id (message-chat-id msg) | ||
| 16 | :message-id (message-id msg)) | 17 | :message-id (message-id msg)) |
| 17 | (error () | 18 | (error () |
| 18 | (handler-case | 19 | (handler-case |
| 19 | (reply-animation bot msg #P"blob/do-not.mp4" | 20 | (reply-animation msg #P"blob/do-not.mp4" |
| 20 | :allow-sending-without-reply nil) | 21 | :allow-sending-without-reply nil) |
| 21 | (error () nil))))) | 22 | (error () nil))))) |
diff --git a/src/tg/get-me.lisp b/src/tg/get-me.lisp index b7e8bc0..e7d41a1 100644 --- a/src/tg/get-me.lisp +++ b/src/tg/get-me.lisp | |||
| @@ -1,27 +1,31 @@ | |||
| 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/src/tg/get-me | 3 | (defpackage :ukkoclot/src/tg/get-me |
| 4 | (:documentation "getMe Telegram method") | ||
| 4 | (:use :c2cl :ukkoclot/src/tg/method-macros :ukkoclot/src/tg/user) | 5 | (:use :c2cl :ukkoclot/src/tg/method-macros :ukkoclot/src/tg/user) |
| 5 | (:import-from :ukkoclot/src/state :bot-id% :bot-username%) | 6 | (:import-from :state) |
| 6 | (:export :bot-id :bot-username :get-me)) | 7 | (:export :bot-id :bot-username :get-me)) |
| 7 | (in-package :ukkoclot/src/tg/get-me) | 8 | (in-package :ukkoclot/src/tg/get-me) |
| 8 | 9 | ||
| 9 | (define-tg-method (get-me% user :GET)) | 10 | (define-tg-method (get-me% user :GET)) |
| 10 | 11 | ||
| 11 | (defun get-me (bot) | 12 | (defun get-me () |
| 12 | (let ((me (get-me% bot))) | 13 | "getMe Telegram method" |
| 13 | (setf (bot-id% bot) (user-id me)) | 14 | (let ((me (get-me%))) |
| 14 | (setf (bot-username% bot) (user-username me)) | 15 | (setf (state:id%) (user-id me)) |
| 16 | (setf (state:username%) (user-username me)) | ||
| 15 | me)) | 17 | me)) |
| 16 | 18 | ||
| 17 | (defun bot-id (bot) | 19 | (defun bot-id () |
| 18 | (or (bot-id% bot) | 20 | "Get the bot's ID, this memoizes the result" |
| 21 | (or (state:id%) | ||
| 19 | (progn | 22 | (progn |
| 20 | (get-me bot) | 23 | (get-me) |
| 21 | (bot-id% bot)))) | 24 | (state:id%)))) |
| 22 | 25 | ||
| 23 | (defun bot-username (bot) | 26 | (defun bot-username () |
| 24 | (or (bot-username% bot) | 27 | "Get the bot's username, this memoizes the result" |
| 28 | (or (state:username%) | ||
| 25 | (progn | 29 | (progn |
| 26 | (get-me bot) | 30 | (get-me) |
| 27 | (bot-username% bot)))) | 31 | (state:username%)))) |
diff --git a/src/tg/method-macros.lisp b/src/tg/method-macros.lisp index 00adf95..56445e3 100644 --- a/src/tg/method-macros.lisp +++ b/src/tg/method-macros.lisp | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | (:import-from :alexandria :with-gensyms) | 6 | (:import-from :alexandria :with-gensyms) |
| 7 | (:import-from :com.dieggsy.f-string :enable-f-strings) | 7 | (:import-from :com.dieggsy.f-string :enable-f-strings) |
| 8 | (:import-from :serapeum :take) | 8 | (:import-from :serapeum :take) |
| 9 | (:import-from :state) | ||
| 9 | (:import-from :str) | 10 | (:import-from :str) |
| 10 | (:import-from :ukkoclot/src/state :bot) | ||
| 11 | (:import-from :ukkoclot/src/transport :do-call) | 11 | (:import-from :ukkoclot/src/transport :do-call) |
| 12 | (:export :define-tg-method)) | 12 | (:export :define-tg-method)) |
| 13 | (in-package :ukkoclot/src/tg/method-macros) | 13 | (in-package :ukkoclot/src/tg/method-macros) |
| @@ -53,9 +53,9 @@ | |||
| 53 | `(,(param-name param) ,(param-default param))) | 53 | `(,(param-name param) ,(param-default param))) |
| 54 | 54 | ||
| 55 | (defun emit-defun (name return-type params method) | 55 | (defun emit-defun (name return-type params method) |
| 56 | (with-gensyms (args bot) | 56 | (with-gensyms (args) |
| 57 | `(defun ,name (,bot &key ,@(iter (for param in params) ; lint:suppress lambda-list-invalid | 57 | `(defun ,name (&key ,@(iter (for param in params) ; lint:suppress lambda-list-invalid |
| 58 | (collect (emit-defun-arg param)))) | 58 | (collect (emit-defun-arg param)))) |
| 59 | (let (,args) | 59 | (let (,args) |
| 60 | ,@(iter (for param in (reverse params)) | 60 | ,@(iter (for param in (reverse params)) |
| 61 | (collect (if (param-skip-if-default param) | 61 | (collect (if (param-skip-if-default param) |
| @@ -63,11 +63,11 @@ | |||
| 63 | ,(param-default param)) | 63 | ,(param-default param)) |
| 64 | ,(emit-append-to-args param args)) | 64 | ,(emit-append-to-args param args)) |
| 65 | (emit-append-to-args param args)))) | 65 | (emit-append-to-args param args)))) |
| 66 | (do-call ,bot ,method ,(path-from-name name) ',return-type ,args))))) | 66 | (do-call ,method ,(path-from-name name) ',return-type ,args))))) |
| 67 | 67 | ||
| 68 | (defun emit-ftype (name return-type params) | 68 | (defun emit-ftype (name return-type params) |
| 69 | `(declaim (ftype (function (bot &key ,@(iter (for param in params) | 69 | `(declaim (ftype (function (&key ,@(iter (for param in params) |
| 70 | (collect (emit-arg-type param)))) | 70 | (collect (emit-arg-type param)))) |
| 71 | ,return-type) | 71 | ,return-type) |
| 72 | ,name)))) | 72 | ,name)))) |
| 73 | 73 | ||
diff --git a/src/tg/send-animation.lisp b/src/tg/send-animation.lisp index a0b2d57..560b331 100644 --- a/src/tg/send-animation.lisp +++ b/src/tg/send-animation.lisp | |||
| @@ -1,6 +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/src/tg/send-animation | 3 | (defpackage :ukkoclot/src/tg/send-animation |
| 4 | (:documentation "sendAnimation Telegram method") | ||
| 4 | (:use | 5 | (:use |
| 5 | :c2cl | 6 | :c2cl |
| 6 | :ukkoclot/src/tg/force-reply | 7 | :ukkoclot/src/tg/force-reply |
| @@ -40,9 +41,9 @@ | |||
| 40 | (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) | 41 | (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) |
| 41 | 42 | ||
| 42 | ;; TODO: Some kind of caching for files? | 43 | ;; TODO: Some kind of caching for files? |
| 43 | (defun reply-animation (bot msg animation &key allow-sending-without-reply text parse-mode caption-above) | 44 | (defun reply-animation (msg animation &key allow-sending-without-reply text parse-mode caption-above) |
| 44 | (send-animation bot | 45 | "Shortcut to reply to a given MSG with an animation." |
| 45 | :chat-id (message-chat-id msg) | 46 | (send-animation :chat-id (message-chat-id msg) |
| 46 | :animation animation | 47 | :animation animation |
| 47 | :caption text | 48 | :caption text |
| 48 | :parse-mode parse-mode | 49 | :parse-mode parse-mode |
diff --git a/src/tg/send-message.lisp b/src/tg/send-message.lisp index 9edc50d..befecbe 100644 --- a/src/tg/send-message.lisp +++ b/src/tg/send-message.lisp | |||
| @@ -1,6 +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/src/tg/send-message | 3 | (defpackage :ukkoclot/src/tg/send-message |
| 4 | (:documentation "sendMessage Telegram method") | ||
| 4 | (:use | 5 | (:use |
| 5 | :c2cl | 6 | :c2cl |
| 6 | :ukkoclot/src/tg/force-reply | 7 | :ukkoclot/src/tg/force-reply |
| @@ -30,9 +31,9 @@ | |||
| 30 | (reply-parameters (or reply-parameters null) nil) | 31 | (reply-parameters (or reply-parameters null) nil) |
| 31 | (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) | 32 | (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) |
| 32 | 33 | ||
| 33 | (defun reply-message (bot msg text &key parse-mode allow-sending-without-reply) | 34 | (defun reply-message (msg text &key parse-mode allow-sending-without-reply) |
| 34 | (send-message bot | 35 | "Shortcut to reply to a given MSG." |
| 35 | :chat-id (message-chat-id msg) | 36 | (send-message :chat-id (message-chat-id msg) |
| 36 | :text text | 37 | :text text |
| 37 | :parse-mode parse-mode | 38 | :parse-mode parse-mode |
| 38 | :reply-parameters | 39 | :reply-parameters |
diff --git a/src/tg/set-my-name.lisp b/src/tg/set-my-name.lisp index 67c698d..2b3869a 100644 --- a/src/tg/set-my-name.lisp +++ b/src/tg/set-my-name.lisp | |||
| @@ -1,6 +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/src/tg/set-my-name | 3 | (defpackage :ukkoclot/src/tg/set-my-name |
| 4 | (:documentation "setMyName Telegram method.") | ||
| 4 | (:use :c2cl :ukkoclot/src/tg/bot-name :ukkoclot/src/tg/get-my-name :ukkoclot/src/tg/method-macros) | 5 | (:use :c2cl :ukkoclot/src/tg/bot-name :ukkoclot/src/tg/get-my-name :ukkoclot/src/tg/method-macros) |
| 5 | (:export :set-my-name)) | 6 | (:export :set-my-name)) |
| 6 | (in-package :ukkoclot/src/tg/set-my-name) | 7 | (in-package :ukkoclot/src/tg/set-my-name) |
| @@ -9,11 +10,14 @@ | |||
| 9 | (name (or string null) nil) | 10 | (name (or string null) nil) |
| 10 | (language-code (or string null) nil)) | 11 | (language-code (or string null) nil)) |
| 11 | 12 | ||
| 12 | (defun set-my-name (bot &key (name nil) (language-code nil)) | 13 | (defun set-my-name (&key (name nil) (language-code nil)) |
| 14 | "setMyName Telegram method. | ||
| 15 | |||
| 16 | We also first check if the name is already set because setMyName has a very heavy rate limiting impact." | ||
| 13 | (block nil | 17 | (block nil |
| 14 | (when name | 18 | (when name |
| 15 | (let ((curr-name (get-my-name bot :language-code language-code))) | 19 | (let ((curr-name (get-my-name :language-code language-code))) |
| 16 | (when (string= name (bot-name-name curr-name)) | 20 | (when (string= name (bot-name-name curr-name)) |
| 17 | (return)))) | 21 | (return)))) |
| 18 | (unless (set-my-name% bot :name name :language-code language-code) | 22 | (unless (set-my-name% :name name :language-code language-code) |
| 19 | (error "Failed to set name")))) | 23 | (error "Failed to set name")))) |