From adfedd999771a60b2a804066ff2ff6f0f2643eb5 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 1 Mar 2022 12:19:19 -0600 Subject: --explain now fetches oneliners from server when needed --- src/lib.lisp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lib.lisp b/src/lib.lisp index 2f25ac7..9253484 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -166,10 +166,25 @@ the directories that appear in the value of that variable." (format t "Could not find the oneliner specified by ~a~%" ,nvar))))) (defun print-item-explanation (number &optional idp) - (with-cached-result (ol number idp) - (when (getf ol :explanation) - (princ #\newline) - (princ (getf ol :explanation))))) + (let ((found nil)) + (with-cached-result (ol number idp) + (setf found t) + (when (getf ol :explanation) + (princ #\newline) + (princ (getf ol :explanation)))) + (when (and idp (not found)) + (format t "Trying to fetch oneliner with id ~a from the wiki.~%" number) + (ensure-config) + (a:if-let ((ol + (api:request-with (:host (host)) + (jonathan:parse + (api::get--oneliner-entry number))))) + (progn + (when (getf ol :explanation) + (princ #\newline) + (princ (getf ol :explanation))) + (merge-into-cache (list ol))) + (format t "Still couldn't find it. Are you connected?"))))) ;;; API REQUEST FUNCTIONS @@ -256,7 +271,7 @@ the directories that appear in the value of that variable." (setf found t) (bind-vars-and-run-oneliner ol args force-clip)) (when (and by-id (not found)) - (format t "Trying to fetch that oneliner with id ~a from the wiki.~%" item-number) + (format t "Trying to fetch oneliner with id ~a from the wiki.~%" item-number) (ensure-config) (a:if-let ((ol (api:request-with (:host (host)) @@ -264,7 +279,7 @@ the directories that appear in the value of that variable." (api::get--oneliner-entry item-number))))) (progn (bind-vars-and-run-oneliner ol args force-clip) (merge-into-cache (list ol))) - (format t "Still couldn't find it. Is something wrong?"))))) + (format t "Still couldn't find it. Are you connected?"))))) (defun valid-oneliner-string-p (string) (and (not (find #\newline string)) -- cgit v1.2.3