【新月実装】需【Clojure・ClojureScript】

e5f674cc :Anonymous 2016-01-20 16:01
@markdown
下はスパムの削除に使用したコードです。コピペ荒らしは期間とスレが限定されていたので割と楽に削除できました。

```clojure
(defn remove-spam
[]
(dorun (map (fn [record]
(let [record (ju.db.core/get-record-by-id (:id record))
body (String. (:body record) "UTF-8")
elements (->> (clojure.string/split body #"<>")
(map #(re-find #"^([a-zA-Z0-9]+):(.*)$" %))
(map #(do {(keyword (nth % 1)) (nth % 2)}))
(apply merge))
thread-title (unhexify (second (re-find #"^thread_(.*)$" (:file-name (ju.db.core/get-file-by-id (:file-id record))) )))]
(when (or (and (:name elements) (pos? (count (:name elements)))
(:mail elements) (pos? (count (:mail elements)))
(:body elements)
(or (re-find #"^[^ぁ-ゞァ-ヶ]+$" (:body elements))
(re-find #"http://|href=" (:body elements))))
(and (<= 1368259441 (:stamp record)) (<= (:stamp record) 1368334184)
(some #{thread-title}
#{"新月を広める方法を考えよう~♪"
"\"2ちゃんねるに代わる新たな新天地\"\"新月\"\"\""
"【2ch】難民キャンプ【書き込み規制】"
"SPAM"
"雑談しながらリンクを貼るスレ"
"新月の開発"
"【ただひたすら書き込むスレ】"
"雑談"
"初心者用質問スレッド"
"Twitterの真似事"
"ここが新月かぁ~"
"今日の天気を報告するスレ"
"メニュー"
"朔の「状態」を晒す"})
(not (some #{[(:stamp record) thread-title]}
#{[1368269164 "朔の「状態」を晒す"]
[1368288797 "朔の「状態」を晒す"]
[1368322356 "朔の「状態」を晒す"]
[1368291561 "新月の開発"]
[1368292773 "新月の開発"]
[1368324146 "新月の開発"]
[1368287598 "新月を広める方法を考えよう~♪"]
[1368321534 "新月を広める方法を考えよう~♪"]
[1368321715 "新月を広める方法を考えよう~♪"]
[1368323070 "【2ch】難民キャンプ【書き込み規制】"]
[1368289606 "ここが新月かぁ~"]
[1368289928 "ここが新月かぁ~"]
[1368287843 "初心者用質問スレッド"]
[1368294225 "初心者用質問スレッド"]}))))
(ju.db.core/mark-record-as-deleted (:id record))
(taoensso.timbre/info (:id record)
(:stamp record)
thread-title
(:body elements)))
(if (zero? (mod (:id record) 100))
(comment taoensso.timbre/info "Processed" (:id record) "records."))))
(sort #(< (:id %1) (:id %2)) (ju.db.core/get-all-records-with-ids-only))))
(ju.db.core/update-all-files))
```
Powered by shinGETsu.