Generate Ruboty Handler + Actions plugin.
Ruboty is Chat bot framework. Ruby + Bot = Ruboty
Add this line to your application's Gemfile:
gem 'ruboty-generator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ruboty-generator
key | value | example |
---|---|---|
user_name | github user name | tbpgr |
gem_class_name | gem class name | Hoge |
gem_name | gem name | hoge |
description | description | An Ruboty Handler + Actions to output hige. |
env/name | ENV variable name | DEFAULT_HOGE_TEXT |
env/description | ENV description | default hoge text |
commands/command name | Ruboty::Handler.on name | hoge |
commands/command pattern | Ruboty::Handler.on pattern | /hoge\z/ |
commands/command description | Ruboty::Handler.on description | output hige |
generate Rubotygenerator template file.
$ ruboty-generator init
$ ls -1 | grep Rubotygenerator
Rubotygenerator
generate Ruboty Handler + Action template
- edit Rubotygenerator file
# encoding: utf-8
user_name "tbpgr"
gem_class_name "Hoge"
gem_name "hoge"
description "An Ruboty Handler + Actions to hoge-hige"
env do |e|
e.name "DEFAULT_HOGE_TEXT1"
e.description "DEFAULT_HOGE_TEXT1 desc"
end
env do |e|
e.name "DEFAULT_HOGE_TEXT2"
e.description "DEFAULT_HOGE_TEXT2 desc"
end
command do |c|
c.name "hoge"
c.pattern "hoge\\z"
c.description "output hoge"
end
command do |c|
c.name "hige"
c.pattern "hige\\z"
c.description "output hige"
end
$ ruboty-generator generate -a
- output
.
└── ruboty-hoge
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│ ├── console
│ └── setup
├── lib
│ └── ruboty
│ ├── handlers
│ │ └── hoge.rb
│ ├── hoge
│ │ ├── actions
│ │ │ ├── hige.rb
│ │ │ └── hoge.rb
│ │ └── version.rb
│ └── hoge.rb
└── ruboty-hoge.gemspec
- check generated handler
require "ruboty/hoge/actions/hoge"
require "ruboty/hoge/actions/hige"
module Ruboty
module Handlers
# An Ruboty Handler + Actions to hoge-hige
class Hoge < Base
on /hoge\z/, name: 'hoge', description: 'output hoge'
on /hige\z/, name: 'hige', description: 'output hige'
env :DEFAULT_HOGE_TEXT1, "DEFAULT_HOGE_TEXT1 desc"
env :DEFAULT_HOGE_TEXT2, "DEFAULT_HOGE_TEXT2 desc"
def hoge(message)
Ruboty::Hoge::Actions::Hoge.new(message).call
end
def hige(message)
Ruboty::Hoge::Actions::Hige.new(message).call
end
end
end
end
- check generated action
hoge.rb
module Ruboty
module Hoge
module Actions
class Hoge < Ruboty::Actions::Base
def call
message.reply(hoge)
rescue => e
message.reply(e.message)
end
private
def hoge
# TODO: main logic
end
end
end
end
end
hige.rb
module Ruboty
module Hoge
module Actions
class Hige < Ruboty::Actions::Base
def call
message.reply(hige)
rescue => e
message.reply(e.message)
end
private
def hige
# TODO: main logic
end
end
end
end
end
$ ruboty-generator generate
- output
.
└── ruboty-hoge
├── Gemfile
├── README.md
├── Rakefile
├── bin
│ ├── console
│ └── setup
├── lib
│ └── ruboty
│ ├── handlers
│ │ └── hoge.rb
│ ├── hoge
│ │ └── version.rb
│ └── hoge.rb
└── ruboty-hoge.gemspec
- check generated handler
module Ruboty
module Handlers
# An Ruboty Handler + Actions to hoge-hige
class Hoge < Base
on /hoge\z/, name: 'hoge', description: 'output hoge'
on /hige\z/, name: 'hige', description: 'output hige'
env :DEFAULT_HOGE_TEXT1, "DEFAULT_HOGE_TEXT1 desc"
env :DEFAULT_HOGE_TEXT2, "DEFAULT_HOGE_TEXT2 desc"
def hoge(message)
# TODO: implement your action
end
def hige(message)
# TODO: implement your action
end
end
end
end
- Fork it ( https://github.com/tbpgr/ruboty-generator/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request