Git Product home page Git Product logo

ruboty-generator's Introduction

Ruboty::Gen::Readme

Generate Ruboty Handler + Actions plugin.

Gem Version Build Status

Ruboty is Chat bot framework. Ruby + Bot = Ruboty

โฌ‡๏ธ Installation

Add this line to your application's Gemfile:

gem 'ruboty-generator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruboty-generator

๐Ÿ“˜ Rubotygenerator

Setting File Parameters

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

๐Ÿ“œ Usage

init

generate Rubotygenerator template file.

$ ruboty-generator init
$ ls -1 | grep Rubotygenerator
Rubotygenerator

generate

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 hige"
end

command do |c|
  c.name "hige"
  c.pattern "hige\\z"
  c.description "output hige"
end

generate plugin with action

$ 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 hige'
      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

generate plugin without action

$ 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 hige'
      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

๐Ÿ‘ฌ Contributing ๐Ÿ‘ญ

  1. Fork it ( https://github.com/tbpgr/ruboty-generator/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

ruboty-generator's People

Contributors

tbpgr avatar

Watchers

kaiba avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.