diff options
| author | 2025-10-13 02:43:23 +0300 | |
|---|---|---|
| committer | 2025-10-13 02:43:23 +0300 | |
| commit | 5db1d491cecd9b610e9693d10b5015822429d261 (patch) | |
| tree | e1980c2b68d78779fb5244d7673111fc80cd7391 /src/main.lisp | |
| parent | Remove some commented-out code (diff) | |
| download | ukkoclot-5db1d491cecd9b610e9693d10b5015822429d261.tar.gz ukkoclot-5db1d491cecd9b610e9693d10b5015822429d261.tar.xz ukkoclot-5db1d491cecd9b610e9693d10b5015822429d261.zip | |
Added a SWANK server
Diffstat (limited to 'src/main.lisp')
| -rw-r--r-- | src/main.lisp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.lisp b/src/main.lisp index 862526b..a113ab0 100644 --- a/src/main.lisp +++ b/src/main.lisp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg) | 5 | (:use :c2cl :ukkoclot/bot :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) | ||
| 8 | (:import-from :ukkoclot/bot :make-bot :bot-power-on :fixup-value) | 9 | (:import-from :ukkoclot/bot :make-bot :bot-power-on :fixup-value) |
| 9 | (:import-from :ukkoclot/db :with-db) | 10 | (:import-from :ukkoclot/db :with-db) |
| 10 | (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) | 11 | (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) |
| @@ -21,16 +22,34 @@ | |||
| 21 | (error (err) (report-error bot ,evt err))) | 22 | (error (err) (report-error bot ,evt err))) |
| 22 | (progn ,@body))) | 23 | (progn ,@body))) |
| 23 | 24 | ||
| 25 | (defun start-swank (port) | ||
| 26 | (log:info "Starting a SWANK server on port ~A..." port) | ||
| 27 | (swank:create-server :port port :dont-close t) | ||
| 28 | (log:info "SWANK started. You can connect to it by forwarding ports via SSH: `ssh -L~A:127.0.0.1:~A username@server.com'" port port) | ||
| 29 | (log:info "And then afterwards M-x slime-connect giving localhost and ~A" port)) | ||
| 30 | |||
| 31 | (defun stop-swank (port) | ||
| 32 | (log:info "Stopping the SWANK server on port ~A..." port) | ||
| 33 | (swank:stop-server port) | ||
| 34 | (log:info "Done")) | ||
| 35 | |||
| 24 | (defun main () | 36 | (defun main () |
| 25 | (unwind-protect | 37 | (unwind-protect |
| 26 | (let ((config (config-load #P"config.default.lisp"))) | 38 | (let ((config (config-load #P"config.default.lisp"))) |
| 27 | (config-merge config #P"config.lisp") | 39 | (config-merge config #P"config.lisp") |
| 28 | (log:info "Starting up ~A" (config-bot-name config)) | 40 | (log:info "Starting up ~A" (config-bot-name config)) |
| 41 | (main-with-config config)) | ||
| 42 | (log:info "Quitting!"))) | ||
| 43 | |||
| 44 | (defun main-with-config (config) | ||
| 45 | (unwind-protect | ||
| 46 | (progn | ||
| 47 | (start-swank (config-swank-port config)) | ||
| 29 | (with-db (db (config-db-path config)) | 48 | (with-db (db (config-db-path config)) |
| 30 | (let ((bot (make-bot config db))) | 49 | (let ((bot (make-bot config db))) |
| 31 | ;; TODO: Catch fatal errors & report them | 50 | ;; TODO: Catch fatal errors & report them |
| 32 | (wrapped-main bot config)))) | 51 | (wrapped-main bot config)))) |
| 33 | (log:info "We're done!"))) | 52 | (stop-swank (config-swank-port config)))) |
| 34 | 53 | ||
| 35 | (defun wrapped-main (bot config) | 54 | (defun wrapped-main (bot config) |
| 36 | (when *in-prod* | 55 | (when *in-prod* |