Compare commits
2 commits
2435821cab
...
a1a26e5df4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1a26e5df4 | ||
|
|
fb371cbb31 |
2 changed files with 45 additions and 27 deletions
47
bot.lisp
47
bot.lisp
|
|
@ -4,7 +4,7 @@
|
||||||
;; (:export main*))
|
;; (:export main*))
|
||||||
;; (in-package :birthday-boy)
|
;; (in-package :birthday-boy)
|
||||||
(load (sb-ext:posix-getenv "ASDF"))
|
(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"))
|
;; (.env:load-env (merge-pathnames ".env"))
|
||||||
;; (ql:quickload '(:dexador :cl-dotenv :local-time :jonathan))
|
;; (ql:quickload '(:dexador :cl-dotenv :local-time :jonathan))
|
||||||
|
|
@ -76,14 +76,7 @@
|
||||||
;; (list
|
;; (list
|
||||||
;; :|reason| "for birthday bot")))
|
;; :|reason| "for birthday bot")))
|
||||||
|
|
||||||
(defvar *birthdays* '((:person "carl" :month 4 :day 13)
|
(defvar *birthdays* nil)
|
||||||
(: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)))
|
|
||||||
|
|
||||||
|
|
||||||
(defun is-today (tstamp)
|
(defun is-today (tstamp)
|
||||||
|
|
@ -99,10 +92,9 @@
|
||||||
(defun is-today* (day month)
|
(defun is-today* (day month)
|
||||||
(is-today (local-time:encode-timestamp 0 0 0 0 day month 1900)))
|
(is-today (local-time:encode-timestamp 0 0 0 0 day month 1900)))
|
||||||
|
|
||||||
|
|
||||||
(defun collect-bdays ()
|
(defun collect-bdays ()
|
||||||
(loop for person in *birthdays*
|
(loop for person in (gethash "birthdays" *birthdays*)
|
||||||
when (is-today* (getf person :day) (getf person :month))
|
when (is-today* (gethash "day" person) (gethash "month" person))
|
||||||
collect person))
|
collect person))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -112,9 +104,32 @@
|
||||||
(defun main ()
|
(defun main ()
|
||||||
;; (.env:load-env env-file)
|
;; (.env:load-env env-file)
|
||||||
(dolist (person (collect-bdays))
|
(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* ()
|
(defun main* ()
|
||||||
(unwind-protect (main)
|
(let* ((args sb-ext:*posix-argv*)
|
||||||
(sb-ext:exit :code 0)))
|
(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))))
|
||||||
|
|
|
||||||
25
flake.nix
25
flake.nix
|
|
@ -21,8 +21,15 @@
|
||||||
[ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
[ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||||
perSystem = { config, self', inputs', pkgs, system, ... }:
|
perSystem = { config, self', inputs', pkgs, system, ... }:
|
||||||
let
|
let
|
||||||
sbcl' = pkgs.sbcl.withPackages
|
sbcl' = pkgs.sbcl.withPackages (ps:
|
||||||
(ps: with ps; [ dexador cl-dotenv jonathan local-time deploy ]);
|
with ps; [
|
||||||
|
dexador
|
||||||
|
cl-dotenv
|
||||||
|
jonathan
|
||||||
|
local-time
|
||||||
|
deploy
|
||||||
|
cl-yaml
|
||||||
|
]);
|
||||||
in {
|
in {
|
||||||
# Per-system attributes can be defined here. The self' and inputs'
|
# Per-system attributes can be defined here. The self' and inputs'
|
||||||
# module parameters provide easy access to attributes of the same
|
# module parameters provide easy access to attributes of the same
|
||||||
|
|
@ -48,13 +55,13 @@
|
||||||
cp birthday-boy $out/bin/_birthday-boy
|
cp birthday-boy $out/bin/_birthday-boy
|
||||||
chmod +x $out/bin/_birthday-boy
|
chmod +x $out/bin/_birthday-boy
|
||||||
|
|
||||||
|
|
||||||
touch $out/bin/birthday-boy
|
touch $out/bin/birthday-boy
|
||||||
echo "#!/usr/bin/env sh" >> $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:${
|
echo "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${
|
||||||
pkgs.lib.makeLibraryPath [ pkgs.openssl ]
|
pkgs.lib.makeLibraryPath [ pkgs.openssl pkgs.libyaml ]
|
||||||
} $out/bin/_birthday-boy" >> $out/bin/birthday-boy
|
} $out/bin/_birthday-boy \$1 \$2" >> $out/bin/birthday-boy
|
||||||
|
|
||||||
# cp run.sh $out/bin/birthday-boy
|
|
||||||
chmod +x $out/bin/birthday-boy
|
chmod +x $out/bin/birthday-boy
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
@ -65,11 +72,7 @@
|
||||||
devshells.default = {
|
devshells.default = {
|
||||||
env = [ ];
|
env = [ ];
|
||||||
commands = [ ];
|
commands = [ ];
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [ openssl sbcl' ];
|
||||||
openssl
|
|
||||||
(sbcl.withPackages
|
|
||||||
(p: with p; [ dexador cl-dotenv jonathan local-time deploy ]))
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
flake = {
|
flake = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue