diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2010-12-03 18:00:43 -0500 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2010-12-03 18:00:43 -0500 |
| commit | 4ccea08b8edbd3440f23cee2730a62d4013dc6e0 (patch) | |
| tree | 4ec5b32b9719c9fbdc629b06f324f43a1c0a9f62 /src/message.clj | |
| parent | 13541b84837c8f360e2ae825d81ae489691b9e14 (diff) | |
| parent | 59af476f7d0c29319931102f05b7b6da63c5ee54 (diff) | |
Merge branch 'master' of ssh://dump.fm/pichat/repo
Diffstat (limited to 'src/message.clj')
| -rw-r--r-- | src/message.clj | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/message.clj b/src/message.clj new file mode 100644 index 0000000..a8e0e9b --- /dev/null +++ b/src/message.clj @@ -0,0 +1,39 @@ +(ns message + (:use user)) + +;; Message parsing + +;; http://snippets.dzone.com/posts/show/6995 +(def url-regex #"(?i)^((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$") +(def pic-regex #"(?i)\.(jpg|jpeg|png|gif|bmp|svg)(\?|&|$)") + +(defn is-image? [word] + (and (re-find url-regex word) + (re-find pic-regex word))) + +(defn take-images [content] + (filter is-image? (.split content " "))) + +(defn classify-msg [msg] + (let [words (.split msg " ") + imgs (map is-image? words)] + (cond (every? boolean imgs) :image + (some boolean imgs) :mixed + :else :text))) + +(def recip-regex #"(?:^|\s)@\w+") + +(defn get-recips [content] + (filter + boolean + (for [at-nick (re-seq recip-regex content)] + (fetch-nick (.substring (.trim at-nick) 1))))) + +(defn get-recips-from-msgs [msgs] + (let [recips (set (apply concat + (for [m msgs] + (re-seq recip-regex (:content m)))))] + (filter + boolean + (for [r recips] + (fetch-nick (.substring (.trim r) 1)))))) |
