Created
August 8, 2019 18:02
-
-
Save ryanlabouve/1d06bafa294025fe82a0865cf5b09358 to your computer and use it in GitHub Desktop.
OKC.rb Lita Bot Notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OKC.rb Lita Notes | |
slides: https://gifcannon.s3.us-west-2.amazonaws.com/ReplacingYourFriendsWithRobots.pdf | |
## 1. We can boot the bot | |
```rb | |
lita new briankobot-dr | |
cd briankobot | |
bundle | |
lita | |
``` | |
Inside Lita: | |
```rb | |
lita> lita info | |
lita> lita help | |
``` | |
Don't forget to commit! | |
```rb | |
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" | |
```rb | |
lita help | |
lita handler hello-world | |
cd lita-hello-world | |
``` | |
[https://docs.lita.io/plugin-authoring/](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! | |
```rb | |
... | |
route(/^ping/, :pong) | |
def pong(response) | |
response.reply("PONG") | |
end | |
... | |
``` | |
Basic test | |
[https://docs.lita.io/plugin-authoring/testing/#testing-routes](https://docs.lita.io/plugin-authoring/testing/#testing-routes) | |
```rb | |
context "When trying to PONG" do | |
it { is_expected.to route("ping").to(:pong) } | |
end | |
``` | |
Smore tests | |
```rb | |
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 | |
```rb | |
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](https://github.com/litaio/lita-slack) | |
```rb | |
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/nickpegg/lita-butt) | |
[https://github.com/killpack/lita-pugbomb](https://github.com/killpack/lita-pugbomb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment