Sha256: e48a644d490d44f28a6e58b8d56d55f6a92fbd597baefc1f161421bcf835be7e
Contents?: true
Size: 726 Bytes
Versions: 1
Compression:
Stored size: 726 Bytes
Contents
require 'open-uri' require 'hpricot' class Imgur < Linkbot::Plugin Linkbot::Plugin.register('imgur', self, { :message => {:regex => /!imgur/, :handler => :on_message, :help => :help}, :"direct-message" => {:regex => /!imgur/, :handler => :on_message, :help => :help} } ) def self.on_message(message, matches) imgs = [] puts "loading images" 1.upto(3) do |x| doc = Hpricot(open("http://imgur.com/gallery?p=#{x}").read) imgs += doc.search("div[@class=post] a img").collect do |m| m.attributes["src"].gsub("b.jpg", ".jpg") end end img = imgs[rand(imgs.length)] img end def self.help "!imgur - return a random top picture" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
protolink-0.2.8 | example/linkbot/plugins/imgur.rb |