Sha256: e4d9c3a30d18cf7c5b238a1d0d1f72de9409998f977c4c4a30cae7f28edd338c

Contents?: true

Size: 614 Bytes

Versions: 1

Compression:

Stored size: 614 Bytes

Contents

module Ruboty
  module Handlers
    class Mpush < Base
      NAMESPACE = "mpush"

      on /(?<body>.+)/, name: 'mpop', description: 'message pop'
      on /mpush (?<body>.+)/, name: 'mpush', description: 'message push'

      def mpush(message)
        create(message)
        message.reply 'ok'
      end

      def mpop(message)
        return if message[:body].start_with? 'mpush'
        rep = mstack.pop
        message.reply rep if rep
      end

      def mstack
        robot.brain.data[NAMESPACE] ||= []
      end

      def create(message)
        mstack.push message[:body]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruboty-mpush-0.0.0 lib/ruboty/handlers/mpush.rb