cognition 2.0.8 → 2.1.3

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
- SHA1:
3
- metadata.gz: 32aec8b43747dc3d4e93dde52b11976060dee440
4
- data.tar.gz: 29694fbdf558c9599f7867d14985ccd05e50bce0
2
+ SHA256:
3
+ metadata.gz: b3b0f0c99709eaabea164fe5e9f7cd5022331b28f39f74024f2a5d52fdcd8b1d
4
+ data.tar.gz: ef2823646928bfdd3ff9e60e9b91e980181a08af2a445a919404ebba1709e43c
5
5
  SHA512:
6
- metadata.gz: f14281cbedf9470605b6fcf454b1f862c5f0e0a58297a0afa6e16f7279a04ffafdbfa71824a8963d6c0bd8ba900bbfc0c90513238c837107e3e6678886569e59
7
- data.tar.gz: b6bae92cad86c46c055d33ef13ca60f67f6159c8628d4710e195ae0f73e10db90510b5fada35a6d820c3aaaa313d4e3a200e95b3ecf172d39e1c23a2a1d3dc99
6
+ metadata.gz: 6f53ef31b1ec20592b7a23b45c492a598515fac294e442a4ce6f35e4d97fed345afd4e131fc63707c07dbe9f0a2024695b55608f21c345196c1489c61138fba0
7
+ data.tar.gz: 06230123d76191225a842b675d05f277399c1184758068fcd0357b23beef18208cd2f529e0247ceec72440d5ef8a1012e93c820136fce85ad0fee35e4833fcc2
data/README.md CHANGED
@@ -62,7 +62,9 @@ msg.reply("foo") # Posts 'content=foo' to http://foo.bar/baz
62
62
 
63
63
  ## Creating a Plugin
64
64
  Creating plugins is easy. Subclass `Cognition::Plugins::Base` and setup your
65
- matches and logic that should be run:
65
+ matches and logic that should be run. Your methods will be passed the `msg`
66
+ object and any `metadata` you've passed to the bot's `process` method. Here's
67
+ an example plugin:
66
68
  ```ruby
67
69
  class Hello < Cognition::Plugins::Base
68
70
  # Simple string based matcher. Must match *EXACTLY*
data/cognition.gemspec CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "httparty", "~> 0.8"
22
- spec.add_dependency "tilt", "~> 1.4"
21
+ spec.add_dependency "httparty", "~> 0.15"
22
+ spec.add_dependency "tilt", "~> 2.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
  spec.add_development_dependency "webmock", "~> 1.20"
28
- spec.add_development_dependency "haml", "~> 4.0"
28
+ spec.add_development_dependency "haml", "~> 5.0"
29
29
  end
data/lib/cognition/bot.rb CHANGED
@@ -45,7 +45,7 @@ module Cognition
45
45
  def process_msg(msg)
46
46
  response = false
47
47
  matchers.each do |matcher|
48
- if matcher.attempt(msg)
48
+ if matcher.attempt(msg) != false
49
49
  response = matcher.response
50
50
  break
51
51
  end
@@ -4,7 +4,7 @@ module Cognition
4
4
 
5
5
  def initialize(trigger, options = {}, &action)
6
6
  fail ArgumentError, "matcher must have a trigger" unless trigger
7
- fail ArgumentError, "matcher must have a action" unless action
7
+ fail ArgumentError, "matcher must have an action" unless action
8
8
  @trigger = trigger
9
9
  @help = options[:help] ||= {}
10
10
  @action = action
@@ -18,12 +18,13 @@ module Cognition
18
18
 
19
19
  def attempt(msg)
20
20
  return false unless matches?(msg)
21
-
22
21
  run(msg)
23
22
  end
24
23
 
25
24
  def run(msg)
26
- @response = action.call(msg, match_data)
25
+ @response = action.call(msg, match_data).to_s
26
+ rescue => e
27
+ @response = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
27
28
  end
28
29
 
29
30
  def matches?(msg)
@@ -1,7 +1,5 @@
1
- <table>
1
+ <ul>
2
2
  <% @help.each do |text| %>
3
- <tr>
4
- <td><%= CGI.escapeHTML(text) %></td>
5
- </tr>
3
+ <li><%= CGI.escapeHTML(text) %></li>
6
4
  <% end %>
7
- </table>
5
+ </ul>
@@ -19,7 +19,7 @@ module Cognition
19
19
  def help(msg, match_data = nil)
20
20
  type = msg.metadata[:type] ||= "text"
21
21
  if match_data[:command].nil? || match_data[:command].empty?
22
- @help = bot.help
22
+ @help = bot.help.sort
23
23
  else
24
24
  @help = bot.help.find_all { |text| text.match match_data[:command] }
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Cognition
2
- VERSION = "2.0.8"
2
+ VERSION = "2.1.3"
3
3
  end
@@ -7,7 +7,7 @@ class DefaultPluginTest < Minitest::Test
7
7
  end
8
8
 
9
9
  def test_returns_help
10
- help = "ping - Test if the endpoint is responding. Returns PONG.\nhelp - Lists all commands with help\nhelp <command> - Lists help for <command>"
10
+ help = "help - Lists all commands with help\nhelp <command> - Lists help for <command>\nping - Test if the endpoint is responding. Returns PONG."
11
11
  assert_equal help, @bot.process("help")
12
12
  end
13
13
 
data/test/test_matcher.rb CHANGED
@@ -74,8 +74,26 @@ class MatcherTest < Minitest::Test
74
74
  matcher_with_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, { help: { "hello" => "says hello" } }, &proc(&method(:dummy_method)))
75
75
  assert_equal ["hello - says hello"], matcher_with_help.help
76
76
  end
77
+
78
+ def test_raises_exception_when_command_fails
79
+ msg = Cognition::Message.new("boom")
80
+ matcher = Cognition::Matcher.new(/boom/, {}, &proc(&method(:blow_up)))
81
+ matcher.attempt(msg)
82
+ assert matcher.response.include? "ZeroDivisionError"
83
+ end
84
+
85
+ def test_empty_response_is_not_a_failure
86
+ msg = Cognition::Message.new("empty")
87
+ matcher = Cognition::Matcher.new(/empty/, {}, &proc {})
88
+ matcher.attempt(msg)
89
+ assert_equal "", matcher.response
90
+ end
77
91
  end
78
92
 
79
93
  def dummy_method(_, match_data)
80
94
  "Hello #{match_data['name']}"
81
95
  end
96
+
97
+ def blow_up(msg, match_data)
98
+ raise ZeroDivisionError, "divided by 0"
99
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cognition
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Anderson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '0.15'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: '0.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tilt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.4'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.4'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '4.0'
103
+ version: '5.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '4.0'
110
+ version: '5.0'
111
111
  description: Match text; run commands. Works great for building a chatbot!
112
112
  email:
113
113
  - andnat@gmail.com
@@ -153,7 +153,7 @@ homepage: https://github.com/basecamp/cognition
153
153
  licenses:
154
154
  - MIT
155
155
  metadata: {}
156
- post_install_message:
156
+ post_install_message:
157
157
  rdoc_options: []
158
158
  require_paths:
159
159
  - lib
@@ -168,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.5.1
173
- signing_key:
171
+ rubygems_version: 3.5.4
172
+ signing_key:
174
173
  specification_version: 4
175
174
  summary: A rules engine for running commands.
176
175
  test_files: