Module: Twibot::Macros

Defined in:
lib/twibot/macros.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



9
10
11
# File 'lib/twibot/macros.rb', line 9

def self.included(mod)
  @@bot = nil
end

Instance Method Details

#after(event = :all, &blk) ⇒ Object



43
44
45
# File 'lib/twibot/macros.rb', line 43

def after(event=:all, &blk)
  add_hook :"after_#{event}", &blk
end

#before(event = :all, &blk) ⇒ Object



47
48
49
# File 'lib/twibot/macros.rb', line 47

def before(event=:all, &blk)
  add_hook :"before_#{event}", &blk
end

#configure(&blk) ⇒ Object



13
14
15
# File 'lib/twibot/macros.rb', line 13

def configure(&blk)
  bot.configure(&blk)
end

#follower(&blk) ⇒ Object



29
30
31
# File 'lib/twibot/macros.rb', line 29

def follower(&blk)
  add_handler(:follower, nil, {}, &blk)
end

#hashtag(tag_or_tags, pattern = nil, options = {}, &blk) ⇒ Object Also known as: hashtags



33
34
35
36
# File 'lib/twibot/macros.rb', line 33

def hashtag(tag_or_tags, pattern = nil, options = {}, &blk)
  query = [tag_or_tags].flatten.map {|ht| ht.to_s[0] == ?# ? ht.to_s : "##{ht}"}.join(" OR ")
  add_handler([:search, query], pattern, options, &blk)
end

#message(pattern = nil, options = {}, &blk) ⇒ Object



17
18
19
# File 'lib/twibot/macros.rb', line 17

def message(pattern = nil, options = {}, &blk)
  add_handler(:message, pattern, options, &blk)
end

#post_reply(status, msg) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/twibot/macros.rb', line 63

def post_reply(status, msg)
  text = msg.respond_to?(:text) ? msg.text : msg
  reply_to_screen_name = (status.user.present) ? status.user.screen_name : status.from_user
  reply_to_status_id = status.id
  message = "@#{reply_to_screen_name} #{text}"
  puts message
  client.status(:reply, { :status => message, :in_reply_to_status_id => reply_to_status_id })
end

#post_tweet(msg) ⇒ Object



57
58
59
60
61
# File 'lib/twibot/macros.rb', line 57

def post_tweet(msg)
  message = msg.respond_to?(:text) ? msg.text : msg
  puts message
  client.status(:post, message)
end

#reply(pattern = nil, options = {}, &blk) ⇒ Object



21
22
23
# File 'lib/twibot/macros.rb', line 21

def reply(pattern = nil, options = {}, &blk)
  add_handler(:reply, pattern, options, &blk)
end

#run?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/twibot/macros.rb', line 72

def run?
  !@@bot.nil?
end

#search(query, pattern = nil, options = {}, &blk) ⇒ Object



39
40
41
# File 'lib/twibot/macros.rb', line 39

def search(query, pattern = nil, options = {}, &blk)
  add_handler([:search, query], pattern, options, &blk)
end

#tweet(pattern = nil, options = {}, &blk) ⇒ Object



25
26
27
# File 'lib/twibot/macros.rb', line 25

def tweet(pattern = nil, options = {}, &blk)
  add_handler(:tweet, pattern, options, &blk)
end

#twitterObject Also known as: client



51
52
53
# File 'lib/twibot/macros.rb', line 51

def twitter
  bot.twitter
end