From 8b8bd2b811ed4097a3aaf8785d233bd012d22ac0 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 13 Oct 2025 06:48:00 +0300 Subject: Move bot/adanced to tg/* --- src/bot/advanced.lisp | 55 ---------------------------------------------- src/inline-bots.lisp | 3 +-- src/main.lisp | 2 +- src/tg/delete-message.lisp | 15 +++++++++++-- src/tg/get-me.lisp | 22 ++++++++++++++----- src/tg/send-animation.lisp | 16 +++++++++++++- src/tg/send-message.lisp | 13 ++++++++++- 7 files changed, 59 insertions(+), 67 deletions(-) delete mode 100644 src/bot/advanced.lisp diff --git a/src/bot/advanced.lisp b/src/bot/advanced.lisp deleted file mode 100644 index 3763151..0000000 --- a/src/bot/advanced.lisp +++ /dev/null @@ -1,55 +0,0 @@ -;; SPDX-License-Identifier: EUPL-1.2 -;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs -(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))))) diff --git a/src/inline-bots.lisp b/src/inline-bots.lisp index 1c44fd4..caf210a 100644 --- a/src/inline-bots.lisp +++ b/src/inline-bots.lisp @@ -3,8 +3,7 @@ (defpackage :ukkoclot/inline-bots (:use :c2cl :ukkoclot/config :ukkoclot/tg) (:import-from :log) - (:import-from :ukkoclot/bot/advanced :try-delete-message) - (:import-from :ukkoclot/tg :send-message) + (:import-from :ukkoclot/tg :send-message :try-delete-message) (:import-from :ukkoclot/state :bot-config :bot-db) (:local-nicknames (:db :ukkoclot/db)) (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot)) diff --git a/src/main.lisp b/src/main.lisp index 1111100..68ba371 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -2,7 +2,7 @@ ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/main (:nicknames :ukkoclot) - (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg :ukkoclot/bot/advanced) + (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) (:import-from :anaphora :acond :awhen :it) (:import-from :log) (:import-from :swank) diff --git a/src/tg/delete-message.lisp b/src/tg/delete-message.lisp index 3e79de7..fd6f323 100644 --- a/src/tg/delete-message.lisp +++ b/src/tg/delete-message.lisp @@ -1,10 +1,21 @@ ;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/tg/delete-message - (:use :c2cl :ukkoclot/bot/method-macros) - (:export :delete-message)) + (:use :c2cl :ukkoclot/tg/message :ukkoclot/bot/method-macros :ukkoclot/tg/send-animation) + (:export :delete-message :try-delete-message)) (in-package :ukkoclot/tg/delete-message) (define-tg-method (delete-message boolean) (chat-id (or integer string)) (message-id integer)) + +(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))))) diff --git a/src/tg/get-me.lisp b/src/tg/get-me.lisp index ae00717..cfb1304 100644 --- a/src/tg/get-me.lisp +++ b/src/tg/get-me.lisp @@ -3,13 +3,25 @@ (defpackage :ukkoclot/tg/get-me (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/user) (:import-from :ukkoclot/state :bot-id% :bot-username%) - (:export :get-me)) + (:export :bot-id :bot-username :get-me)) (in-package :ukkoclot/tg/get-me) (define-tg-method (get-me% user :GET)) (defun get-me (bot) - (let ((res (get-me% bot))) - (setf (bot-id% bot) (user-id res)) - (setf (bot-username% bot) (user-username res)) - res)) + (let ((me (get-me bot))) + (setf (bot-id% bot) (user-id me)) + (setf (bot-username% bot) (user-username me)) + me)) + +(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)))) diff --git a/src/tg/send-animation.lisp b/src/tg/send-animation.lisp index e9558fa..97dd9f0 100644 --- a/src/tg/send-animation.lisp +++ b/src/tg/send-animation.lisp @@ -13,7 +13,7 @@ :ukkoclot/tg/reply-keyboard-remove :ukkoclot/tg/reply-parameters :ukkoclot/tg/suggested-post-parameters) - (:export :send-animation)) + (:export :reply-animation :send-animation)) (in-package :ukkoclot/tg/send-animation) (define-tg-method (send-animation message) @@ -38,3 +38,17 @@ (suggested-post-parameters (or suggested-post-parameters null) nil) (reply-parameters (or reply-parameters null) nil) (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) + +;; 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)))) diff --git a/src/tg/send-message.lisp b/src/tg/send-message.lisp index d2e7248..7cd91d9 100644 --- a/src/tg/send-message.lisp +++ b/src/tg/send-message.lisp @@ -13,7 +13,7 @@ :ukkoclot/tg/reply-keyboard-markup :ukkoclot/tg/reply-keyboard-remove :ukkoclot/tg/reply-parameters) - (:export :send-message)) + (:export :reply-message :send-message)) (in-package :ukkoclot/tg/send-message) (define-tg-method (send-message message) @@ -29,3 +29,14 @@ (message-effect-id (or string null) nil) (reply-parameters (or reply-parameters null) nil) (reply-markup (or inline-keyboard-markup reply-keyboard-markup reply-keyboard-remove force-reply null) nil)) + +(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)))) -- cgit v1.2.3