Module: Twibot::Macros
- Defined in:
- lib/twibot/macros.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after(event = :all, &blk) ⇒ Object
- #before(event = :all, &blk) ⇒ Object
- #configure(&blk) ⇒ Object
- #follower(&blk) ⇒ Object
- #hashtag(tag_or_tags, pattern = nil, options = {}, &blk) ⇒ Object (also: #hashtags)
- #message(pattern = nil, options = {}, &blk) ⇒ Object
- #post_reply(status, msg) ⇒ Object
- #post_tweet(msg) ⇒ Object
- #reply(pattern = nil, options = {}, &blk) ⇒ Object
- #run? ⇒ Boolean
- #search(query, pattern = nil, options = {}, &blk) ⇒ Object
- #tweet(pattern = nil, options = {}, &blk) ⇒ Object
- #twitter ⇒ Object (also: #client)
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:
33 34 35 36 |
# File 'lib/twibot/macros.rb', line 33 def hashtag(, pattern = nil, = {}, &blk) query = [].flatten.map {|ht| ht.to_s[0] == ?# ? ht.to_s : "##{ht}"}.join(" OR ") add_handler([:search, query], pattern, , &blk) end |
#message(pattern = nil, options = {}, &blk) ⇒ Object
17 18 19 |
# File 'lib/twibot/macros.rb', line 17 def (pattern = nil, = {}, &blk) add_handler(:message, pattern, , &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 = "@#{reply_to_screen_name} #{text}" puts client.status(:reply, { :status => , :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) = msg.respond_to?(:text) ? msg.text : msg puts client.status(:post, ) end |
#reply(pattern = nil, options = {}, &blk) ⇒ Object
21 22 23 |
# File 'lib/twibot/macros.rb', line 21 def reply(pattern = nil, = {}, &blk) add_handler(:reply, pattern, , &blk) end |
#run? ⇒ 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, = {}, &blk) add_handler([:search, query], pattern, , &blk) end |
#tweet(pattern = nil, options = {}, &blk) ⇒ Object
25 26 27 |
# File 'lib/twibot/macros.rb', line 25 def tweet(pattern = nil, = {}, &blk) add_handler(:tweet, pattern, , &blk) end |
#twitter ⇒ Object Also known as: client
51 52 53 |
# File 'lib/twibot/macros.rb', line 51 def twitter bot.twitter end |