Skip to content

Instantly share code, notes, and snippets.

@makyo
Created February 13, 2015 21:56
Show Gist options
  • Save makyo/d96779d6c5c534d5701b to your computer and use it in GitHub Desktop.
Save makyo/d96779d6c5c534d5701b to your computer and use it in GitHub Desktop.
Makyo_Ebooks bots.rb
require 'twitter_ebooks'
# This is an example bot definition with event handlers commented out
# You can define and instantiate as many bots as you like
# Load the models generated by `ebooks consume-all all corpus/*`
$model = Ebooks::Model.load('model/all.model')
class MyBot < Ebooks::Bot
# Configuration here applies to all MyBots
def configure
# Consumer details come from registering an app at https://dev.twitter.com/
# Once you have consumer details, use "ebooks auth" for new access tokens
self.consumer_key = '<key here>' # Your app consumer key
self.consumer_secret = '<secret here>' # Your app consumer secret
# Users to block instead of interacting with
self.blacklist = ['tnietzschequote']
# Range in seconds to randomize delay when bot.delay is called
self.delay_range = 1..6
end
def on_startup
scheduler.every '2h' do
tweet($model.make_statement())
end
end
def on_message(dm)
# Reply to a DM
# reply(dm, "secret secrets")
end
def on_follow(user)
# Follow a user back
# follow(user.screen_name)
end
def on_mention(tweet)
favorite(tweet)
reply(tweet, $model.make_response(tweet.full_text, 100))
end
def on_timeline(tweet)
# Reply to a tweet in the bot's timeline
# reply(tweet, "nice tweet")
end
end
# Make a MyBot and attach it to an account
MyBot.new("makyo_ebooks") do |bot|
bot.access_token = "<token here>" # Token connecting the app to this account
bot.access_token_secret = "<secret here>" # Secret connecting the app to this account
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment