Some actual tests for the bot response logic
This commit is contained in:
parent
746d218896
commit
5bfaac99de
4 changed files with 276 additions and 135 deletions
|
@ -21,9 +21,9 @@ module Ebooks
|
||||||
@config[:consumer_key] = STDIN.gets.chomp
|
@config[:consumer_key] = STDIN.gets.chomp
|
||||||
print "Consumer secret: "
|
print "Consumer secret: "
|
||||||
@config[:consumer_secret] = STDIN.gets.chomp
|
@config[:consumer_secret] = STDIN.gets.chomp
|
||||||
print "Oauth token: "
|
print "Access token: "
|
||||||
@config[:oauth_token] = STDIN.gets.chomp
|
@config[:oauth_token] = STDIN.gets.chomp
|
||||||
print "Oauth secret: "
|
print "Access secret: "
|
||||||
@config[:oauth_token_secret] = STDIN.gets.chomp
|
@config[:oauth_token_secret] = STDIN.gets.chomp
|
||||||
|
|
||||||
File.open(CONFIG_PATH, 'w') do |f|
|
File.open(CONFIG_PATH, 'w') do |f|
|
||||||
|
@ -34,8 +34,8 @@ module Ebooks
|
||||||
Twitter::REST::Client.new do |config|
|
Twitter::REST::Client.new do |config|
|
||||||
config.consumer_key = @config[:consumer_key]
|
config.consumer_key = @config[:consumer_key]
|
||||||
config.consumer_secret = @config[:consumer_secret]
|
config.consumer_secret = @config[:consumer_secret]
|
||||||
config.oauth_token = @config[:oauth_token]
|
config.access_token = @config[:oauth_token]
|
||||||
config.oauth_token_secret = @config[:oauth_token_secret]
|
config.access_token_secret = @config[:oauth_token_secret]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,56 +4,70 @@ require 'twitter'
|
||||||
require 'rufus/scheduler'
|
require 'rufus/scheduler'
|
||||||
require 'eventmachine'
|
require 'eventmachine'
|
||||||
|
|
||||||
# Wrap SSLSocket so that readpartial yields the fiber instead of
|
module Ebooks
|
||||||
# blocking when there is no data
|
# Wrap SSLSocket so that readpartial yields the fiber instead of
|
||||||
#
|
# blocking when there is no data
|
||||||
# We hand this to the twitter library so we can select on the sockets
|
#
|
||||||
# and thus run multiple streams without them blocking
|
# We hand this to the twitter library so we can select on the sockets
|
||||||
class FiberSSLSocket
|
# and thus run multiple streams without them blocking
|
||||||
def initialize(*args)
|
class FiberSSLSocket
|
||||||
@socket = OpenSSL::SSL::SSLSocket.new(*args)
|
def initialize(*args)
|
||||||
end
|
@socket = OpenSSL::SSL::SSLSocket.new(*args)
|
||||||
|
|
||||||
def readpartial(maxlen)
|
|
||||||
data = ""
|
|
||||||
|
|
||||||
loop do
|
|
||||||
begin
|
|
||||||
data = @socket.read_nonblock(maxlen)
|
|
||||||
rescue IO::WaitReadable
|
|
||||||
end
|
|
||||||
break if data.length > 0
|
|
||||||
Fiber.yield(@socket)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
def readpartial(maxlen)
|
||||||
|
data = ""
|
||||||
|
|
||||||
|
loop do
|
||||||
|
begin
|
||||||
|
data = @socket.read_nonblock(maxlen)
|
||||||
|
rescue IO::WaitReadable
|
||||||
|
end
|
||||||
|
break if data.length > 0
|
||||||
|
Fiber.yield(@socket)
|
||||||
|
end
|
||||||
|
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_missing(m, *args)
|
||||||
|
@socket.send(m, *args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(m, *args)
|
# An EventMachine handler which resumes a fiber on incoming data
|
||||||
@socket.send(m, *args)
|
class FiberSocketHandler < EventMachine::Connection
|
||||||
end
|
def initialize(fiber)
|
||||||
end
|
@fiber = fiber
|
||||||
|
end
|
||||||
|
|
||||||
# An EventMachine handler which resumes a fiber on incoming data
|
def notify_readable
|
||||||
class FiberSocketHandler < EventMachine::Connection
|
@fiber.resume
|
||||||
def initialize(fiber)
|
end
|
||||||
@fiber = fiber
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_readable
|
class ConfigurationError < Exception
|
||||||
@fiber.resume
|
end
|
||||||
|
|
||||||
|
# UserInfo tracks some meta information for how much
|
||||||
|
# we've interacted with a user, and how much they've responded
|
||||||
|
class UserInfo
|
||||||
|
attr_accessor :times_bugged, :times_responded
|
||||||
|
def initialize
|
||||||
|
self.times_bugged = 0
|
||||||
|
self.times_responded = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module Ebooks
|
|
||||||
class Bot
|
class Bot
|
||||||
attr_accessor :consumer_key, :consumer_secret,
|
attr_accessor :consumer_key, :consumer_secret,
|
||||||
:oauth_token, :oauth_token_secret
|
:access_token, :access_token_secret
|
||||||
|
|
||||||
attr_accessor :username
|
|
||||||
|
|
||||||
attr_reader :twitter, :stream
|
attr_reader :twitter, :stream
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
attr_accessor :username, :delay_range, :blacklist
|
||||||
|
|
||||||
@@all = [] # List of all defined bots
|
@@all = [] # List of all defined bots
|
||||||
def self.all; @@all; end
|
def self.all; @@all; end
|
||||||
|
|
||||||
|
@ -61,114 +75,128 @@ module Ebooks
|
||||||
all.find { |bot| bot.username == name }
|
all.find { |bot| bot.username == name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(username, &b)
|
|
||||||
# Set defaults
|
|
||||||
@username = username
|
|
||||||
|
|
||||||
# Override with callback
|
|
||||||
b.call(self)
|
|
||||||
|
|
||||||
Bot.all.push(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
def log(*args)
|
def log(*args)
|
||||||
STDOUT.puts "@#{@username}: " + args.map(&:to_s).join(' ')
|
STDOUT.puts "@#{@username}: " + args.map(&:to_s).join(' ')
|
||||||
STDOUT.flush
|
STDOUT.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure
|
def initialize
|
||||||
|
@username ||= nil
|
||||||
|
@blacklist ||= []
|
||||||
|
@delay_range ||= 0
|
||||||
|
|
||||||
|
@users ||= {}
|
||||||
|
configure
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_client
|
||||||
@twitter = Twitter::REST::Client.new do |config|
|
@twitter = Twitter::REST::Client.new do |config|
|
||||||
config.consumer_key = @consumer_key
|
config.consumer_key = @consumer_key
|
||||||
config.consumer_secret = @consumer_secret
|
config.consumer_secret = @consumer_secret
|
||||||
config.access_token = @oauth_token
|
config.access_token = @access_token
|
||||||
config.access_token_secret = @oauth_token_secret
|
config.access_token_secret = @access_token_secret
|
||||||
end
|
end
|
||||||
|
|
||||||
needs_stream = [@on_follow, @on_message, @on_mention, @on_timeline].any? {|e| !e.nil?}
|
@stream = Twitter::Streaming::Client.new(
|
||||||
|
ssl_socket_class: FiberSSLSocket
|
||||||
|
) do |config|
|
||||||
|
config.consumer_key = @consumer_key
|
||||||
|
config.consumer_secret = @consumer_secret
|
||||||
|
config.access_token = @access_token
|
||||||
|
config.access_token_secret = @access_token_secret
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if needs_stream
|
# Calculate some meta information about a tweet relevant for replying
|
||||||
@stream = Twitter::Streaming::Client.new(
|
def calc_meta(ev)
|
||||||
ssl_socket_class: FiberSSLSocket
|
meta = {}
|
||||||
) do |config|
|
meta[:mentions] = ev.attrs[:entities][:user_mentions].map { |x| x[:screen_name] }
|
||||||
config.consumer_key = @consumer_key
|
|
||||||
config.consumer_secret = @consumer_secret
|
reply_mentions = meta[:mentions].reject { |m| m.downcase == @username.downcase }
|
||||||
config.access_token = @oauth_token
|
reply_mentions = [ev.user.screen_name] + reply_mentions
|
||||||
config.access_token_secret = @oauth_token_secret
|
|
||||||
|
# Don't reply to more than three users at a time
|
||||||
|
if reply_mentions.length > 3
|
||||||
|
log "Truncating reply_mentions to the first three users"
|
||||||
|
reply_mentions = reply_mentions[0..2]
|
||||||
|
end
|
||||||
|
|
||||||
|
meta[:reply_prefix] = reply_mentions.uniq.map { |m| '@'+m }.join(' ') + ' '
|
||||||
|
|
||||||
|
meta[:limit] = 140 - meta[:reply_prefix].length
|
||||||
|
meta
|
||||||
|
end
|
||||||
|
|
||||||
|
# Receive an event from the twitter stream
|
||||||
|
def receive_event(ev)
|
||||||
|
if ev.is_a? Array # Initial array sent on first connection
|
||||||
|
log "Online!"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if ev.is_a? Twitter::DirectMessage
|
||||||
|
return if ev.sender.screen_name == @username # Don't reply to self
|
||||||
|
log "DM from @#{ev.sender.screen_name}: #{ev.text}"
|
||||||
|
fire(:direct_message, ev)
|
||||||
|
|
||||||
|
elsif ev.respond_to?(:name) && ev.name == :follow
|
||||||
|
return if ev.source.screen_name == @username
|
||||||
|
log "Followed by #{ev.source.screen_name}"
|
||||||
|
fire(:follow, ev.source)
|
||||||
|
|
||||||
|
elsif ev.is_a? Twitter::Tweet
|
||||||
|
return unless ev.text # If it's not a text-containing tweet, ignore it
|
||||||
|
return if ev.user.screen_name == @username # Ignore our own tweets
|
||||||
|
|
||||||
|
meta = calc_meta(ev)
|
||||||
|
|
||||||
|
mless = ev.text
|
||||||
|
begin
|
||||||
|
ev.attrs[:entities][:user_mentions].reverse.each do |entity|
|
||||||
|
last = mless[entity[:indices][1]..-1]||''
|
||||||
|
mless = mless[0...entity[:indices][0]] + last.strip
|
||||||
|
end
|
||||||
|
rescue Exception
|
||||||
|
p ev.attrs[:entities][:user_mentions]
|
||||||
|
p ev.text
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
|
meta[:mentionless] = mless
|
||||||
|
|
||||||
|
# To check if this is a mention, ensure:
|
||||||
|
# - The tweet mentions list contains our username
|
||||||
|
# - The tweet is not being retweeted by somebody else
|
||||||
|
# - Or soft-retweeted by somebody else
|
||||||
|
if meta[:mentions].map(&:downcase).include?(@username.downcase) && !ev.retweeted_status? && !ev.text.start_with?('RT ')
|
||||||
|
log "Mention from @#{ev.user.screen_name}: #{ev.text}"
|
||||||
|
fire(:mention, ev, meta)
|
||||||
|
else
|
||||||
|
fire(:timeline, ev, meta)
|
||||||
|
end
|
||||||
|
elsif ev.is_a? Twitter::Streaming::DeletedTweet
|
||||||
|
# pass
|
||||||
|
else
|
||||||
|
log ev
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_stream
|
def start_stream
|
||||||
log "starting stream for #@username"
|
log "starting stream for #@username"
|
||||||
@stream.before_request do
|
|
||||||
log "Online!"
|
|
||||||
end
|
|
||||||
|
|
||||||
@stream.user do |ev|
|
@stream.user do |ev|
|
||||||
p ev
|
receive_event ev
|
||||||
|
|
||||||
if ev.is_a? Twitter::DirectMessage
|
|
||||||
next if ev.sender.screen_name == @username # Don't reply to self
|
|
||||||
log "DM from @#{ev.sender.screen_name}: #{ev.text}"
|
|
||||||
@on_message.call(ev) if @on_message
|
|
||||||
elsif ev.respond_to?(:name) && ev.name == :follow
|
|
||||||
next if ev.source.screen_name == @username
|
|
||||||
log "Followed by #{ev.source.screen_name}"
|
|
||||||
@on_follow.call(ev.source) if @on_follow
|
|
||||||
elsif ev.is_a? Twitter::Tweet
|
|
||||||
next unless ev.text # If it's not a text-containing tweet, ignore it
|
|
||||||
next if ev.user.screen_name == @username # Ignore our own tweets
|
|
||||||
|
|
||||||
meta = {}
|
|
||||||
mentions = ev.attrs[:entities][:user_mentions].map { |x| x[:screen_name] }
|
|
||||||
|
|
||||||
reply_mentions = mentions.reject { |m| m.downcase == @username.downcase }
|
|
||||||
reply_mentions = [ev.user.screen_name] + reply_mentions
|
|
||||||
|
|
||||||
meta[:reply_prefix] = reply_mentions.uniq.map { |m| '@'+m }.join(' ') + ' '
|
|
||||||
meta[:limit] = 140 - meta[:reply_prefix].length
|
|
||||||
|
|
||||||
mless = ev.text
|
|
||||||
begin
|
|
||||||
ev.attrs[:entities][:user_mentions].reverse.each do |entity|
|
|
||||||
last = mless[entity[:indices][1]..-1]||''
|
|
||||||
mless = mless[0...entity[:indices][0]] + last.strip
|
|
||||||
end
|
|
||||||
rescue Exception
|
|
||||||
p ev.attrs[:entities][:user_mentions]
|
|
||||||
p ev.text
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
meta[:mentionless] = mless
|
|
||||||
|
|
||||||
# To check if this is a mention, ensure:
|
|
||||||
# - The tweet mentions list contains our username
|
|
||||||
# - The tweet is not being retweeted by somebody else
|
|
||||||
# - Or soft-retweeted by somebody else
|
|
||||||
if mentions.map(&:downcase).include?(@username.downcase) && !ev.retweeted_status? && !ev.text.start_with?('RT ')
|
|
||||||
log "Mention from @#{ev.user.screen_name}: #{ev.text}"
|
|
||||||
@on_mention.call(ev, meta) if @on_mention
|
|
||||||
else
|
|
||||||
@on_timeline.call(ev, meta) if @on_timeline
|
|
||||||
end
|
|
||||||
else
|
|
||||||
log "Unsure how to handle event: ", ev
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Connects to tweetstream and opens event handlers for this bot
|
# Connects to tweetstream and opens event handlers for this bot
|
||||||
def start
|
def start
|
||||||
configure
|
# Sanity check
|
||||||
|
if @username.nil?
|
||||||
@on_startup.call if @on_startup
|
raise ConfigurationError, "bot.username cannot be nil"
|
||||||
|
|
||||||
if not @stream
|
|
||||||
log "not bothering with stream for #@username"
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
make_client
|
||||||
|
fire(:startup)
|
||||||
|
|
||||||
fiber = Fiber.new do
|
fiber = Fiber.new do
|
||||||
start_stream
|
start_stream
|
||||||
end
|
end
|
||||||
|
@ -179,35 +207,74 @@ module Ebooks
|
||||||
conn.notify_readable = true
|
conn.notify_readable = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fire an event
|
||||||
|
def fire(event, *args)
|
||||||
|
handler = "on_#{event}".to_sym
|
||||||
|
if respond_to? handler
|
||||||
|
self.send(handler, *args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Wrapper for EM.add_timer
|
# Wrapper for EM.add_timer
|
||||||
# Delays add a greater sense of humanity to bot behaviour
|
# Delays add a greater sense of humanity to bot behaviour
|
||||||
def delay(time, &b)
|
def delay(&b)
|
||||||
time = time.to_a.sample unless time.is_a? Integer
|
time = @delay.to_a.sample unless @delay.is_a? Integer
|
||||||
EM.add_timer(time, &b)
|
EM.add_timer(time, &b)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blacklisted?(username)
|
||||||
|
if @blacklist.include?(username)
|
||||||
|
log "Saw scary blacklisted user @#{username}"
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Reply to a tweet or a DM.
|
# Reply to a tweet or a DM.
|
||||||
# Applies configurable @reply_delay range
|
|
||||||
def reply(ev, text, opts={})
|
def reply(ev, text, opts={})
|
||||||
opts = opts.clone
|
opts = opts.clone
|
||||||
|
|
||||||
if ev.is_a? Twitter::DirectMessage
|
if ev.is_a? Twitter::DirectMessage
|
||||||
|
return if blacklisted?(ev.sender.screen_name)
|
||||||
log "Sending DM to @#{ev.sender.screen_name}: #{text}"
|
log "Sending DM to @#{ev.sender.screen_name}: #{text}"
|
||||||
@twitter.create_direct_message(ev.sender.screen_name, text, opts)
|
@twitter.create_direct_message(ev.sender.screen_name, text, opts)
|
||||||
elsif ev.is_a? Twitter::Tweet
|
elsif ev.is_a? Twitter::Tweet
|
||||||
|
meta = calc_meta(ev)
|
||||||
|
|
||||||
|
return if blacklisted?(ev.user.screen_name)
|
||||||
log "Replying to @#{ev.user.screen_name} with: #{text}"
|
log "Replying to @#{ev.user.screen_name} with: #{text}"
|
||||||
@twitter.update(text, in_reply_to_status_id: ev.id)
|
@twitter.update(meta[:reply_prefix] + text, in_reply_to_status_id: ev.id)
|
||||||
else
|
else
|
||||||
raise Exception("Don't know how to reply to a #{ev.class}")
|
raise Exception("Don't know how to reply to a #{ev.class}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def scheduler
|
def favorite(tweet)
|
||||||
@scheduler ||= Rufus::Scheduler.new
|
return if blacklisted?(tweet.user.screen_name)
|
||||||
|
log "Favoriting @#{tweet.user.screen_name}: #{tweet.text}"
|
||||||
|
|
||||||
|
begin
|
||||||
|
@twitter.favorite(tweet.id)
|
||||||
|
rescue Twitter::Error::Forbidden
|
||||||
|
log "Already favorited: #{tweet.user.screen_name}: #{tweet.text}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def retweet(tweet)
|
||||||
|
return if blacklisted?(tweet.user.screen_name)
|
||||||
|
log "Retweeting @#{tweet.user.screen_name}: #{tweet.text}"
|
||||||
|
|
||||||
|
begin
|
||||||
|
@twitter.retweet(tweet.id)
|
||||||
|
rescue Twitter::Error::Forbidden
|
||||||
|
log "Already retweeted: #{tweet.user.screen_name}: #{tweet.text}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(*args)
|
def follow(*args)
|
||||||
log "Following #{args}"
|
log "Following #{args}"
|
||||||
|
|
||||||
@twitter.follow(*args)
|
@twitter.follow(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -216,16 +283,14 @@ module Ebooks
|
||||||
@twitter.update(*args)
|
@twitter.update(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def scheduler
|
||||||
|
@scheduler ||= Rufus::Scheduler.new
|
||||||
|
end
|
||||||
|
|
||||||
# could easily just be *args however the separation keeps it clean.
|
# could easily just be *args however the separation keeps it clean.
|
||||||
def pictweet(txt, pic, *args)
|
def pictweet(txt, pic, *args)
|
||||||
log "Tweeting #{txt.inspect} - #{pic} #{args}"
|
log "Tweeting #{txt.inspect} - #{pic} #{args}"
|
||||||
@twitter.update_with_media(txt, File.new(pic), *args)
|
@twitter.update_with_media(txt, File.new(pic), *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_startup(&b); @on_startup = b; end
|
|
||||||
def on_follow(&b); @on_follow = b; end
|
|
||||||
def on_mention(&b); @on_mention = b; end
|
|
||||||
def on_timeline(&b); @on_timeline = b; end
|
|
||||||
def on_message(&b); @on_message = b; end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
75
spec/bot_spec.rb
Normal file
75
spec/bot_spec.rb
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'memory_profiler'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
|
def Process.rss; `ps -o rss= -p #{Process.pid}`.chomp.to_i; end
|
||||||
|
|
||||||
|
class TestBot < Ebooks::Bot
|
||||||
|
attr_accessor :twitter
|
||||||
|
|
||||||
|
def configure
|
||||||
|
self.username = "test_ebooks"
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_direct_message(dm)
|
||||||
|
reply dm, "echo: #{dm.text}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_mention(tweet, meta)
|
||||||
|
reply tweet, "echo: #{meta[:mentionless]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_timeline(tweet, meta)
|
||||||
|
reply tweet, "fine tweet good sir"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def twitter_id
|
||||||
|
533295311591337984
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_dm(username, text)
|
||||||
|
Twitter::DirectMessage.new(id: twitter_id,
|
||||||
|
sender: { id: twitter_id, screen_name: username},
|
||||||
|
text: text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_tweet(username, text)
|
||||||
|
mentions = text.split.find_all { |x| x.start_with?('@') }
|
||||||
|
Twitter::Tweet.new(
|
||||||
|
id: twitter_id,
|
||||||
|
user: { id: twitter_id, screen_name: username },
|
||||||
|
text: text,
|
||||||
|
entities: {
|
||||||
|
user_mentions: mentions.map { |m|
|
||||||
|
{ screen_name: m.split('@')[1],
|
||||||
|
indices: [text.index(m), text.index(m)+m.length] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Ebooks::Bot do
|
||||||
|
let(:bot) { TestBot.new }
|
||||||
|
|
||||||
|
it "responds to dms" do
|
||||||
|
bot.twitter = double("twitter")
|
||||||
|
expect(bot.twitter).to receive(:create_direct_message).with("m1sp", "echo: this is a dm", {})
|
||||||
|
bot.receive_event(mock_dm("m1sp", "this is a dm"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "responds to mentions" do
|
||||||
|
bot.twitter = double("twitter")
|
||||||
|
expect(bot.twitter).to receive(:update).with("@m1sp echo: this is a mention",
|
||||||
|
in_reply_to_status_id: twitter_id)
|
||||||
|
bot.receive_event(mock_tweet("m1sp", "@test_ebooks this is a mention"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "responds to timeline tweets" do
|
||||||
|
bot.twitter = double("twitter")
|
||||||
|
expect(bot.twitter).to receive(:update).with("@m1sp fine tweet good sir",
|
||||||
|
in_reply_to_status_id: twitter_id)
|
||||||
|
|
||||||
|
bot.receive_event(mock_tweet("m1sp", "some excellent tweet"))
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,12 +16,13 @@ Gem::Specification.new do |gem|
|
||||||
gem.version = Ebooks::VERSION
|
gem.version = Ebooks::VERSION
|
||||||
|
|
||||||
gem.add_development_dependency 'rspec'
|
gem.add_development_dependency 'rspec'
|
||||||
|
gem.add_development_dependency 'rspec-mocks'
|
||||||
gem.add_development_dependency 'memory_profiler'
|
gem.add_development_dependency 'memory_profiler'
|
||||||
gem.add_development_dependency 'pry-byebug'
|
gem.add_development_dependency 'pry-byebug'
|
||||||
|
|
||||||
gem.add_runtime_dependency 'twitter', '~> 5.0'
|
gem.add_runtime_dependency 'twitter', '~> 5.0'
|
||||||
gem.add_runtime_dependency 'simple_oauth', '~> 0.2.0'
|
gem.add_runtime_dependency 'simple_oauth', '~> 0.2.0'
|
||||||
gem.add_runtime_dependency 'tweetstream'
|
gem.add_runtime_dependency 'eventmachine', '~> 1.0.3'
|
||||||
gem.add_runtime_dependency 'rufus-scheduler'
|
gem.add_runtime_dependency 'rufus-scheduler'
|
||||||
gem.add_runtime_dependency 'gingerice'
|
gem.add_runtime_dependency 'gingerice'
|
||||||
gem.add_runtime_dependency 'htmlentities'
|
gem.add_runtime_dependency 'htmlentities'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue