Class: TweetPlugin
- Inherits:
-
Campfire::PollingBot::Plugin
- Object
- Campfire::PollingBot::Plugin
- TweetPlugin
- Defined in:
- lib/campfire/polling_bot/plugins/tweet/tweet_plugin.rb
Overview
plugin to send a tweet to a Twitter account
Constant Summary
Constants inherited from Campfire::PollingBot::Plugin
Campfire::PollingBot::Plugin::HALT
Instance Attribute Summary
Attributes inherited from Campfire::PollingBot::Plugin
Instance Method Summary collapse
-
#help ⇒ Object
return array of available commands and descriptions.
- #process(message) ⇒ Object
Methods inherited from Campfire::PollingBot::Plugin
accepts, #accepts?, accepts?, bot, bot=, directory, directory=, inherited, #initialize, load_all, load_plugin_classes, #logger, logger, priority, #priority, requires_config, requires_config?, #requires_config?, setup_database, subclasses, #to_s
Constructor Details
This class inherits a constructor from Campfire::PollingBot::Plugin
Instance Method Details
#help ⇒ Object
return array of available commands and descriptions
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/campfire/polling_bot/plugins/tweet/tweet_plugin.rb', line 57 def help user = username || 'the configured user' [['tweet: <message>', "post <message> to #{user}'s twitter account"], ['save tweet: <message>', "save <message> for later"], ['show tweets', "shows the queued tweets for #{user}'s twitter account"], ['show next tweet', "shows the oldest queued twitter message"], ['post next tweet', "sends the oldest queued twitter message"], ['post tweet <n>', "sends the <n>th tweet from the list"], ['delete tweet <n>', "deletes the <n>th tweet from the list"]] end |
#process(message) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/campfire/polling_bot/plugins/tweet/tweet_plugin.rb', line 7 def process() case .command when /^(?:tweet|twitter):?\s*("?)(.*?)\1$/i begin text = strip_links($2) post_tweet(text) rescue TwitterError => ex bot.say("Hmm...didn't work. Got this response:") bot.paste(ex.http_result.content) end return HALT when /^(?:save|queue)\s+(?:tweet|twitter):?\s*("?)(.*?)\1$/i tweet = Tweet.create(:person => .person, :message => strip_links($2), :timestamp => ..to_i) bot.say("Ok, saved for later: #{tweet}") return HALT when /^(?:show|list)\s+(?:all\s+)?(?:queued\s+)?(?:tweets|twitters)$/i act_on_list do |list| bot.say("Here are the tweets in the queue:") i = 0 bot.paste(list.map{|tweet| "#{i+=1}. #{tweet}"}.join("\n")) end return HALT when /^show\s+next\s+(?:tweet|twitter)$/i act_on_list do |list| bot.say("Next tweet to post: #{list.first}") end return HALT when /^(?:post|send)\s+next\s+(?:tweet|twitter)$/i act_on_list do |list| tweet = list.first post_tweet(tweet) tweet.destroy end return HALT when /^(?:post|send)\s+tweet\s+(\d+)$/i act_on_tweet($1.to_i-1) do |tweet| post_tweet(tweet) tweet.destroy end return HALT when /^delete\s+tweet\s+(\d+)$/i act_on_tweet($1.to_i-1) do |tweet| tweet.destroy bot.say("Okay, deleted tweet #{$1}: #{tweet}") end return HALT end end |