Sha256: 87139cd93a36b6f346999a1fb6cb24a92d8e4f00e9f3f236c6680e8235495a94

Contents?: true

Size: 908 Bytes

Versions: 1

Compression:

Stored size: 908 Bytes

Contents

module Lita
  module Handlers
    class Whoami < Handler
      REDIS_KEY = 'lita-whoami'

      route(/^(\w+) is (.+)/, :assign_person, command: true, help: {
        "SOMEONE is SOMETHING" => "Tell everbot that someone is something."
      })

      route(/^who ?is (\w+)/, :describe_person, command: true, help: {
        "SOMEONE is SOMETHING" => "Tell everbot that someone is something."
      })

      def key_for_person name
        "#{REDIS_KEY}:#{name}"
      end

      def assign_person(chat)
        name, thing = chat.matches[0]

        redis.rpush key_for_person(name), thing

        chat.reply "Okay, #{name} is #{thing}!"
      end

      def describe_person(chat)
        name = chat.matches[0][0]

        descriptors = redis.lrange(key_for_person(name), 0, -1).uniq

        chat.reply "#{name} is #{descriptors.join ', '}"
      end

      Lita.register_handler(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-whoami-0.1.1 lib/lita/handlers/whoami.rb