Class: CampfireBot::AbsenteeCamper::Plugin

Inherits:
Plugin
  • Object
show all
Includes:
Config, Notification
Defined in:
lib/campfire_bot/absentee_camper.rb

Instance Method Summary collapse

Methods included from Config

#plugin_config, #root_config

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



18
19
20
# File 'lib/campfire_bot/absentee_camper.rb', line 18

def initialize
  Logger.instance.log = bot.log
end

Instance Method Details

#role_call(msg) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/campfire_bot/absentee_camper.rb', line 22

def role_call(msg)
  room = msg[:room]

  body = msg['body']
  body.scan(/@\w+/).map(&:downcase).uniq.each do |mention|
    mentioned = mention[1..-1]
    if plugin_config['users'].keys.include? mentioned

      # If the user isn't in the room, fire off a notification
      unless room.users.map { |u| u['id'] }.include? user_id_from_config(mentioned)
        NotificationManager.new(msg, plugin_config['users'][mentioned]).send_notifications
        room.speak("[Notified #{mentioned}]")
      end
    end
  end
end