Sha256: c49fe5d2dd49b2feaddb7414272efb6986ce735e6673dfe8a3b6df7aa0306db4

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'rest-client'

module Lita
  module Handlers
    class KarotzActions < Handler

      def self.default_config(config)
        config.karot_kake_url = nil
      end

      MESSAGE_REGEX = /(karotz|k) message (.*)/i
      route(MESSAGE_REGEX, :message, command: true,
            help: { "karotz message <message>" => "Tell karotz what to say" }
      )
      route(/(karotz|k) ears/i, :ears, command: true,
            help: { "karotz ears" => "Move karotz ears" }
      )
      route(/(karotz|k) nyan/i, :nyan, command: true,
            help: { "karotz nyan" => "Play nyan cat *meow meow*" }
      )

      def message(response)
        message = response.message.body.match(MESSAGE_REGEX).captures[1]
        RestClient.post "#{karot_kake_url}/speak", { message: message }
      end

      def ears(response)
        RestClient.post "#{karot_kake_url}/ears", {}
      end

      def nyan(response)
        RestClient.post "#{karot_kake_url}/nyan", {}
      end

    private
      def karot_kake_url
        Lita.config.handlers.karotz_actions.karot_kake_url || raise('karot_kake_url not set')
      end
    end

    Lita.register_handler(KarotzActions)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lita-karotz_actions-0.0.2 lib/lita/handlers/karotz_actions.rb
lita-karotz_actions-0.0.1 lib/lita/handlers/karotz_actions.rb