summaryrefslogtreecommitdiff
path: root/utils.lisp
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-10-07 18:44:13 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-10-07 18:44:13 +0200
commitb5c357c081a4901c892ab0e61e33ab94ade98086 (patch)
treefcc2b13bf09d5b7cb0c4be6489645aa8cdae9355 /utils.lisp
parente6b65cb7b6c16d1fb9ecb86260dddb1fc0c4b115 (diff)
Make use of Akismet for spam detection.
darcs-hash:8828531ab148ca71cca0a0dbef7733717834cbb4
Diffstat (limited to 'utils.lisp')
-rw-r--r--utils.lisp42
1 files changed, 42 insertions, 0 deletions
diff --git a/utils.lisp b/utils.lisp
index d4a2d77..64edb9e 100644
--- a/utils.lisp
+++ b/utils.lisp
@@ -203,3 +203,45 @@ ELEMENT-TYPE as the stream's."
(when errorp
(assert (not (null list))))
(first list))
+
+
+(defun akismet-login ()
+ (drakma:http-request "http://rest.akismet.com/1.1/verify-key"
+ :protocol :http/1.0
+ :method :post
+ :user-agent "Mulk Journal/0.0.1"
+ :parameters `(("key" . ,*wordpress-key*)
+ ("blog" . "http://matthias.benkard.de/journal"))))
+
+
+(defun akismet-check-comment (comment referrer)
+ #.(locally-enable-sql-reader-syntax)
+ (prog1
+ (with-slots (submitter-user-agent submitter-ip body author website entry-id)
+ comment
+ (drakma:http-request (format nil "http://~A.rest.akismet.com/1.1/comment-check" *wordpress-key*)
+ :protocol :http/1.0
+ :method :post
+ :user-agent "Mulk Journal/0.0.1"
+ :parameters `(("blog" . "http://matthias.benkard.de/journal")
+ ("user_ip" . ,submitter-ip)
+ ("user_agent" . ,submitter-user-agent)
+ ,@(when referrer
+ `(("referrer" . ,referrer)))
+ ("permalink" . ,(link-to :view
+ :post-id (first
+ (select [id]
+ :from [journal-entry]
+ :where [= [id] entry-id]
+ :flatp t))))
+ ("comment_type" . "comment")
+ ("comment_author" . ,author)
+ ("comment_author_url" . ,website)
+ ("comment_content" . ,body))))
+ #.(restore-sql-reader-syntax-state)))
+
+
+(defun detect-spam (comment &key referrer)
+ (ignore-errors
+ (akismet-login)
+ (string= "true" (akismet-check-comment comment referrer))))