Skip to content

Instantly share code, notes, and snippets.

@sts10
Created December 23, 2014 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sts10/9f253ea19bbf49b622ed to your computer and use it in GitHub Desktop.
Save sts10/9f253ea19bbf49b622ed to your computer and use it in GitHub Desktop.
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
class MyBot < Ebooks::Bot
# Configuration here applies to all MyBots
attr_accessor :original, :model, :model_path
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 = '' # Your app consumer key
self.consumer_secret = '' # 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
load_model!
scheduler.every '24h' do
# Tweet something every 24 hours
# See https://github.com/jmettraux/rufus-scheduler
# tweet("hi")
# pictweet("hi", "cuteselfie.jpg")
end
scheduler.every '57m' do
statement = model.make_statement(140)
while statement.downcase.include?("buzz")
statement = model.make_statement(140)
end
tweet(statement)
end
# scheduler.every '5h' do
# ryan_reply = model.make_statement(110)
# tweet("@ryanvailbrown " + ryan_reply)
# 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)
# Reply to a mention
# reply(tweet, "oh hullo")
reply(tweet, model.make_statement(120))
end
def on_timeline(tweet)
# Reply to a tweet in the bot's timeline
# reply(tweet, "nice tweet")
end
private
def load_model!
return if @model
@model_path ||= "model/#{original}.model"
log "Loading model #{model_path}"
@model = Ebooks::Model.load(model_path)
end
end
# Make a MyBot and attach it to an account
MyBot.new("schlinkbot") do |bot|
bot.access_token = "" # Token connecting the app to this account
bot.access_token_secret = "" # Secret connecting the app to this account
bot.original = "sts10"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment