Created
August 12, 2013 07:06
-
-
Save hisaichi5518/6208747 to your computer and use it in GitHub Desktop.
tumblr irc bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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