summaryrefslogtreecommitdiff
path: root/src/message.clj
diff options
context:
space:
mode:
authorScott Ostler <sbsotler@gmail.com>2010-11-29 01:15:49 -0500
committerScott Ostler <sbsotler@gmail.com>2010-11-29 01:15:49 -0500
commitdd46cb29fa939546908db15fc92491bc49f3130f (patch)
tree50b8f74086728540cbc49249d4b98aacb9040d12 /src/message.clj
parentd82ee6e32595edef8b7c5782f72eacac24d8a0c2 (diff)
Commit initial vip-only direct messaging
Diffstat (limited to 'src/message.clj')
-rw-r--r--src/message.clj39
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))))))