From 9e424b351da370630924e32d0a84eba6fdb8c05e Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 13 Oct 2025 06:32:57 +0300 Subject: Move bot/methods to tg/* --- src/bot/advanced.lisp | 2 +- src/bot/methods.lisp | 97 --------------------------------------- src/inline-bots.lisp | 2 +- src/main.lisp | 2 +- src/tg.lisp | 9 ++++ src/tg/answer-callback-query.lisp | 13 ++++++ src/tg/delete-message.lisp | 10 ++++ src/tg/edit-message-text.lisp | 25 ++++++++++ src/tg/get-me.lisp | 15 ++++++ src/tg/get-my-name.lisp | 9 ++++ src/tg/get-updates.lisp | 12 +++++ src/tg/send-animation.lisp | 40 ++++++++++++++++ src/tg/send-message.lisp | 31 +++++++++++++ src/tg/set-my-name.lisp | 19 ++++++++ 14 files changed, 186 insertions(+), 100 deletions(-) delete mode 100644 src/bot/methods.lisp create mode 100644 src/tg/answer-callback-query.lisp create mode 100644 src/tg/delete-message.lisp create mode 100644 src/tg/edit-message-text.lisp create mode 100644 src/tg/get-me.lisp create mode 100644 src/tg/get-my-name.lisp create mode 100644 src/tg/get-updates.lisp create mode 100644 src/tg/send-animation.lisp create mode 100644 src/tg/send-message.lisp create mode 100644 src/tg/set-my-name.lisp (limited to 'src') 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 @@ ;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/bot/advanced - (:use :c2cl :ukkoclot/bot/methods :ukkoclot/tg) + (: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) 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 @@ -;; SPDX-License-Identifier: EUPL-1.2 -;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs -(defpackage :ukkoclot/bot/methods - (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg) - (:import-from :ukkoclot/state :bot-id% :bot-username%) - (:export :answer-callback-query :delete-message :send-animation :edit-message-text :get-me :get-updates :send-message :set-my-name)) -(in-package :ukkoclot/bot/methods) - -(define-tg-method (answer-callback-query boolean) - (callback-query-id string) - (text (or string null) nil) - (show-alert boolean nil) - (url (or string null) nil) - (cache-time (or integer null) nil)) - -(define-tg-method (delete-message boolean) - (chat-id (or integer string)) - (message-id integer)) - -;; TODO: Add a way to simply specify :message msg :) -(define-tg-method (edit-message-text message) - (business-connection-id (or string null) nil) - (chat-id (or integer string null) nil) - (message-id (or integer null) nil) - (inline-message-id (or string null) nil) - (text string) - (parse-mode (or parse-mode null) nil) - (entities (or (array message-entity) null) nil) - (link-preview-options (or link-preview-options null) nil) - (reply-markup (or inline-keyboard-markup null) nil)) - -(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)) - -(define-tg-method (get-my-name bot-name :GET) - (language-code (or string null) nil)) - -(define-tg-method (get-updates (array update)) - (offset (or integer null) nil) - (limit (or integer null) nil) - (timeout (or integer null) nil) - (allowed-updates (or string null) nil)) - -(define-tg-method (send-animation message) - (business-connection-id (or string null) nil) - (chat-id (or integer string)) - (message-thread-id (or integer null) nil) - (direct-messages-topic-id (or integer null) nil) - (animation (or pathname string)) - (duration (or integer null) nil) - (width (or integer null) nil) - (height (or integer null) nil) - (thumbnail (or pathname string null) nil) - (caption (or string null) nil) - (parse-mode (or parse-mode null) nil) - (caption-entities (or (array message-entity) null) nil) - (show-caption-above-media boolean nil) - (has-spoiler boolean nil) - (disable-notification boolean nil) - (protect-content boolean nil) - (allow-paid-broadcast boolean nil) - (message-effect-id (or string null) nil) - (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)) - -(define-tg-method (send-message message) - (business-connection-id (or string null) nil) - (chat-id (or integer string)) - (message-thread-id (or integer null) nil) - (text string) - (parse-mode (or parse-mode null) nil) - (entities (or (array message-entity) null) nil) - (link-preview-options (or link-preview-options null) nil) - (disable-notification (or boolean null) nil) - (protect-content (or boolean null) nil) - (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)) - -(define-tg-method (set-my-name% boolean) - (name (or string null) nil) - (language-code (or string null) nil)) - -(defun set-my-name (bot &key (name nil) (language-code nil)) - (block nil - (when name - (let ((curr-name (get-my-name bot :language-code language-code))) - (when (string= name (bot-name-name curr-name)) - (return)))) - (unless (set-my-name% bot :name name :language-code language-code) - (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 @@ (:use :c2cl :ukkoclot/config :ukkoclot/tg) (:import-from :log) (:import-from :ukkoclot/bot/advanced :try-delete-message) - (:import-from :ukkoclot/bot/methods :send-message) + (:import-from :ukkoclot/tg :send-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 522fb1b..1111100 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/methods :ukkoclot/bot/advanced) + (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg :ukkoclot/bot/advanced) (:import-from :anaphora :acond :awhen :it) (:import-from :log) (: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 @@ (:use) (:use-reexport :ukkoclot/tg/animation + :ukkoclot/tg/answer-callback-query :ukkoclot/tg/bot-name :ukkoclot/tg/business-bot-rights :ukkoclot/tg/business-connection @@ -11,7 +12,12 @@ :ukkoclot/tg/chat :ukkoclot/tg/chat-type :ukkoclot/tg/chat-administrator-rights + :ukkoclot/tg/delete-message + :ukkoclot/tg/edit-message-text :ukkoclot/tg/force-reply + :ukkoclot/tg/get-me + :ukkoclot/tg/get-my-name + :ukkoclot/tg/get-updates :ukkoclot/tg/inline-keyboard-button :ukkoclot/tg/inline-keyboard-markup :ukkoclot/tg/keyboard-button @@ -32,6 +38,9 @@ :ukkoclot/tg/reply-keyboard-markup :ukkoclot/tg/reply-keyboard-remove :ukkoclot/tg/reply-parameters + :ukkoclot/tg/send-animation + :ukkoclot/tg/send-message + :ukkoclot/tg/set-my-name :ukkoclot/tg/suggested-post-parameters :ukkoclot/tg/suggested-post-price :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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/answer-callback-query + (:use :c2cl :ukkoclot/bot/method-macros) + (:export :answer-callback-query)) +(in-package :ukkoclot/tg/answer-callback-query) + +(define-tg-method (answer-callback-query boolean) + (callback-query-id string) + (text (or string null) nil) + (show-alert boolean nil) + (url (or string null) nil) + (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 @@ +;; 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)) +(in-package :ukkoclot/tg/delete-message) + +(define-tg-method (delete-message boolean) + (chat-id (or integer string)) + (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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/edit-message-text + (:use + :c2cl + :ukkoclot/tg/inline-keyboard-markup + :ukkoclot/tg/link-preview-options + :ukkoclot/tg/message + :ukkoclot/tg/message-entity + :ukkoclot/bot/method-macros + :ukkoclot/tg/parse-mode) + (:export :edit-message-text)) +(in-package :ukkoclot/tg/edit-message-text) + +;; TODO: Add a way to simply specify :message msg :) +(define-tg-method (edit-message-text message) + (business-connection-id (or string null) nil) + (chat-id (or integer string null) nil) + (message-id (or integer null) nil) + (inline-message-id (or string null) nil) + (text string) + (parse-mode (or parse-mode null) nil) + (entities (or (array message-entity) null) nil) + (link-preview-options (or link-preview-options null) nil) + (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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(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)) +(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)) 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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/get-my-name + (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/bot/method-macros) + (:export :get-my-name)) +(in-package :ukkoclot/tg/get-my-name) + +(define-tg-method (get-my-name bot-name :GET) + (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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/get-updates + (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/tg/update) + (:export :get-updates)) +(in-package :ukkoclot/tg/get-updates) + +(define-tg-method (get-updates (array update)) + (offset (or integer null) nil) + (limit (or integer null) nil) + (timeout (or integer null) nil) + (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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/send-animation + (:use + :c2cl + :ukkoclot/tg/force-reply + :ukkoclot/tg/inline-keyboard-markup + :ukkoclot/tg/message + :ukkoclot/tg/message-entity + :ukkoclot/bot/method-macros + :ukkoclot/tg/parse-mode + :ukkoclot/tg/reply-keyboard-markup + :ukkoclot/tg/reply-keyboard-remove + :ukkoclot/tg/reply-parameters + :ukkoclot/tg/suggested-post-parameters) + (:export :send-animation)) +(in-package :ukkoclot/tg/send-animation) + +(define-tg-method (send-animation message) + (business-connection-id (or string null) nil) + (chat-id (or integer string)) + (message-thread-id (or integer null) nil) + (direct-messages-topic-id (or integer null) nil) + (animation (or pathname string)) + (duration (or integer null) nil) + (width (or integer null) nil) + (height (or integer null) nil) + (thumbnail (or pathname string null) nil) + (caption (or string null) nil) + (parse-mode (or parse-mode null) nil) + (caption-entities (or (array message-entity) null) nil) + (show-caption-above-media boolean nil) + (has-spoiler boolean nil) + (disable-notification boolean nil) + (protect-content boolean nil) + (allow-paid-broadcast boolean nil) + (message-effect-id (or string null) nil) + (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)) 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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/send-message + (:use + :c2cl + :ukkoclot/tg/force-reply + :ukkoclot/tg/inline-keyboard-markup + :ukkoclot/tg/link-preview-options + :ukkoclot/tg/message + :ukkoclot/tg/message-entity + :ukkoclot/bot/method-macros + :ukkoclot/tg/parse-mode + :ukkoclot/tg/reply-keyboard-markup + :ukkoclot/tg/reply-keyboard-remove + :ukkoclot/tg/reply-parameters) + (:export :send-message)) +(in-package :ukkoclot/tg/send-message) + +(define-tg-method (send-message message) + (business-connection-id (or string null) nil) + (chat-id (or integer string)) + (message-thread-id (or integer null) nil) + (text string) + (parse-mode (or parse-mode null) nil) + (entities (or (array message-entity) null) nil) + (link-preview-options (or link-preview-options null) nil) + (disable-notification (or boolean null) nil) + (protect-content (or boolean null) nil) + (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)) 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 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/tg/set-my-name + (:use :c2cl :ukkoclot/tg/bot-name :ukkoclot/tg/get-my-name :ukkoclot/bot/method-macros) + (:export :set-my-name)) +(in-package :ukkoclot/tg/set-my-name) + +(define-tg-method (set-my-name% boolean) + (name (or string null) nil) + (language-code (or string null) nil)) + +(defun set-my-name (bot &key (name nil) (language-code nil)) + (block nil + (when name + (let ((curr-name (get-my-name bot :language-code language-code))) + (when (string= name (bot-name-name curr-name)) + (return)))) + (unless (set-my-name% bot :name name :language-code language-code) + (error "Failed to set name")))) -- cgit v1.2.3