ellen 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1257d785b8002b44123966764bc1fe93e87f854c
4
- data.tar.gz: 94c83b8ab5999c51c3d4685824d345d58e2dce51
3
+ metadata.gz: f27816fa4aa7300a9b7c35b5827d5940c47088d6
4
+ data.tar.gz: 1cb192ad3cc6a7f8a29cc07f7907f2958be45077
5
5
  SHA512:
6
- metadata.gz: 8096e060eb4f008cfb5d4c5d71f185c4db34f33488d98e9d0608054b00420038b3c78e92c6e1f9d96b29865f7ff3c4e4502574b995dfff9c7752511c0de107a2
7
- data.tar.gz: 58a0ed4737904956f866ee1b6138cec656cdefe4f345ae9f349e4c08ad200b8b1686e540a1c5dd757295b978c2341fadf27ab25b7894c54912b6daa53376cc0d
6
+ metadata.gz: 5037d6dadd4f679ed7254fd262405367f933d5cb8aa4dbeb114658243d31a0f1e469d460646a5e8e5608ccc087499f3051bed40b928c1065972b7356fea60e40
7
+ data.tar.gz: 314db415e020045daee42765c201c5faad64a0163a2ad4874d235dcfb12b7896079a882d8da99566539e08a79065af349991c5509ecface10b87d632cf4f5fde
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.5
2
+ * Now Action can access to MatchData object via Message
3
+ * ENV["ROBOT_NAME"] or "ellen" is default name
4
+ * Robot only responds to mention unless :all option specified
5
+
1
6
  ## 0.0.4
2
7
  * Add --dotenv option to load .env before running
3
8
 
data/README.md CHANGED
@@ -4,22 +4,6 @@ A chatterbot framework, inspired by Hubot.
4
4
  ## Dependencies
5
5
  * Ruby 1.9.3+
6
6
 
7
- ## Usage
8
- ```sh
9
- $ gem install ellen # Install `ellen` gem to your local machine
10
- $ ellen --help # Show usage with --help
11
- Usage: ellen [options]
12
- -a, --adapter Take adapter name.
13
- --dotenv Load .env before running.
14
- -g, --generate Generate a new chatterbot with ./ellen/ directory if specified.
15
- -l, --load Load a ruby file before running.
16
- -h, --help Display this help message.
17
- $ ellen --generate # Generate your new chatterbot with ./ellen/ directory
18
- $ cd ellen # Change to ./ellen/
19
- $ vi Gemfile # Add your favorite plugin gems
20
- $ bundle exec ellen --adapter=shell # Run your chatterbot with specified adapter
21
- ```
22
-
23
7
  ## Adapter
24
8
  You can create your own favorite adapter from
25
9
  [Ellen::Adpaters::Base](https://github.com/r7kamura/ellen/blob/master/lib/ellen/adapters/base.rb)
@@ -44,3 +28,27 @@ gem "ellen-foo"
44
28
  gem "ellen-bar"
45
29
  gem "ellen-baz"
46
30
  ```
31
+
32
+ ## Config
33
+ Store config in envorinment variables.
34
+ They are easy to change between deploys without changing any code.
35
+ We recommend to put `.env` and run with `ellen --dotenv` option to manage them.
36
+
37
+ ## Deploy
38
+ Here is the smallest example to deploy a simple chatterbot to Heroku.
39
+
40
+ ```sh
41
+ $ gem install ellen
42
+ $ ellen --generate
43
+ $ cd ellen
44
+ $ echo 'gem "ellen-my_adapter"' >> Gemfile
45
+ $ echo 'bot: bundle exec ellen --adapter my_adapter' >> Procfile
46
+ $ bundle install
47
+ $ git init
48
+ $ git add .
49
+ $ git commit -m "Initial commit"
50
+ $ heroku create
51
+ $ heroku scale bot=1
52
+ $ heroku config:set FOO=1 BAR=2 BAZ=3
53
+ $ git push heroku master
54
+ ```
data/lib/ellen/action.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ellen
2
2
  class Action
3
- attr_reader :pattern, :options, :block
3
+ attr_reader :block, :options, :pattern
4
4
 
5
5
  def initialize(pattern, options = {}, &block)
6
6
  @pattern = pattern
@@ -9,7 +9,21 @@ module Ellen
9
9
  end
10
10
 
11
11
  def call(handler, message)
12
- handler.robot.instance_exec(message, &block) if message.match(pattern, options)
12
+ handler.robot.instance_exec(message, &block) if message.match pattern_with(handler.robot.name)
13
+ end
14
+
15
+ def all?
16
+ !!options[:all]
17
+ end
18
+
19
+ private
20
+
21
+ def pattern_with(name)
22
+ if all?
23
+ /\A#{pattern}/
24
+ else
25
+ /\A@?#{Regexp.escape(name)}\s*#{pattern}/
26
+ end
13
27
  end
14
28
  end
15
29
  end
@@ -3,8 +3,9 @@
3
3
  # Example:
4
4
  #
5
5
  # class MyHandler < Ellen::Handlers::Base
6
- # def call(message)
7
- # ... do your work ...
6
+ # on /kill\z/, command: true do |message|
7
+ # say "Good bye, cruel world..."
8
+ # exit
8
9
  # end
9
10
  # end
10
11
  #
@@ -1,8 +1,8 @@
1
1
  module Ellen
2
2
  module Handlers
3
3
  class Help < Base
4
- on /help\z/, command: true do |message|
5
- say "You'll be okay", destination: message.source
4
+ on /help\z/ do |message|
5
+ say "You'll be okay"
6
6
  end
7
7
  end
8
8
  end
data/lib/ellen/message.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ellen
2
2
  class Message
3
- attr_reader :body, :source, :command
3
+ attr_reader :body, :command, :match_data, :source
4
4
 
5
5
  def initialize(options)
6
6
  @body = options[:body]
@@ -8,8 +8,12 @@ module Ellen
8
8
  @command = options[:command]
9
9
  end
10
10
 
11
- def match(pattern, options = {})
12
- (!options[:command] || command) && pattern === body
11
+ def match(pattern)
12
+ @match_data = pattern.match(body)
13
+ end
14
+
15
+ def [](index)
16
+ match_data[index]
13
17
  end
14
18
  end
15
19
  end
data/lib/ellen/robot.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Ellen
2
2
  class Robot
3
+ DEFAULT_ROBOT_NAME = "ellen"
4
+
3
5
  include Mem
4
6
 
5
7
  delegate :say, to: :adapter
@@ -25,6 +27,10 @@ module Ellen
25
27
  end
26
28
  end
27
29
 
30
+ def name
31
+ ENV["ROBOT_NAME"] || DEFAULT_ROBOT_NAME
32
+ end
33
+
28
34
  private
29
35
 
30
36
  def adapt
data/lib/ellen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ellen
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-13 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport