random messages
This commit is contained in:
parent
83a6c30351
commit
f1a3f67533
2 changed files with 10 additions and 3 deletions
12
bot.lisp
12
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))))
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
local-time
|
||||
deploy
|
||||
cl-yaml
|
||||
alexandria
|
||||
]);
|
||||
in {
|
||||
# Per-system attributes can be defined here. The self' and inputs'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue