Sha256: 5f20cbfd455770460d89ce9e3c695df537e66d30e283cf8ef6cd5d44b8a7c1b0

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

module Lita
  module Handlers
    # s/chatbot/chatbutt/
    class Butt < Handler
      # insert handler code here
      route(/^b(u*)tt(s?)/, :butt, help: { 'butt' => '(_)_)' })

      def butt(response)
        groups = response.matches.first
        width = groups.first.size
        butt = make_butt width

        if groups.last == 's'
          response.reply(escape([butt, butt].join(' ')))
        else
          response.reply(escape(butt))
        end
      end

      def make_butt(width = 1)
        bottom = '_' * width
        "(#{bottom})#{bottom})"
      end

      # Properly escape the butt for a given chat service
      def escape(butt, adapter = robot.config.robot.adapter)
        case adapter
        when :slack
          "`#{butt}`"
        else
          butt
        end
      end

      Lita.register_handler(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-butt-0.1.2 lib/lita/handlers/butt.rb