Skip to content
Browse files

Rewrite numbering logic and add a 'timers' command.

  • Loading branch information...
1 parent d3396fc commit 673f78a0c2fd099f472cae487497f7f32a1c0346 @Raynes committed
Showing with 13 additions and 9 deletions.
  1. +13 −9 src/lazybot/plugins/timer.clj
View
22 src/lazybot/plugins/timer.clj
@@ -17,18 +17,14 @@
(m/schedule-at executor (time-to-ms spec)
(fn []
(send-message com-m (:message spec))
- (swap! running-timers
- #(-> %
- (update-in [:count] dec)
- (dissoc count))))))
+ (swap! running-timers dissoc count))))
(defn set-timer [spec com-m]
(swap! running-timers
(fn [x]
- (let [count (inc (:count x 0))]
- (assoc x
- :count count
- count (task count spec com-m))))))
+ (let [count (inc (apply max (or (keys x) [0])))]
+ (assoc x count {:task (task count spec com-m)
+ :message (:message spec)})))))
(defn parse-message [s]
(let [[offset message] (s/split s #" " 2)]
@@ -44,4 +40,12 @@
(-> (s/join " " args)
(parse-message)
(set-timer com-m))
- (send-message com-m "Timer added."))))
+ (send-message com-m "Timer added.")))
+ (:cmd
+ "List the running timers."
+ #{"timers"}
+ (fn [com-m]
+ (send-message com-m
+ (s/join "; "
+ (for [[k {m :message}] @running-timers]
+ (format "%d: %s" k (s/join (take 20 m)))))))))

0 comments on commit 673f78a

Please sign in to comment.
Something went wrong with that request. Please try again.