Class: SMSPlugin

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

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



42
43
44
45
46
47
48
# File 'lib/campfire/polling_bot/plugins/sms/sms_plugin.rb', line 42

def help
  [['set my sms address to: <address>', "set your sms address"],
   ["set <person>'s sms address to", "set someone else's sms address"],
   ['(sms|text|txt) <person>: <message>', "send an sms message"],
   ["list sms addresses", "list all sms addresses"]
  ]
end

#process(message) ⇒ Object



6
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
# File 'lib/campfire/polling_bot/plugins/sms/sms_plugin.rb', line 6

def process(message)
  case message.command
  when /(?:set)?\s+my\s+sms\s+address\s*(?:is|to|:)\s*(.+)/i
    address = $1
    if address =~ /"mailto:(.*?)"/
      address = $1
    end
    update_sms_address(message.person, address)
    bot.say("OK, #{message.person}, I've set your SMS address to #{address}")
    return HALT
  when /(?:set)?\s+(\w+?)'s\s+sms\s+address\s*(?:is|to|:)\s*(.+)/i
    person = $1
    address = $2
    if address =~ /"mailto:(.*?)"/
      address = $1
    end
    update_sms_address(person, address)
    bot.say("OK, #{message.person}, I've set #{$1}'s SMS address to #{$2}")
    return HALT     
  when /list sms addresses/i
    if (settings = SMSSetting.all(:order => [:person])).any?
      bot.say("Here are the SMS addresses I have:")
      settings.each { |setting| bot.say("  #{setting.person} - #{setting.address}") }
    else
      bot.say("Sorry, I don't have any SMS addresses yet.")
    end
    return HALT
  when /(?:sms|text|txt)\s+([^\s:]+):?\s*(.*)/i
    if address = send_sms(message.person, $1, $2)
      bot.say("Sent an SMS to #{$1} at #{address}")
    end
    return HALT
  end
end