Class: TwitterSearchPlugin

Inherits:
Campfire::PollingBot::Plugin show all
Defined in:
lib/campfire/polling_bot/plugins/twitter_search/twitter_search_plugin.rb

Overview

plugin to search twitter

Constant Summary

Constants inherited from Campfire::PollingBot::Plugin

Campfire::PollingBot::Plugin::HALT

Instance Attribute Summary

Attributes inherited from Campfire::PollingBot::Plugin

#bot, #config

Instance Method Summary collapse

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

#helpObject

return array of available commands and descriptions


25
26
27
28
29
30
# File 'lib/campfire/polling_bot/plugins/twitter_search/twitter_search_plugin.rb', line 25

def help
  [
    ["what are (people|is everyone) saying about <subject>", "search twitter for tweets on <subject>"],
    ["what's the word on <subject>", "search twitter for tweets on <subject>"],
  ]
end

#process(message) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/campfire/polling_bot/plugins/twitter_search/twitter_search_plugin.rb', line 8

def process(message)
  searched = false

  case message.command
  when /(?:(?:what(?:'s)? (?:(?:are )?people|(?:is |does )?every(?:one|body)) (?:saying|tweeting|think) about)|what's the word on)\s+(?:the )?(.*?)[.?!]?\s*$/i
    subject = $1
    tweets = search_twitter(subject)
    if tweets.any?
      tweets.each {|t| bot.tweet(t) }
    else
      bot.say("Couldn't find anything for \"#{subject}\"")
    end
    return HALT
  end
end