Skip to content

Instantly share code, notes, and snippets.

@aereal
Created August 26, 2010 14:15
Show Gist options
  • Select an option

  • Save aereal/551455 to your computer and use it in GitHub Desktop.

Select an option

Save aereal/551455 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$: << File.expand_path('~/src/net-irc/lib')
require 'net/irc'
class Bot < Net::IRC::Client
include Net::IRC::Constants
def on_rpl_welcome(m)
post JOIN, '#twitter@tig'
end
def on_connected
@latest_tweeted = Time.now
end
def on_message(m)
automated_tweet(m)
end
private
def automated_tweet(received)
(Time.now - @latest_tweeted) > 60 * (10 + rand(5)) && tweet(random_message)
end
def tweet(message)
post PRIVMSG, '#twitter@tig', message
@latest_tweeted = Time.now
end
def random_message
@tweet_stack.__send__([].respond_to?(:sample) ? :sample : :choice)
end
def tweet_stack
read_pattern.split(/\n+/)
end
def read_pattern
path = (ENV['HOME'] || '~aereal') + '/tweet_stack'
path = File.expand_path(path)
File.read(path)
end
end
Bot.new('localhost', '6667', {
:user => 'aereal',
:nick => 'aereal',
:real => 'aereal',
}).start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment