Compare commits

..

2 commits

Author SHA1 Message Date
Mike Russo
a1a26e5df4 parameterize birthdays as well 2025-04-18 15:02:23 -06:00
Mike Russo
fb371cbb31 add another test bday for tmrw 2025-04-18 14:17:41 -06:00
2 changed files with 45 additions and 27 deletions

View file

@ -4,7 +4,7 @@
;; (:export main*))
;; (in-package :birthday-boy)
(load (sb-ext:posix-getenv "ASDF"))
(asdf:load-systems :dexador :local-time :jonathan)
(asdf:load-systems :dexador :local-time :jonathan :cl-yaml :cl-dotenv)
;;
;; (.env:load-env (merge-pathnames ".env"))
;; (ql:quickload '(:dexador :cl-dotenv :local-time :jonathan))
@ -76,14 +76,7 @@
;; (list
;; :|reason| "for birthday bot")))
(defvar *birthdays* '((:person "carl" :month 4 :day 13)
(:person "noellie" :month 7 :day 15)
(:person "joe" :month 9 :day 17)
(:person "daniel" :month 7 :day 18)
(:person "mike" :month 2 :day 13)
(:person "David Tennant" :month 4 :day 18)
(:person "famous actor Sean Bean" :month 4 :day 17)
(:person "bwandice" :month 10 :day 15)))
(defvar *birthdays* nil)
(defun is-today (tstamp)
@ -99,10 +92,9 @@
(defun is-today* (day month)
(is-today (local-time:encode-timestamp 0 0 0 0 day month 1900)))
(defun collect-bdays ()
(loop for person in *birthdays*
when (is-today* (getf person :day) (getf person :month))
(loop for person in (gethash "birthdays" *birthdays*)
when (is-today* (gethash "day" person) (gethash "month" person))
collect person))
@ -112,9 +104,32 @@
(defun main ()
;; (.env:load-env env-file)
(dolist (person (collect-bdays))
(message (make-bday-message (getf person :person)) "ROOM_ID")))
(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"))
(missing-vars '()))
(dolist (var required-vars)
(unless (uiop:getenv var)
(push var missing-vars)))
(when missing-vars
(format t "ERROR: Missing required environment variables:~%")
(dolist (var missing-vars)
(format t " - ~A~%" var))
(sb-ext:exit :code 1))
t))
(defun main* ()
(unwind-protect (main)
(sb-ext:exit :code 0)))
(let* ((args sb-ext:*posix-argv*)
(env-file (or (second args) #P".env"))
(birthdays-file (or (third args) "./birthdays.yml")))
(format t "Using env file: ~A~%" env-file)
(format t "Using birthdays file: ~A~%" birthdays-file)
(.env:load-env env-file)
(check-required-env-vars)
(unwind-protect
(let ((*birthdays* (cl-yaml:parse (pathname birthdays-file))))
(main))
(sb-ext:exit :code 0))))

View file

@ -21,8 +21,15 @@
[ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
sbcl' = pkgs.sbcl.withPackages
(ps: with ps; [ dexador cl-dotenv jonathan local-time deploy ]);
sbcl' = pkgs.sbcl.withPackages (ps:
with ps; [
dexador
cl-dotenv
jonathan
local-time
deploy
cl-yaml
]);
in {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
@ -48,13 +55,13 @@
cp birthday-boy $out/bin/_birthday-boy
chmod +x $out/bin/_birthday-boy
touch $out/bin/birthday-boy
echo "#!/usr/bin/env sh" >> $out/bin/birthday-boy
echo "env \$(grep -v '^#' \$1 | xargs -d '\n') LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${
pkgs.lib.makeLibraryPath [ pkgs.openssl ]
} $out/bin/_birthday-boy" >> $out/bin/birthday-boy
echo "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${
pkgs.lib.makeLibraryPath [ pkgs.openssl pkgs.libyaml ]
} $out/bin/_birthday-boy \$1 \$2" >> $out/bin/birthday-boy
# cp run.sh $out/bin/birthday-boy
chmod +x $out/bin/birthday-boy
'';
};
@ -65,11 +72,7 @@
devshells.default = {
env = [ ];
commands = [ ];
packages = with pkgs; [
openssl
(sbcl.withPackages
(p: with p; [ dexador cl-dotenv jonathan local-time deploy ]))
];
packages = with pkgs; [ openssl sbcl' ];
};
};
flake = {