diff options
| author | 2025-10-18 05:36:44 +0300 | |
|---|---|---|
| committer | 2025-10-18 05:36:44 +0300 | |
| commit | 6b216e2b7c4b8f4a54551ab3f01c2d2695a99d5b (patch) | |
| tree | 03f2757896686afd058303b9210e792fce856497 | |
| parent | Manage dependencies with ocicl :) (diff) | |
| download | ukkoclot-6b216e2b7c4b8f4a54551ab3f01c2d2695a99d5b.tar.gz ukkoclot-6b216e2b7c4b8f4a54551ab3f01c2d2695a99d5b.tar.xz ukkoclot-6b216e2b7c4b8f4a54551ab3f01c2d2695a99d5b.zip | |
Revert "Added a SWANK server"
This reverts commit 5db1d491cecd9b610e9693d10b5015822429d261.
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | config.default.lisp | 3 | ||||
| -rw-r--r-- | src/config.lisp | 10 | ||||
| -rw-r--r-- | src/main.lisp | 17 |
4 files changed, 9 insertions, 23 deletions
| @@ -7,8 +7,6 @@ When running in a debuggy environment, consider | |||
| 7 | (setf ukkoclot::*in-prod* nil) | 7 | (setf ukkoclot::*in-prod* nil) |
| 8 | ``` | 8 | ``` |
| 9 | 9 | ||
| 10 | When connecting via remote SWANK, you might want to run `(log:config :sane2)`. | ||
| 11 | |||
| 12 | # Licensing | 10 | # Licensing |
| 13 | 11 | ||
| 14 | European Union Public Licence, version 1.2. | 12 | European Union Public Licence, version 1.2. |
diff --git a/config.default.lisp b/config.default.lisp index 4162c9a..0f1dbb7 100644 --- a/config.default.lisp +++ b/config.default.lisp | |||
| @@ -4,5 +4,4 @@ | |||
| 4 | :bot-token "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi" | 4 | :bot-token "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi" |
| 5 | :db-path "./data.db" | 5 | :db-path "./data.db" |
| 6 | :dev-group -1001234567890 | 6 | :dev-group -1001234567890 |
| 7 | :owner 12345678 | 7 | :owner 12345678) |
| 8 | :swank-port 4006) | ||
diff --git a/src/config.lisp b/src/config.lisp index 1bac762..55575bb 100644 --- a/src/config.lisp +++ b/src/config.lisp | |||
| @@ -2,13 +2,16 @@ | |||
| 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/config | 3 | (defpackage :ukkoclot/config |
| 4 | (:use :c2cl :ukkoclot/hash-tables) | 4 | (:use :c2cl :ukkoclot/hash-tables) |
| 5 | (:documentation | ||
| 6 | "Stuff for loading the configuration of the bot") | ||
| 5 | (:export | 7 | (:export |
| 6 | :config-load :config-merge | 8 | :config-load :config-merge |
| 7 | :config-p | 9 | :config-p |
| 8 | :config-bot-name :config-bot-token :config-db-path :config-dev-group :config-owner :config-swank-port)) | 10 | :config-bot-name :config-bot-token :config-db-path :config-dev-group :config-owner)) |
| 9 | (in-package :ukkoclot/config) | 11 | (in-package :ukkoclot/config) |
| 10 | 12 | ||
| 11 | (defmacro defconfig (&rest slots-and-types) | 13 | (defmacro defconfig (&rest slots-and-types) |
| 14 | "Macro to make the config struct creation easier." | ||
| 12 | `(defstruct config | 15 | `(defstruct config |
| 13 | ,@(loop for (name type) on slots-and-types by #'cddr | 16 | ,@(loop for (name type) on slots-and-types by #'cddr |
| 14 | collect `(,(intern (symbol-name name)) (error "No value given for ~A" ,name) :type ,type :read-only t)))) | 17 | collect `(,(intern (symbol-name name)) (error "No value given for ~A" ,name) :type ,type :read-only t)))) |
| @@ -18,12 +21,13 @@ | |||
| 18 | :bot-token string | 21 | :bot-token string |
| 19 | :db-path string | 22 | :db-path string |
| 20 | :dev-group integer | 23 | :dev-group integer |
| 21 | :owner integer | 24 | :owner integer) |
| 22 | :swank-port (integer 1 65536)) | ||
| 23 | 25 | ||
| 24 | (defun config-load (filename) | 26 | (defun config-load (filename) |
| 27 | "Load the config from the given `filename'. All entries must be specified." | ||
| 25 | (apply #'make-config (with-open-file (f filename) (read f)))) | 28 | (apply #'make-config (with-open-file (f filename) (read f)))) |
| 26 | 29 | ||
| 27 | (defun config-merge (config filename) | 30 | (defun config-merge (config filename) |
| 31 | "Merge the current config with new entries from `filename'." | ||
| 28 | (loop for (name value) on (with-open-file (f filename) (read f)) by #'cddr do | 32 | (loop for (name value) on (with-open-file (f filename) (read f)) by #'cddr do |
| 29 | (setf (slot-value config (intern (symbol-name name) :ukkoclot/config)) value))) | 33 | (setf (slot-value config (intern (symbol-name name) :ukkoclot/config)) value))) |
diff --git a/src/main.lisp b/src/main.lisp index 712b25d..f9720c9 100644 --- a/src/main.lisp +++ b/src/main.lisp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) | 5 | (:use :c2cl :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) |
| 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) | ||
| 9 | (:import-from :ukkoclot/db :with-db) | 8 | (:import-from :ukkoclot/db :with-db) |
| 10 | (:import-from :ukkoclot/serializing :fixup-value) | 9 | (:import-from :ukkoclot/serializing :fixup-value) |
| 11 | (:import-from :ukkoclot/state :make-bot :bot-config :bot-power-on) | 10 | (:import-from :ukkoclot/state :make-bot :bot-config :bot-power-on) |
| @@ -24,19 +23,6 @@ | |||
| 24 | (error (err) (report-error bot ,evt err))) | 23 | (error (err) (report-error bot ,evt err))) |
| 25 | (progn ,@body))) | 24 | (progn ,@body))) |
| 26 | 25 | ||
| 27 | (defun start-swank (port) | ||
| 28 | (log:info "Starting a SWANK server on port ~A..." port) | ||
| 29 | (swank:create-server :port port :dont-close t) | ||
| 30 | (log:info | ||
| 31 | "SWANK started. You can connect to it by forwarding ports via SSH: `ssh -L~A:127.0.0.1:~A username@server.com'" | ||
| 32 | port port) | ||
| 33 | (log:info "And then afterwards M-x slime-connect giving localhost and ~A" port)) | ||
| 34 | |||
| 35 | (defun stop-swank (port) | ||
| 36 | (log:info "Stopping the SWANK server on port ~A..." port) | ||
| 37 | (swank:stop-server port) | ||
| 38 | (log:info "Done")) | ||
| 39 | |||
| 40 | (defun main () | 26 | (defun main () |
| 41 | (log:config :debug) | 27 | (log:config :debug) |
| 42 | (unwind-protect | 28 | (unwind-protect |
| @@ -50,12 +36,11 @@ | |||
| 50 | (defun main-with-config (config) | 36 | (defun main-with-config (config) |
| 51 | (unwind-protect | 37 | (unwind-protect |
| 52 | (progn | 38 | (progn |
| 53 | (start-swank (config-swank-port config)) | ||
| 54 | (with-db (db (config-db-path config)) | 39 | (with-db (db (config-db-path config)) |
| 55 | (let ((bot (make-bot config db))) | 40 | (let ((bot (make-bot config db))) |
| 56 | ;; TODO: Catch fatal errors & report them | 41 | ;; TODO: Catch fatal errors & report them |
| 57 | (wrapped-main bot config)))) | 42 | (wrapped-main bot config)))) |
| 58 | (stop-swank (config-swank-port config)))) | 43 | (log:info "We're done!"))) |
| 59 | 44 | ||
| 60 | (defun wrapped-main (bot config) | 45 | (defun wrapped-main (bot config) |
| 61 | (when *in-prod* | 46 | (when *in-prod* |