Skip to content

Instantly share code, notes, and snippets.

@ryanlabouve
Created August 8, 2019 18:02
Show Gist options
  • Save ryanlabouve/be585ca9368131e1cb23dc8b17ecd2c3 to your computer and use it in GitHub Desktop.
Save ryanlabouve/be585ca9368131e1cb23dc8b17ecd2c3 to your computer and use it in GitHub Desktop.

OKC.rb Lita Notes

slides: https://gifcannon.s3.us-west-2.amazonaws.com/ReplacingYourFriendsWithRobots.pdf

1. We can boot the bot

lita new briankobot-dr
cd briankobot 
bundle
lita

Inside Lita:

lita> lita info
lita> lita help

Don't forget to commit!

git init
git add .
git commit -m "Checkpoint 1"
// you could do some fancy git submodule thing here

2. We can get the bot to say "ping" when we say "pong"

lita help
lita handler hello-world
cd lita-hello-world

https://docs.lita.io/plugin-authoring/

  • try to run
  • notice dumb issues in gemspec
  • Silly bundler version issue

Basic implementation

Inside the main lib file!

...
route(/^ping/, :pong)
def pong(response)
  response.reply("PONG")
end
...

Basic test

https://docs.lita.io/plugin-authoring/testing/#testing-routes

context "When trying to PONG" do
  it { is_expected.to route("ping").to(:pong) }
end

Smore tests

it { is_expected.to route("PING").to(:pong) }
it { is_expected.to route("Can I get a PING?").to(:pong) }

it "returns pong" do
  send_message("ping")
  expect(replies.last).to eq("PONG")
end

3. We can get a bot to hello world at us when mentioned directly

  module Lita
    module Handlers
      class OffAndOn < Handler
        route(/\s*down\s*/, :off_and_on, command: true)

        def off_and_on(response)
          response.reply("Have you tried turning it off and on again?")
        end

        Lita.register_handler(self)
      end
    end
  end

  describe Lita::Handlers::OffAndOn, lita_handler: true do
    context "something is down" do
      it { is_expected.not_to route("something something down something something").to(:off_and_on) }
      it { is_expected.to route("#{Lita.config.robot.name} something something down something something").to(:off_and_on) }
      it { is_expected.to route("#{Lita.config.robot.name} Heroku's down").to(:off_and_on) }

      it "asks you to turn it off an on again" do
        send_message("#{Lita.config.robot.name} Heroku's down")

        expect(replies.last).to eq("Have you tried turning it off and on again?")
      end
    end
  end

lita heroku's down

We can @ briankobot

change name in config and install the gems

    gem "lita-hello-world", path: "./lita-hello-world"
    gem "lita-off-and-on", path: "./lita-off-and-on"

This all works in slack

gem "lita-slack"

https://github.com/litaio/lita-slack

    Lita.configure do |config|
      config.robot.adapter = :slack
      config.adapters.slack.token = "boooop"
    end

External Commands

https://github.com/nickpegg/lita-butt

https://github.com/killpack/lita-pugbomb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment