ruboty-bomb

ruboty-bomb

rubotyのプラグイン手作り体験( ・ㅂ・)و ̑̑
理解のためrubotyプラグインジェネレータ使わないで手作業

gemのひな形作成

$ bundle gem ruboty-bomb

ハンドラとかアクション追加

$ cd ruboty-bomb
$ cat lib/ruboty/handlers/bomb.rb
require "ruboty/bomb/actions/bomb"

module Ruboty
  module Handlers
    class Bomb < Base
      on /bomb/, name: 'bomb', description: 'output booooom!!!'

      def bomb(message)
        Ruboty::Bomb::Actions::Bomb.new(message).call
      end
    end
  end
end

$ cat lib/ruboty/bomb/actions/bomb.rb
module Ruboty
  module Bomb
    module Actions
      class Bomb < Ruboty::Actions::Base
        def call
          message.reply('booooom!!!')
        end
      end
    end
  end
end

$ cat lib/ruboty/bomb.rb
require "ruboty/bomb/version"
require "ruboty"
require "ruboty/handlers/bomb"

ファイル構成はこんなん

$ tree
.
├── CODE_OF_CONDUCT.md
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│   ├── console
│   └── setup
├── lib
│   └── ruboty
│       ├── bomb
│       │   ├── actions
│       │   │   └── bomb.rb
│       │   └── version.rb
│       ├── bomb.rb
│       └── handlers
│           └── bomb.rb
├── ruboty-bomb.gemspec
└── spec
    ├── ruboty
    │   └── bomb_spec.rb
    └── spec_helper.rb

8 directories, 14 files

ruboty-bomb.gemspecspec.add_runtime_dependency "ruboty"追加しとく

ruboty側のGemfileはこんな感じ

$ cat Gemfile
# A sample Gemfile
source "https://rubygems.org"

gem "ruboty-cron"
gem "ruboty-google_image"
#gem "ruboty-redis"
#gem "ruboty-slack"
gem "ruboty-bomb", :path => "~/Desktop/ruboty-bomb"

bundle install(or update)してruboty-bombをインストール(or 更新)

動作確認

$ bundle exec ruboty
Type `exit` or `quit` to end the session.
> ruboty help
ruboty /add job "(?<schedule>.+?)" (?<body>.+)/ - Add a new cron job
ruboty /bomb/ - output booooom!!!
ruboty /delete job (?<id>\d+)/ - Delete a cron job
ruboty /image( me)? (?<keyword>.+)/ - Search image from Google
ruboty /list jobs\z/ - List all cron jobs
ruboty /help( me)?(?: (?<filter>.+))?\z/i - Show this help message
ruboty /ping\z/i - Return PONG to PING
ruboty /who am i\?/i - Answer who you are
> ruboty bomb
booooom!!!

ほんほん。あとはプラグインを適当に公開、Slackと連携させればチャット上でボムれる


https://github.com/Lorentzca/ruboty-bomb