Class: GreetingPlugin

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

Overview

Plugin to greet people when they enter, provide a catch-up url, and notify them of any “future” messages requires the HistoryPlugin

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



43
44
45
46
47
48
49
# File 'lib/campfire/polling_bot/plugins/greeting/greeting_plugin.rb', line 43

def help
  [['(disable|turn off) greetings', "don't say hi when you log in (you grump)"],
   ['(enable|turn on) greetings', "say hi when you log in"],
   ['toggle greetings', "disable greetings if enabled, enable if disabled. You know--toggle."],
   ['catch me up|ketchup', "gives you a link to the point in the transcript where you last logged out"]
  ]
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
# File 'lib/campfire/polling_bot/plugins/greeting/greeting_plugin.rb', line 7

def process(message)
  user = message.user
  wants_greeting = wants_greeting?(user)
  if message.kind_of?(Campfire::EnterMessage)
    link = catch_up_link(message.person_full_name)
    futures = future_messages(message.person_full_name, message.person)
    if wants_greeting && link
      bot.say("Hey #{message.person.downcase}. Catch up: #{link}")
    end
    futures.each{|m| bot.say(m) }
  elsif message.kind_of?(Campfire::TextMessage)
    case message.command
    when /(disable|turn off) greetings/i
      wants_greeting(user, false)
      bot.say("OK, I've disabled greetings for you, #{message.person}")
      return HALT
    when /(enable|turn on) greetings/i        
      wants_greeting(user, true)
      bot.say("OK, I've enabled greetings for you, #{message.person}")
      return HALT
    when /toggle greetings/i
      old_setting = wants_greeting?(user)
      wants_greeting(user, !old_setting)
      bot.say("OK, I've #{old_setting ? 'disabled' : 'enabled'} greetings for you, #{message.person}")
      return HALT
    when /catch me up|ketchup/i
      if link = catch_up_link(message.person_full_name, true)
        bot.say("Here you go, #{message.person}: #{link}")
      else
        bot.say("Hmm...couldn't find when you last logged out, #{message.person}")
      end
      return HALT
    end
  end
end