diff options
author | Colin Okay <okay@toyful.space> | 2022-03-01 12:19:19 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-01 12:19:19 -0600 |
commit | adfedd999771a60b2a804066ff2ff6f0f2643eb5 (patch) | |
tree | 9cacdaa4643217a3cdc36e6e66c309e2c3a9216e /src | |
parent | ff8a6b5bb611fa5094de230e38c7f35188726e79 (diff) |
--explain now fetches oneliners from server when needed
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.lisp | 27 |
1 files changed, 21 insertions, 6 deletions
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)) |