diff --git a/bot.lisp b/bot.lisp index 8f3c446..84de8ca 100644 --- a/bot.lisp +++ b/bot.lisp @@ -5,7 +5,7 @@ (in-package :birthday-boy) (load (sb-ext:posix-getenv "ASDF")) -(asdf:load-systems :dexador :local-time :jonathan :cl-yaml) +(asdf:load-systems :dexador :local-time :jonathan :cl-yaml :alexandria) (defvar *birthdays* nil "Hashtable of birthdays.") @@ -95,14 +95,18 @@ (defun make-bday-message (person) - (format nil "Hey hey hey, its the birthday boy, and I am pleased to announce that it is ~A's today. Congratulation, I love you." person)) + (format nil (alexandria:random-elt (gethash "bot_message_template" *config*)) person)) + +(defun seed-random-state () + "Seed the random state with current time for true randomness between runs" + (setf *random-state* (make-random-state t))) (defun main () (dolist (person (collect-bdays)) (message (make-bday-message (gethash "person" person)) "ROOM_ID"))) (defun check-required-env-vars () - (let ((required-vars '("bot_name" "bot_pw" "bot_access_token" "homeserver_url" "room_id")) + (let ((required-vars '("bot_name" "bot_pw" "bot_access_token" "homeserver_url" "room_id" "bot_message_template")) (missing-vars '())) (dolist (var required-vars) @@ -120,10 +124,12 @@ (let* ((args sb-ext:*posix-argv*) (config-file (or (second args) "./config.yml"))) (format t "Using config file: ~A~%" config-file) + (unwind-protect (let* ((base-config (cl-yaml:parse (pathname config-file))) (*birthdays* (gethash "birthdays" base-config)) (*config* (gethash "config" base-config))) + (seed-random-state) (check-required-env-vars) (main)) (sb-ext:exit :code 0)))) diff --git a/flake.nix b/flake.nix index 8a01110..edc0575 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,7 @@ local-time deploy cl-yaml + alexandria ]); in { # Per-system attributes can be defined here. The self' and inputs'