diff options
Diffstat (limited to 'src/config.lisp')
| -rw-r--r-- | src/config.lisp | 10 |
1 files changed, 7 insertions, 3 deletions
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))) |