Created
June 11, 2010 15:41
-
-
Save raek/434657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns myrbot.core | |
(:use irclj.irclj)) | |
;;; cond-re macro | |
(defn- re-clause-to-if [s [re bindings body] else] | |
`(if-let [[~'_ ~@bindings] (re-find ~re ~s)] | |
~body | |
~else)) | |
(defn- re-clauses-to-ifs [s clauses] | |
(when-first [clause clauses] | |
(if (and (not (next clauses)) | |
(= (count clause) 1)) | |
(first clause) | |
(re-clause-to-if s clause (re-clauses-to-ifs s (rest clauses)))))) | |
(defmacro cond-re [s & clauses] | |
(re-clauses-to-ifs s (partition 3 3 nil clauses))) | |
;;; The IRC bot | |
(def ignored #{"=D" "=)"}) | |
(defn on-message [{:keys [irc channel nick message]}] | |
(when-not (ignored message) | |
(cond-re message | |
#"^=(.*)" [exp] (send-message irc channel (format "Eval command \"%s\"" exp)) | |
#"^~(.*)" [str] (send-message irc channel (format "Squiggly command \"%s\"" str)) | |
#"jumbo/LARGE" [] (send-message irc channel "Hey! No in-jokes!")))) | |
(def bot (connect (create-irc {:name "myrbot" | |
:server "irc.quakenet.org" | |
:fnmap {:on-message #'on-message}}) | |
:channels ["#d1d" "#myrbot"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment