Skip to content

Instantly share code, notes, and snippets.

@hisaichi5518
Created August 12, 2013 07:06
Show Gist options
  • Save hisaichi5518/6208747 to your computer and use it in GitHub Desktop.
Save hisaichi5518/6208747 to your computer and use it in GitHub Desktop.
tumblr irc bot.
# -*- encoding: utf-8 -*-
require 'cinch'
require 'tumblr_client'
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.server"
c.port = 5000
c.password = 'secret'
c.channels = ["#tumbirc"]
c.nick = 'tumbirc'
c.realname = 'tumbirc'
c.user = 'tumbirc'
c.ssl.use = 1
end
Tumblr.configure do |config|
config.consumer_key = ""
config.consumer_secret = ""
end
on :message, /#(.+)/ do |m, tag|
client = Tumblr::Client.new
posts = client.tagged(tag)
photo_urls = [];
posts.each{|post|
if post["type"] == "photo" then
post["photos"].each{|photo|
photo_urls << photo["alt_sizes"][0]["url"]
}
end
}
m.reply photo_urls[rand(photo_urls.length)]
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment