Skip to content

Instantly share code, notes, and snippets.

@kalleth
Created September 9, 2013 10:01
Show Gist options
  • Save kalleth/6493709 to your computer and use it in GitHub Desktop.
Save kalleth/6493709 to your computer and use it in GitHub Desktop.
Twitter bot to relay a twitter account to IRC
#!/usr/bin/env ruby
require 'cinch'
require 'tweetstream'
require 'pry'
require 'pp'
FOLLOWED_USERS = [595112123,710713526,1695958922] # Array of twitter ID's to follow
TweetStream.configure do |config|
config.consumer_key = 'YOUR-CONSUMER-KEY'
config.consumer_secret = 'YOUR-CONSUMER-SECRET'
config.oauth_token = 'YOUR-OAUTH-TOKEN'
config.oauth_token_secret = 'YOUR-OAUTH-TOKEN-SECRET'
config.auth_method = :oauth
end
class MyHandler
include Cinch::Plugin
listen_to :tweet
def listen(m, tweet)
$stdout.puts "Sending tweet #{m}"
$stdout.puts "Tweet data: #{tweet.inspect}"
Channel('#f1').send tweet
end
end
class TwitterPlugin
def initialize(bot)
@bot = bot
end
def start
@client = TweetStream::Client.new
@client.on_limit do |skip_count|
$stdout.puts "Limit error, skip: #{skip_count}"
end
@client.on_enhance_your_calm do
$stdout.puts "Enhance your calm!"
end
@client.follow(FOLLOWED_USERS) do |status|
$stdout.puts "Handling tweet"
pp(status, $stdout)
unless status.retweet? || status.reply?
if FOLLOWED_USERS.include?(status.user.id)
@bot.handlers.dispatch(:tweet, nil, status.text)
end
end
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.synirc.net"
c.channels = ["#f1"]
c.nick = "F1PitRadio"
c.plugins.plugins = [MyHandler]
end
end
Thread.new { TwitterPlugin.new(bot).start }
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment