Class: Twitter::Tweet
- Inherits:
-
Object
- Object
- Twitter::Tweet
- Defined in:
- lib/twittbot/gem_ext/twitter/tweet.rb
Instance Method Summary collapse
-
#expanded_text ⇒ String
Returns the full expanded tweet (over 140 characters).
-
#favourite ⇒ Object
(also: #fav, #fave, #favorite)
Favourites a tweet.
-
#mentioned_users(reply_all = true, screen_name = $bot[:config][:screen_name]) ⇒ Array
Scans the tweet text for screen names.
-
#reply(tweet_text, options = {}) ⇒ Object
Creates a reply to this tweet.
-
#retweet ⇒ Object
(also: #rt)
Retweets this tweet.
Instance Method Details
#expanded_text ⇒ String
Returns the full expanded tweet (over 140 characters)
60 61 62 |
# File 'lib/twittbot/gem_ext/twitter/tweet.rb', line 60 def self.attrs.dig(:extended_tweet, :full_text) || full_text || text end |
#favourite ⇒ Object Also known as: fav, fave, favorite
Favourites a tweet
32 33 34 35 36 37 |
# File 'lib/twittbot/gem_ext/twitter/tweet.rb', line 32 def favourite return if $bot.nil? or $bot[:client].nil? $bot[:client].favorite self.id rescue Twitter::Error => e puts "caught Twitter error while favouriting: #{e.}" end |
#mentioned_users(reply_all = true, screen_name = $bot[:config][:screen_name]) ⇒ Array
Scans the tweet text for screen names.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/twittbot/gem_ext/twitter/tweet.rb', line 47 def mentioned_users(reply_all = true, screen_name = $bot[:config][:screen_name]) userlist = [ self.user.screen_name ] if reply_all self.text.scan /@([A-Za-z0-9_]{1,16})/ do |user_name| user_name = user_name[0] userlist << user_name unless userlist.include?(user_name) or screen_name == user_name end end userlist end |
#reply(tweet_text, options = {}) ⇒ Object
Creates a reply to this tweet.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/twittbot/gem_ext/twitter/tweet.rb', line 7 def reply(tweet_text, = {}) return if $bot.nil? or $bot[:client].nil? opts = { reply_all: false }.merge() mentions = self.mentioned_users(opts[:reply_all]) result = "@#{mentions.join(" @")} #{tweet_text}"[(0...140)] $bot[:client].update result, in_reply_to_status_id: self.id rescue Twitter::Error => e puts "caught Twitter error while replying: #{e.}" end |
#retweet ⇒ Object Also known as: rt
Retweets this tweet.
23 24 25 26 27 28 |
# File 'lib/twittbot/gem_ext/twitter/tweet.rb', line 23 def retweet return if $bot.nil? or $bot[:client].nil? $bot[:client].retweet self.id rescue Twitter::Error => e puts "caught Twitter error while retweeting: #{e.}" end |