Permalink
Browse files

Write a plugin for metacritic stuff.

  • Loading branch information...
Raynes committed Feb 17, 2013
1 parent 3b95235 commit 88b52c5f93cfb9ebcc76fa4ac73ef62a0386fb7c
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/lazybot/plugins/metacritic.clj
@@ -0,0 +1,40 @@
+(ns lazybot.plugins.metacritic
+ (:require [lazybot.registry :refer [send-message defplugin]]
+ [me.raynes.laser :as l]
+ [clojure.string :as s]))
+
+(def paths
+ {"xbox" "/game/xbox-360/"
+ "pc" "/game/pc/"
+ "ps3" "/game/playstation-3/"
+ "movie" "/movie/"})
+
+(defn normalize [s]
+ (s/join "-" (map s/lower-case s)))
+
+(def url "http://www.metacritic.com")
+
+(defn metacritic [args]
+ (let [[type & args] args
+ path (str url (paths type) (normalize args))]
+ (if-let [html (try (l/parse (slurp path))
+ (catch Exception _))]
+ (let [[critic user] (map (comp l/text first)
+ [(l/select html
+ (l/descendant-of
+ (l/class= "main_details")
+ (l/class= "score_value")))
+ (l/select html
+ (l/descendant-of
+ (l/class= "userscore_wrap")
+ (l/class= "score_value")))])]
+ (str "Critics: " critic "; User: " user " - " path))
+ "I'm a little drunk. Can't find my keys.")))
+
+(defplugin
+ (:cmd
+ "Look up scores for a game, movie, or album on metacritic. Pass the type of thing it is.
+ This can be movie, xbox, ps3, pc, or album."
+ #{"metacritic"}
+ (fn [{:keys [args] :as com-m}]
+ (send-message com-m (metacritic args)))))

0 comments on commit 88b52c5

Please sign in to comment.