diff options
| author | 2025-10-23 10:17:00 +0300 | |
|---|---|---|
| committer | 2025-10-23 10:32:36 +0300 | |
| commit | fec434a4e2d0ff65510581e461d87a945d25759a (patch) | |
| tree | 676891233e6121f8801f4751d3e2d1ca7ad4e09c /src/config.lisp | |
| parent | Use alexandria's make-keyword & symbolicate (diff) | |
| download | ukkoclot-fec434a4e2d0ff65510581e461d87a945d25759a.tar.gz ukkoclot-fec434a4e2d0ff65510581e461d87a945d25759a.tar.xz ukkoclot-fec434a4e2d0ff65510581e461d87a945d25759a.zip | |
Use serapeum's -> & defsubst
Diffstat (limited to 'src/config.lisp')
| -rw-r--r-- | src/config.lisp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/config.lisp b/src/config.lisp index 85c9662..7117de3 100644 --- a/src/config.lisp +++ b/src/config.lisp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | (:nicknames :conf) | 5 | (:nicknames :conf) |
| 6 | (:use :c2cl :iterate :ukkoclot/src/rw-lock) | 6 | (:use :c2cl :iterate :ukkoclot/src/rw-lock) |
| 7 | (:import-from :alexandria :make-keyword) | 7 | (:import-from :alexandria :make-keyword) |
| 8 | (:import-from :serapeum :->) | ||
| 8 | (:export | 9 | (:export |
| 9 | #:*config* | 10 | #:*config* |
| 10 | #:config | 11 | #:config |
| @@ -31,36 +32,42 @@ | |||
| 31 | (defvar *config* (make-config) | 32 | (defvar *config* (make-config) |
| 32 | "Bot's configuration") | 33 | "Bot's configuration") |
| 33 | 34 | ||
| 35 | (-> bot-name (&optional config) string) | ||
| 34 | (defun bot-name (&optional (config *config*)) | 36 | (defun bot-name (&optional (config *config*)) |
| 35 | "Get the desired name for the bot" | 37 | "Get the desired name for the bot" |
| 36 | (with-slots (lock bot-name) config | 38 | (with-slots (lock bot-name) config |
| 37 | (with-read-lock (lock) | 39 | (with-read-lock (lock) |
| 38 | bot-name))) | 40 | bot-name))) |
| 39 | 41 | ||
| 42 | (-> bot-token (&optional config) string) | ||
| 40 | (defun bot-token (&optional (config *config*)) | 43 | (defun bot-token (&optional (config *config*)) |
| 41 | "Get the API token for the bot" | 44 | "Get the API token for the bot" |
| 42 | (with-slots (lock bot-token) config | 45 | (with-slots (lock bot-token) config |
| 43 | (with-read-lock (lock) | 46 | (with-read-lock (lock) |
| 44 | bot-token))) | 47 | bot-token))) |
| 45 | 48 | ||
| 49 | (-> db-path (&optional config) pathname) | ||
| 46 | (defun db-path (&optional (config *config*)) | 50 | (defun db-path (&optional (config *config*)) |
| 47 | "Get the path to the bot's database" | 51 | "Get the path to the bot's database" |
| 48 | (with-slots (lock db-path) config | 52 | (with-slots (lock db-path) config |
| 49 | (with-read-lock (lock) | 53 | (with-read-lock (lock) |
| 50 | db-path))) | 54 | (pathname db-path)))) |
| 51 | 55 | ||
| 56 | (-> dev-group (&optional config) integer) | ||
| 52 | (defun dev-group (&optional (config *config*)) | 57 | (defun dev-group (&optional (config *config*)) |
| 53 | "Get the ID of the dev/testing group" | 58 | "Get the ID of the dev/testing group" |
| 54 | (with-slots (lock dev-group) config | 59 | (with-slots (lock dev-group) config |
| 55 | (with-read-lock (lock) | 60 | (with-read-lock (lock) |
| 56 | dev-group))) | 61 | dev-group))) |
| 57 | 62 | ||
| 63 | (-> owner (&optional config) integer) | ||
| 58 | (defun owner (&optional (config *config*)) | 64 | (defun owner (&optional (config *config*)) |
| 59 | "Get the ID of the bot's owner" | 65 | "Get the ID of the bot's owner" |
| 60 | (with-slots (lock owner) config | 66 | (with-slots (lock owner) config |
| 61 | (with-read-lock (lock) | 67 | (with-read-lock (lock) |
| 62 | owner))) | 68 | owner))) |
| 63 | 69 | ||
| 70 | (-> load-config (pathname &optional config) config) | ||
| 64 | (defun load-config (filename &optional (config *config*)) | 71 | (defun load-config (filename &optional (config *config*)) |
| 65 | "Load config from the given `filename'." | 72 | "Load config from the given `filename'." |
| 66 | (prog1 config | 73 | (prog1 config |
| @@ -71,6 +78,7 @@ | |||
| 71 | (let ((name (intern (symbol-name kw-name) :ukkoclot/src/config))) | 78 | (let ((name (intern (symbol-name kw-name) :ukkoclot/src/config))) |
| 72 | (setf (slot-value config name) value))))))) | 79 | (setf (slot-value config name) value))))))) |
| 73 | 80 | ||
| 81 | (-> serialize (config) list) | ||
| 74 | (defun serialize (config) | 82 | (defun serialize (config) |
| 75 | "Serializes the config to a plist." | 83 | "Serializes the config to a plist." |
| 76 | (with-read-lock ((config-lock config)) | 84 | (with-read-lock ((config-lock config)) |
| @@ -81,10 +89,12 @@ | |||
| 81 | (appending (list (make-keyword name) | 89 | (appending (list (make-keyword name) |
| 82 | (slot-value config name)))))))) | 90 | (slot-value config name)))))))) |
| 83 | 91 | ||
| 92 | (-> print-default (pathname) (values &optional)) | ||
| 84 | (defun print-default (filename) | 93 | (defun print-default (filename) |
| 85 | "Prints the default config to the given `filename'." | 94 | "Prints the default config to the given `filename'." |
| 86 | (with-open-file (f filename :direction :output :if-exists :supersede) | 95 | (with-open-file (f filename :direction :output :if-exists :supersede) |
| 87 | (format f ";; lint:suppress in-package spdx-license-identifier~%") | 96 | (format f ";; lint:suppress in-package spdx-license-identifier~%") |
| 88 | (format f ";; Copy this file to config.lisp and modify it there~%") | 97 | (format f ";; Copy this file to config.lisp and modify it there~%") |
| 89 | (let ((data (serialize (make-config)))) | 98 | (let ((data (serialize (make-config)))) |
| 90 | (format f "~<(~;~@{~(~W~) ~W~^ ~_~}~;)~:>~%" data)))) | 99 | (format f "~<(~;~@{~(~W~) ~W~^ ~_~}~;)~:>~%" data))) |
| 100 | (values)) | ||