From f8db5c3e3c4bb426e76e10993b09debdb84b0b57 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 13 Oct 2025 05:51:01 +0300 Subject: Move bot/impl to state --- src/bot.lisp | 6 ------ src/bot/advanced.lisp | 3 ++- src/bot/impl.lisp | 23 ----------------------- src/bot/method-macros.lisp | 2 +- src/bot/methods.lisp | 3 ++- src/inline-bots.lisp | 5 ++++- src/main.lisp | 4 ++-- src/state.lisp | 30 ++++++++++++++++++++++++++++++ src/transport.lisp | 2 +- 9 files changed, 42 insertions(+), 36 deletions(-) delete mode 100644 src/bot.lisp delete mode 100644 src/bot/impl.lisp create mode 100644 src/state.lisp (limited to 'src') diff --git a/src/bot.lisp b/src/bot.lisp deleted file mode 100644 index 78a6ad0..0000000 --- a/src/bot.lisp +++ /dev/null @@ -1,6 +0,0 @@ -;; SPDX-License-Identifier: EUPL-1.2 -;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs -(uiop:define-package :ukkoclot/bot - (:use) - ;; Maybe should somehow hide BOT-USERNAME% and BOT-ID% but whatever - (:use-reexport :ukkoclot/bot/advanced :ukkoclot/bot/impl :ukkoclot/bot/methods)) diff --git a/src/bot/advanced.lisp b/src/bot/advanced.lisp index 635bdb0..c18b574 100644 --- a/src/bot/advanced.lisp +++ b/src/bot/advanced.lisp @@ -1,7 +1,8 @@ ;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/bot/advanced - (:use :c2cl :ukkoclot/bot/impl :ukkoclot/bot/methods :ukkoclot/tg) + (:use :c2cl :ukkoclot/bot/methods :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/impl.lisp b/src/bot/impl.lisp deleted file mode 100644 index ea1aa03..0000000 --- a/src/bot/impl.lisp +++ /dev/null @@ -1,23 +0,0 @@ -;; SPDX-License-Identifier: EUPL-1.2 -;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs -(defpackage :ukkoclot/bot/impl - (:use :c2cl :iterate :ukkoclot/config) - (:export - :bot :bot-p :make-bot - - :bot-config :bot-db :bot-base-uri :bot-power-on :bot-username% :bot-id%)) -(in-package :ukkoclot/bot/impl) - -(defstruct (bot (:constructor make-bot%)) - (config (error "No value given for config") :read-only t) - (db (error "No value given for DB") :read-only t) - (base-uri (error "No value given for base-uri") :read-only t) - (power-on t :type boolean) - (username% nil :type (or string null)) - (id% nil :type (or integer null))) - -(defun make-bot (config db) - (let ((base-uri (concatenate 'string - "https://api.telegram.org/bot" - (config-bot-token config) "/"))) - (make-bot% :config config :db db :base-uri base-uri))) diff --git a/src/bot/method-macros.lisp b/src/bot/method-macros.lisp index b6f237f..0500de9 100644 --- a/src/bot/method-macros.lisp +++ b/src/bot/method-macros.lisp @@ -2,7 +2,7 @@ ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/bot/method-macros (:use :c2cl :iterate) - (:import-from :ukkoclot/bot/impl :bot) + (:import-from :ukkoclot/state :bot) (:import-from :ukkoclot/transport :do-call) (:export :define-tg-method)) (in-package :ukkoclot/bot/method-macros) diff --git a/src/bot/methods.lisp b/src/bot/methods.lisp index bddb9ff..2daea6f 100644 --- a/src/bot/methods.lisp +++ b/src/bot/methods.lisp @@ -1,7 +1,8 @@ ;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/bot/methods - (:use :c2cl :ukkoclot/bot/method-macros :ukkoclot/bot/impl :ukkoclot/tg) + (: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) diff --git a/src/inline-bots.lisp b/src/inline-bots.lisp index 08568d2..1d0d8ff 100644 --- a/src/inline-bots.lisp +++ b/src/inline-bots.lisp @@ -1,8 +1,11 @@ ;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/inline-bots - (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/tg) + (: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/state :bot-config :bot-db) (:local-nicknames (:db :ukkoclot/db)) (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot)) (in-package :ukkoclot/inline-bots) diff --git a/src/main.lisp b/src/main.lisp index d418b78..522fb1b 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -2,13 +2,13 @@ ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/main (:nicknames :ukkoclot) - (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) + (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg :ukkoclot/bot/methods :ukkoclot/bot/advanced) (:import-from :anaphora :acond :awhen :it) (:import-from :log) (:import-from :swank) - (:import-from :ukkoclot/bot :make-bot :bot-power-on) (:import-from :ukkoclot/db :with-db) (:import-from :ukkoclot/serializing :fixup-value) + (:import-from :ukkoclot/state :make-bot :bot-config :bot-power-on) (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) (:local-nicknames (:jzon :com.inuoe.jzon)) diff --git a/src/state.lisp b/src/state.lisp new file mode 100644 index 0000000..98e2048 --- /dev/null +++ b/src/state.lisp @@ -0,0 +1,30 @@ +;; SPDX-License-Identifier: EUPL-1.2 +;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs +(defpackage :ukkoclot/state + (:use :c2cl :ukkoclot/config) + (:export + #:bot + #:make-bot + #:bot-p + #:copy-bot + #:bot-config + #:bot-db + #:bot-base-uri + #:bot-power-on + #:bot-username% + #:bot-id%)) +(in-package :ukkoclot/state) + +(defstruct (bot (:constructor make-bot%)) + (config (error "No value given for config") :read-only t) + (db (error "No value given for DB") :read-only t) + (base-uri (error "No value given for base-uri") :read-only t) + (power-on t :type boolean) + (username% nil :type (or string null)) + (id% nil :type (or integer null))) + +(defun make-bot (config db) + (let ((base-uri (concatenate 'string + "https://api.telegram.org/bot" + (config-bot-token config) "/"))) + (make-bot% :config config :db db :base-uri base-uri))) diff --git a/src/transport.lisp b/src/transport.lisp index 0b5b138..39198dd 100644 --- a/src/transport.lisp +++ b/src/transport.lisp @@ -6,8 +6,8 @@ (:import-from :cl+ssl) (:import-from :dex) (:import-from :log) - (:import-from :ukkoclot/bot/impl :bot-base-uri) (:import-from :ukkoclot/serializing :fixup-args :parse-value) + (:import-from :ukkoclot/state :bot-base-uri) (:local-nicknames (:jzon :com.inuoe.jzon)) (:export :do-call)) -- cgit v1.2.3