~technomancy/pengbot

179781d346e52a24420254be66914150a2799f0b — Phil Hagelberg 1 year, 18 days ago 004a954 strangeloop
Add strangeloop command which tells you upcoming talks.
1 files changed, 28 insertions(+), 2 deletions(-)

M handlers.fnl
M handlers.fnl => handlers.fnl +28 -2
@@ 40,6 40,30 @@
  (.. "The next lisp game jam starts on "
      (jam-date caps.os.date (caps.os.time)) "."))

(fn talks-for [talks the-time]
  (faccumulate [out [] i 1 (length talks) 2 &until (< 4 (length out))]
    (let [time (. talks i)
          title (. talks (+ i 1))]
      (if (< the-time time)
          (doto out (table.insert (.. time " " title)))
          out))))

(fn schedule-for [schedule day time]
  (case (. schedule day)
    talks (.. "Upcoming talks: " (table.concat (talks-for talks time) ", "))
    _ (.. "No talks on the day " day)))

(fn strangeloop [_ args {: caps}]
  (let [schedule (require :strangeloop)
        this-day (caps.os.date "%d" (caps.os.time))
        this-time (+ (* (tonumber (caps.os.date "%H" (caps.os.time))) 1000)
                     (tonumber (caps.os.date "%m" (caps.os.time))) 1000)]
    (case (split args)
      ["help"] "usage: strangeloop [day] [time]"
      [day time] (schedule-for schedule (tonumber day) (tonumber time))
      [time] (schedule-for schedule (tonumber this-day) (tonumber this-time))
      [] (schedule-for schedule (tonumber this-day) (tonumber this-time)))))

(fn tell [_ args {: caps}]
  (match (split args)
    [nick :about term] (.. nick ": " term " is " (get-term caps.io term))


@@ 83,15 107,17 @@
 :tell tell
 : jam
 :reload (fn [_ module-name]
           (let [mod (require module-name)]
           (let [module-name (if (= "" module-name) :handlers module-name)
                 mod (require module-name)]
             (tset package.loaded module-name nil)
             (each [k v (pairs (require module-name))]
               (tset mod k v))
             (tset package.loaded module-name mod))
           "OK, reloaded")
           (.. "OK, reloaded " module-name))
 :debug (fn []
          (set _G.debug? (not _G.debug?))
          (if _G.debug? "Debug enabled." "Debug disabled."))
 : strangeloop
 :pull (fn [_ ?branch {: caps}] (fennels.pull caps ?branch))
 :branch (fn [_ args {: caps}]
           (fennels.branch caps.os args)