Skip to content

Commit

Permalink
Propagate data for xkcd command
Browse files Browse the repository at this point in the history
  • Loading branch information
devth committed Mar 28, 2023
1 parent cebdb95 commit de10577
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/yetibot/commands/xkcd.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@
[json]
((juxt :title :img :alt) json))

(defn xkcd-cmd
(defn xkcd-cmdb
"xkcd # fetch current xkcd comic"
{:yb/cat #{:fun :img}}
[_]
(let [json (get-json (endpoint))]
(reset! todays-comic-number (:num json))
(format-xkcd-response json)))
{:result/value (format-xkcd-response json)
:result/data json}))

(defn xkcd-idx-cmd
"xkcd <index> # fetch xkcd number <index>"
{:yb/cat #{:fun :img}}
[{index :match}]
(format-xkcd-response
(try
(get-json (endpoint index))
(catch Exception _
(get-json (endpoint 1969))))))
(let [json (try
(get-json (endpoint index))
(catch Exception _
(get-json (endpoint 1969))))]
{:result/value (format-xkcd-response json)
:result/data json}))

(defn xkcd-rnd-cmd
"xkcd random # fetch random xkcd comic"
{:yb/cat #{:fun :img}}
[_]
(format-xkcd-response (get-json (endpoint (random-comic-num)))))
(let [json (get-json (endpoint (random-comic-num)))]
{:result/value (format-xkcd-response json)
:result/data json}))

(cmd-hook #"xkcd"
#"\d+" xkcd-idx-cmd
Expand Down

0 comments on commit de10577

Please sign in to comment.