def doPrivmsg(self, irc, msg): if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg): return channel = msg.args[0] if irc.isChannel(channel): if ircmsgs.isAction(msg): text = ircmsgs.unAction(msg) else: text = msg.args[1] for url in utils.web.urlRe.findall(text): #http://us.battle.net/d3/en/calculator/monk#WVYjRk!YUa!cZZaYb m = re.search("battle.net/d3/en/calculator/([\\w-]+)#([\\w\\.]+)!([\\w\\.]+)!([\\w\\.]+)", url) if m: sk = [self.skilldata[m.group(1)]["skills"][f] for f in self._hash_decode(m.group(2))] out = self.classes[m.group(1)] + ": " #classname out += ", ".join(["%s (%s)" % (sk[n]["name"], ("none" if f < 0 else sk[n]["runes"][f]["name"])) for (n, f) in enumerate(self._hash_decode(m.group(4)))]) #skills out += " / " out += ", ".join([self.skilldata[m.group(1)]["traits"][f]["name"] for f in self._hash_decode(m.group(3))]) #traits irc.reply(out, prefixNick=False) return #no need no check the other url formats. #https://twitter.com/#!/Nyzaris/status/179599382814011392 m = re.search("twitter.com/(?:#!/)?.+/status(?:es)?/(\d+)", url) if m: resp, j = self._h.request("http://api.twitter.com/1/statuses/show/%s.json" % m.group(1), "GET") tjson = json.loads(j) irc.reply("%s (%s): %s" % (tjson["user"]["screen_name"], tjson["user"]["name"], tjson["text"]), prefixNick=False) return m = re.search("redd.it/(.+)", url) if m: url = "http://www.reddit.com/comments/%s/.json" % m.group(1) # don't return because we want to go through the next block if url.find("reddit.com/") != -1: resp, j = self._h.request(url + ".json?limit=1", "GET") try: f = json.loads(j)[0]["data"]["children"][0]["data"] except KeyError: return #it probably was a link to a subreddit or something, so don't sweat it if f["is_self"]: irc.reply("Reddit: (+%d) %s (%s) by %s %s ago. %d comment%s." % (f["score"], f["title"], f["domain"], f["author"], DiabloCommon.timeago(time.time() - f["created_utc"]), f["num_comments"], "s" if f["num_comments"] != 1 else ""), prefixNick=False) else: irc.reply("Reddit: (+%d) %s (%s) by %s %s ago. %d comment%s." % (f["score"], f["title"], f["url"], f["author"], DiabloCommon.timeago(time.time() - f["created_utc"]), f["num_comments"], "s" if f["num_comments"] != 1 else ""), prefixNick=False) return