Sha256: 6958bcc9bbc40aafe8b96134490726fa80aac6c2577c13cc04f22b93b176dc91

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

module Lita
  module Handlers
    # Event-related handlers
    class LockerEvents < Handler
      namespace 'Locker'

      include ::Locker::Label
      include ::Locker::Misc
      include ::Locker::Regex
      include ::Locker::Resource

      on :lock_attempt, :lock_attempt
      on :unlock_attempt, :unlock_attempt

      def lock_attempt(payload)
        label      = payload[:label]
        user       = Lita::User.find_by_id(payload[:user_id])
        request_id = payload[:request_id]

        return unless Label.exists?(label)
        l = Label.new(label)
        if l.lock!(user.id)
          robot.trigger(:lock_success, request_id: request_id)
        else
          robot.trigger(:lock_failure, request_id: request_id)
        end
      end

      def unlock_attempt(payload)
        label      = payload[:label]
        request_id = payload[:request_id]

        return unless Label.exists?(label)
        l = Label.new(label)
        if l.unlock!
          robot.trigger(:unlock_success, request_id: request_id)
        else
          robot.trigger(:unlock_failure, request_id: request_id)
        end
      end

      Lita.register_handler(LockerEvents)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lita-locker-1.0.10 lib/lita/handlers/locker_events.rb
lita-locker-1.0.9 lib/lita/handlers/locker_events.rb
lita-locker-1.0.8 lib/lita/handlers/locker_events.rb
lita-locker-1.0.7 lib/lita/handlers/locker_events.rb
lita-locker-1.0.6 lib/lita/handlers/locker_events.rb
lita-locker-1.0.5 lib/lita/handlers/locker_events.rb
lita-locker-1.0.4 lib/lita/handlers/locker_events.rb
lita-locker-1.0.3 lib/lita/handlers/locker_events.rb
lita-locker-1.0.2 lib/lita/handlers/locker_events.rb
lita-locker-1.0.1 lib/lita/handlers/locker_events.rb
lita-locker-1.0.0 lib/lita/handlers/locker_events.rb