<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/commode/util.clj</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,4 @@
 #*
 .*#
 *#
+.DS_Store</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -5,12 +5,12 @@
 
 (require '[clojure.contrib.str-utils2 :as s])
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; configuration ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; configuration ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; some global constants and vars
-(def bot)                                       ; will hold pircbot object
-(def channels (ref {}))                         ; will hold :channame =&gt; Agent(chanstate
+(def bot)                                       ; pircbot object
+(def channels (ref {}))                         ; {&quot;channame&quot; =&gt; Agent(chanstate)}
 (def memory-sleep-ms 5000)                      ; amount of time between reloading memory from database
 (def running true)                              ; yes, we want our monitor agents to run continuously
 
@@ -32,33 +32,28 @@
            :password &quot;&quot;}))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; util ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(defn rand-elm &quot;returns a random element from the sequence, or nil for an empty sequence&quot;
-  [seq] 
-  (let [size (count seq)]
-    (if (&gt; size 0)
-      (nth seq (rand-int (count seq))))))
-
-(defn rand-elm-weighted &quot;takes a [{:weight x, ...} ...] sequence, and returns a weighted-random element&quot;
-  [seq]
-  nil) ;; TODO
+;; structs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defn starts-with [prefix string]
-  (.startsWith string prefix))
+(defstruct msg  :this :channel :sender :login :hostname :message)
+(defstruct chan :channel :nicks)
 
-(defmacro async &quot;just do this, I don't care&quot; [&amp; x]
-  `(send-off (agent nil) (fn [&amp; _#] ~@x )))
-
-; (maybe 0.1 (foo) (bar))
-(defmacro maybe [chance &amp; fns]
-  `(when (&lt; (rand) ~chance)
-     ~@fns))
+(load &quot;commode/util&quot;)
     
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; irc helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defn say [destination &amp; messages]
+(defmacro do-chan [{channel :channel} fun &amp; args]
+  `(send-off (@channels ~channel) 
+             (fn [a# &amp; _#] 
+               (dorun (~fun a# ~@args))
+               a#)))
+
+(defmacro alter-chan [{channel :channel} fun &amp; args]
+  `(send-off (@channels ~channel) 
+             ~fun ~@args))
+
+(defn say [chan &amp; messages]
+  (do-chan chan
   (dorun (map (fn [message]
                 (.sendMessage bot destination message)
                 message)
@@ -68,8 +63,15 @@
   (map #(.getNick %) (.getUsers bot channel)))
 
 (defn join [channel]
+  (dosync
+   (alter channels assoc channel (agent (struct chan channel nil))))
   (.joinChannel bot channel))
 
+(defn part [channel]
+  (dosync
+   (alter channels assoc channel nil))
+  (.leaveChannel bot channel))
+
 (defn nick 
   ([] (.getNick bot))
   ([s] (.changeNick bot s)))
@@ -151,8 +153,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; messages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defstruct msg :this :channel :sender :login :hostname :message)
-
 (defn nick-prefix-pattern []
   (re-pattern (str &quot;^&quot; (nick) &quot;[:,]\\s&quot;)))
 
@@ -170,38 +170,29 @@
     (subs s 0 (dec (count s)))
     s))
 
-(defn origin [msg]
-  (if (:channel msg)
-    (:channel msg)
-    (:sender  msg)))
-
-(defn dispatch [msg]
+(defn dispatch [chan msg]
   (let [normalized-message (strip-nick-prefix (strip-? (:message msg)))]
     (cond
-      (= normalized-message &quot;!help&quot;) :help
-      (addressed? msg) :lookup)))
+      (= normalized-message &quot;karma++&quot;) :add-karma
+      (= normalized-message &quot;karma--&quot;) :rem-karma
+      (addressed? msg)                 :lookup
+      :else                            :default)))
 
 (defmulti responder dispatch)
 
-(defmethod responder :help [msg]
-  (say (origin msg)
-       &quot;ja hallo, nou moet ik zeker al m'n geheime truukjes op tafel leggen&quot;))
-
-(defmethod responder :lookup [msg]
-  (let [response (lookup (:message msg))]
-    (if response
-      (action (origin msg)
-              (transform msg (lookup (:message msg)))))))
-
-(defmethod responder :default [msg]
-  (let [response (lookup (:message msg))]
-    (if response
-      (maybe 0.2 (action (origin msg)
-                         (transform msg response))))))
-
-(defn action [destination response]
-  (say destination 
-       (.replaceFirst response &quot;&lt;reply&gt;&quot; &quot;&quot;)))
+(defmethod responder :add-karma [{channel :channel} msg]
+  (say channel &quot;maar dat kan ik, helemaal niet&quot;))
+
+(defmethod responder :rem-karma [{channel :channel} msg]
+  (say channel &quot;maar dat kan ik, helemaal niet&quot;))
+
+(defmethod responder :lookup [{channel :channel} msg]
+  (when-let [response (lookup (msg :message))]
+    (say channel (transform msg response))))
+
+(defmethod responder :default [{channel :channel msg]
+  (when-let [response (lookup (:message msg))]
+    (maybe 0.2 (say channel (transform msg response)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; irc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</diff>
      <filename>src/commode.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>10923ba036e6ab07ca435d39bd641c397a8ced0b</id>
    </parent>
  </parents>
  <author>
    <name>Marten Veldthuis</name>
    <email>marten@veldthuis.com</email>
  </author>
  <url>http://github.com/marten/clojure-irc-infobot/commit/26414f363d4869c4d91acd8eebc895f78117d3ba</url>
  <id>26414f363d4869c4d91acd8eebc895f78117d3ba</id>
  <committed-date>2009-11-01T01:54:59-07:00</committed-date>
  <authored-date>2009-11-01T01:54:59-07:00</authored-date>
  <message>moved utils out, reorganization, channel agents</message>
  <tree>86839568b9b294241e64ae3663add98ea0b09110</tree>
  <committer>
    <name>Marten Veldthuis</name>
    <email>marten@veldthuis.com</email>
  </committer>
</commit>
