diff options
Diffstat (limited to 'src/main.lisp')
| -rw-r--r-- | src/main.lisp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main.lisp b/src/main.lisp index f31cd7c..f90bfb3 100644 --- a/src/main.lisp +++ b/src/main.lisp | |||
| @@ -2,8 +2,9 @@ | |||
| 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/main | 3 | (defpackage :ukkoclot/main |
| 4 | (:nicknames :ukkoclot) | 4 | (:nicknames :ukkoclot) |
| 5 | (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/log :ukkoclot/tg-types) | 5 | (:use :c2cl :ukkoclot/bot :ukkoclot/config :ukkoclot/inline-bots :ukkoclot/tg-types) |
| 6 | (:import-from :anaphora :acond :awhen :it) | 6 | (:import-from :anaphora :acond :awhen :it) |
| 7 | (:import-from :log) | ||
| 7 | (:import-from :ukkoclot/bot :make-bot :bot-power-on :fixup-value) | 8 | (:import-from :ukkoclot/bot :make-bot :bot-power-on :fixup-value) |
| 8 | (:import-from :ukkoclot/db :with-db) | 9 | (:import-from :ukkoclot/db :with-db) |
| 9 | (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) | 10 | (:import-from :ukkoclot/strings :escape-xml :is-tg-whitespace-str :starts-with :starts-with-ignore-case) |
| @@ -24,12 +25,12 @@ | |||
| 24 | (unwind-protect | 25 | (unwind-protect |
| 25 | (let ((config (config-load #P"config.default.lisp"))) | 26 | (let ((config (config-load #P"config.default.lisp"))) |
| 26 | (config-merge config #P"config.lisp") | 27 | (config-merge config #P"config.lisp") |
| 27 | (log-info "Starting up ~A" (config-bot-name config)) | 28 | (log:info "Starting up ~A" (config-bot-name config)) |
| 28 | (with-db (db (config-db-path config)) | 29 | (with-db (db (config-db-path config)) |
| 29 | (let ((bot (make-bot config db))) | 30 | (let ((bot (make-bot config db))) |
| 30 | ;; TODO: Catch fatal errors & report them | 31 | ;; TODO: Catch fatal errors & report them |
| 31 | (wrapped-main bot config)))) | 32 | (wrapped-main bot config)))) |
| 32 | (log-info "We're done!"))) | 33 | (log:info "We're done!"))) |
| 33 | 34 | ||
| 34 | (defun wrapped-main (bot config) | 35 | (defun wrapped-main (bot config) |
| 35 | (when *in-prod* | 36 | (when *in-prod* |
| @@ -81,7 +82,7 @@ | |||
| 81 | :callback-query-id (callback-query-id cb) | 82 | :callback-query-id (callback-query-id cb) |
| 82 | :text "OK")) | 83 | :text "OK")) |
| 83 | (t | 84 | (t |
| 84 | (log-info "Unrecognised callback query data: ~A" data) | 85 | (log:info "Unrecognised callback query data: ~A" data) |
| 85 | (answer-callback-query bot | 86 | (answer-callback-query bot |
| 86 | :callback-query-id (callback-query-id cb) | 87 | :callback-query-id (callback-query-id cb) |
| 87 | :text "Unallowed callback query, don't press the button again" | 88 | :text "Unallowed callback query, don't press the button again" |
| @@ -215,7 +216,7 @@ | |||
| 215 | 216 | ||
| 216 | (defun on-text-command (bot msg text cmd) | 217 | (defun on-text-command (bot msg text cmd) |
| 217 | (let ((simple-cmd (simplify-cmd bot cmd))) | 218 | (let ((simple-cmd (simplify-cmd bot cmd))) |
| 218 | (log-debug "text-command: ~A AKA ~A" cmd simple-cmd) | 219 | (log:debug "text-command: ~A AKA ~A" cmd simple-cmd) |
| 219 | ;; TODO: Replace this cond with a nicer dispatch. Something like string-case? | 220 | ;; TODO: Replace this cond with a nicer dispatch. Something like string-case? |
| 220 | (acond | 221 | (acond |
| 221 | ((equal simple-cmd "chatid") | 222 | ((equal simple-cmd "chatid") |
| @@ -246,7 +247,7 @@ Send time: ...")) | |||
| 246 | ))) | 247 | ))) |
| 247 | 248 | ||
| 248 | (defun report-error (bot evt err) | 249 | (defun report-error (bot evt err) |
| 249 | (log-error "While handling ~A: ~A" evt err) | 250 | (log:error "While handling ~A: ~A" evt err) |
| 250 | (let ((msg (format nil "<code>~A</code> while handling ~&<pre>~A</pre>" | 251 | (let ((msg (format nil "<code>~A</code> while handling ~&<pre>~A</pre>" |
| 251 | (escape-xml (format nil "~A" err)) | 252 | (escape-xml (format nil "~A" err)) |
| 252 | (escape-xml (format nil "~A" evt))))) | 253 | (escape-xml (format nil "~A" evt))))) |