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