Skip to content

Instantly share code, notes, and snippets.

@mattieb
Created May 15, 2014 02:43
Show Gist options
  • Save mattieb/98dcd9ae6c68bd660509 to your computer and use it in GitHub Desktop.
Save mattieb/98dcd9ae6c68bd660509 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'twitter_ebooks'
# This is an example bot definition with event handlers commented out
# You can define as many of these as you like; they will run simultaneously
Ebooks::Bot.new("zigg_ebooks") do |bot|
# Consumer details come from registering an app at https://dev.twitter.com/
# OAuth details can be fetched with https://github.com/marcel/twurl
bot.consumer_key = "NOPE" # Your app consumer key
bot.consumer_secret = "NOPE" # Your app consumer secret
bot.oauth_token = "NOPE-NOPE" # Token connecting the app to this account
bot.oauth_token_secret = "NOPE" # Secret connecting the app to this account
model = Ebooks::Model.load('model/zigg.model')
bot.on_message do |dm|
length = dm[:text].length
bot.reply(dm, model.make_response(dm[:text], 140-length))
end
bot.on_follow do |user|
bot.follow(user[:screen_name])
end
bot.on_mention do |tweet, meta|
next if tweet[:user][:screen_name].include?('ebooks') && rand > 0.05
next if rand < 0.05
length = tweet[:text].length + meta[:reply_prefix].length
response = model.make_response(tweet[:text], 140 - length)
bot.reply(tweet, meta[:reply_prefix] + response)
end
bot.on_timeline do |tweet, meta|
next if tweet[:retweeted_status] || tweet[:text].start_with?('RT')
next unless rand < 0.05
# Reply to a tweet in the bot's timeline
length = tweet[:text].length + meta[:reply_prefix].length
response = model.make_response(tweet[:text], 140 - length)
bot.reply(tweet, meta[:reply_prefix] + response)
end
bot.scheduler.every '1h' do
bot.tweet(model.make_statement(140))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment