Class: ImageSearchPlugin

Inherits:
Campfire::PollingBot::Plugin show all
Defined in:
lib/campfire/polling_bot/plugins/image_search/image_search_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

#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


35
36
37
38
39
40
# File 'lib/campfire/polling_bot/plugins/image_search/image_search_plugin.rb', line 35

def help
  [
    ['(photo|image|picture) of <subject>', "find a new picture of <subject>"],
    ['search (google|flickr) for a (photo|image|picture) of <subject>', "search the stated service for a new picture of <subject>"]
  ]
end

#process(message) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/campfire/polling_bot/plugins/image_search/image_search_plugin.rb', line 9

def process(message)
  searched = false

  case message.command
  when /(google|flickr)\sfor\sa\s(?:photo|image|picture)\s+of:?\s+(?:a:?\s+)?\s*("?)(.*?)\1$/i
    subject = $3
    photo = next_photo(subject, $1)
    searched = true
  when /(?:photo|image|picture)\s+of:?\s+(?:a:?\s+)?\s*("?)(.*?)\1$/i
    subject = $2
    photo = next_photo(subject)
    searched = true
  end

  if searched
    if photo
      DisplayedImage.create(:uri => photo)
      bot.say(photo)
    else
      bot.say("Couldn't find anything for \"#{subject}\"")
    end
    return HALT
  end
end