botkit 0.0.0 → 0.0.1

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: 73e5a8a7c044af180f0481945c11201c5e591c1c
4
- data.tar.gz: 76423a8943d97de8c626b43ce0d6c765d263c0c6
3
+ metadata.gz: 5b00abfa24e03a260c60bd3543f02c2956d6395d
4
+ data.tar.gz: 78ad1d3fc8b22654db3593156386519322947bc2
5
5
  SHA512:
6
- metadata.gz: 3328ca6512d7a8b0981c30716f17c582ee3b4b2a93f87db5e5d563c977c8ba349c64233d0ba2a45f7b0579ada1531936912b672373b19dfec0d17a0a288a8d5c
7
- data.tar.gz: ede718d33abc2c9351bc0d7993a797ca636391d5edd39d82a2fbe4fda95d0cfa6c2a389ab4cd00a9f6d2957f3fddb8ff8fe1dd422b7c29bc7356db2a39375b01
6
+ metadata.gz: e29a2fbbb1b2f05ef552781bde751590527206445f98da851bd818bc7fed9eed836452f7dab325b69df184cfd7b1264b62900864db8fea80734383e3da0e69ab
7
+ data.tar.gz: 441dd448f09aaaaee8e1b2e4606a8ced8150c41f7309c954c56acfd20473079027e99f045fce4be342b395518c9484144810b3be6c7b1828b8fd156f081b35b0
@@ -0,0 +1,116 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/Alias:
5
+ EnforcedStyle: prefer_alias_method
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ EnforcedStyle: always
9
+
10
+ Style/ClassCheck:
11
+ EnforcedStyle: kind_of?
12
+
13
+ Metrics/LineLength:
14
+ Max: 80
15
+
16
+ Style/BlockDelimiters:
17
+ Enabled: false
18
+
19
+ Style/RegexpLiteral:
20
+ Enabled: false
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+
25
+ Style/PerlBackrefs:
26
+ Enabled: false
27
+
28
+ ClassLength:
29
+ Enabled: false
30
+
31
+ CyclomaticComplexity:
32
+ Enabled: false
33
+
34
+ Documentation:
35
+ Enabled: false
36
+
37
+ Encoding:
38
+ Enabled: false
39
+
40
+ FileName:
41
+ Enabled: false
42
+
43
+ IfUnlessModifier:
44
+ Enabled: false
45
+
46
+ MethodLength:
47
+ Enabled: false
48
+
49
+ ModuleFunction:
50
+ Enabled: false
51
+
52
+ OneLineConditional:
53
+ Enabled: false
54
+
55
+ ParameterLists:
56
+ Enabled: false
57
+
58
+ Proc:
59
+ Enabled: false
60
+
61
+ SingleLineBlockParams:
62
+ Enabled: false
63
+
64
+ VariableInterpolation:
65
+ Enabled: false
66
+
67
+ Style/TrailingCommaInLiteral:
68
+ Enabled: false
69
+
70
+ WhileUntilModifier:
71
+ Enabled: false
72
+
73
+ PredicateName:
74
+ NamePrefixBlacklist:
75
+ - is_
76
+
77
+ StringLiterals:
78
+ EnforcedStyle: double_quotes
79
+
80
+ DotPosition:
81
+ EnforcedStyle: leading
82
+
83
+ SpaceBeforeBlockBraces:
84
+ EnforcedStyle: space
85
+
86
+ SpaceInsideBlockBraces:
87
+ EnforcedStyle: no_space
88
+
89
+ DoubleNegation:
90
+ Enabled: false
91
+
92
+ SpaceInsideBlockBraces:
93
+ SpaceBeforeBlockParameters: false
94
+
95
+ SpaceInsideHashLiteralBraces:
96
+ Enabled: false
97
+
98
+ PercentLiteralDelimiters:
99
+ PreferredDelimiters:
100
+ '%': '{}'
101
+ '%i': '{}'
102
+ '%q': '{}'
103
+ '%Q': '{}'
104
+ '%r': '{}'
105
+ '%s': '{}'
106
+ '%w': '{}'
107
+ '%W': '{}'
108
+ '%x': '{}'
109
+
110
+ Style/CollectionMethods:
111
+ PreferredMethods:
112
+ collect: 'map'
113
+ collect!: 'map!'
114
+ inject: 'reduce'
115
+ detect: 'find'
116
+ find_all: 'select'
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ botkit (0.0.1)
5
+ aitch
6
+ signal
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aitch (1.0.2)
12
+ nokogiri (>= 1.6.0)
13
+ docile (1.1.5)
14
+ json (2.1.0)
15
+ metaclass (0.0.4)
16
+ mini_portile2 (2.3.0)
17
+ minitest (5.10.3)
18
+ minitest-utils (0.4.0)
19
+ minitest
20
+ mocha (1.3.0)
21
+ metaclass (~> 0.0.1)
22
+ nokogiri (1.8.1)
23
+ mini_portile2 (~> 2.3.0)
24
+ rake (12.2.1)
25
+ signal (1.1.0)
26
+ simplecov (0.15.1)
27
+ docile (~> 1.1.0)
28
+ json (>= 1.8, < 3)
29
+ simplecov-html (~> 0.10.0)
30
+ simplecov-html (0.10.2)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ botkit!
37
+ bundler
38
+ minitest-utils
39
+ mocha
40
+ rake
41
+ simplecov
42
+
43
+ BUNDLED WITH
44
+ 1.16.0
@@ -20,7 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
+ spec.add_dependency "aitch"
24
+ spec.add_dependency "signal"
25
+
23
26
  spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "minitest-utils"
28
+ spec.add_development_dependency "mocha"
25
29
  spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "simplecov"
26
31
  end
@@ -1,6 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "botkit/version"
4
-
5
3
  module Botkit
4
+ require "aitch"
5
+ require "signal"
6
+
7
+ require "botkit/version"
8
+ require "botkit/runner"
9
+ require "botkit/message"
10
+ require "botkit/bot"
11
+
12
+ def self.run(bot, **kwargs)
13
+ Runner.new(bot, **kwargs).call
14
+ end
6
15
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Botkit
4
+ class Bot
5
+ include Signal
6
+
7
+ # When setting `bot.halt = true`, the bot will be halted
8
+ # after the current loop.
9
+ attr_writer :halt
10
+
11
+ # Detect if bot should halt himself from the loop.
12
+ def halt?
13
+ @halt
14
+ end
15
+
16
+ def call
17
+ end
18
+
19
+ def send_message(message)
20
+ end
21
+
22
+ def reply_message(_message, reply)
23
+ send_message(reply)
24
+ end
25
+
26
+ def handle_incoming_message(message)
27
+ if message.command?
28
+ emit("command:#{message.command}", message)
29
+ else
30
+ emit("internal:message", message)
31
+ end
32
+ end
33
+
34
+ def parse_message(input, matcher = nil)
35
+ input = input.to_s
36
+ _, command, text = *input.match(%r{\A/([^ ]+)(?:\s+(.*?))\z})
37
+ matches = text.to_s.match(matcher) if matcher
38
+
39
+ {
40
+ command: command,
41
+ text: text || input,
42
+ matches: matches&.named_captures
43
+ }
44
+ end
45
+
46
+ def command(name, &block)
47
+ on("command:#{name}", &block)
48
+ end
49
+
50
+ def message(&block)
51
+ on("internal:message", &block)
52
+ end
53
+
54
+ def exception(&block)
55
+ on("internal:exception", &block)
56
+ end
57
+
58
+ def report_exception(exception)
59
+ emit("internal:exception", exception)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Botkit
4
+ class Message
5
+ attr_reader :text, :command, :matches, :raw, :options, :channel_id
6
+
7
+ def initialize(text:, raw: {}, channel_id: nil, command: nil, matches: nil, options: {})
8
+ @text = text
9
+ @command = command
10
+ @raw = raw
11
+ @channel_id = channel_id
12
+ @options = options
13
+ @matches = matches
14
+ end
15
+
16
+ def command?
17
+ command
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Botkit
4
+ class Runner
5
+ attr_reader :bot, :polling
6
+
7
+ def initialize(bot, polling: 1)
8
+ @bot = bot
9
+ @polling = polling
10
+ end
11
+
12
+ def call
13
+ loop do
14
+ next_tick
15
+ break if bot.halt?
16
+ sleep(polling)
17
+ end
18
+ end
19
+
20
+ private def next_tick
21
+ bot.call
22
+ rescue StandardError => exception
23
+ bot.report_exception(exception)
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Botkit
4
- VERSION = "0.0.0"
4
+ VERSION = "0.0.1"
5
5
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aitch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: signal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +53,21 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: minitest
56
+ name: minitest-utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - ">="
@@ -52,6 +94,20 @@ dependencies:
52
94
  - - ">="
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description: A simple chatbot framework
56
112
  email:
57
113
  - fnando.vieira@gmail.com
@@ -60,9 +116,11 @@ extensions: []
60
116
  extra_rdoc_files: []
61
117
  files:
62
118
  - ".gitignore"
119
+ - ".rubocop.yml"
63
120
  - ".travis.yml"
64
121
  - CODE_OF_CONDUCT.md
65
122
  - Gemfile
123
+ - Gemfile.lock
66
124
  - LICENSE.txt
67
125
  - README.md
68
126
  - Rakefile
@@ -70,6 +128,9 @@ files:
70
128
  - bin/setup
71
129
  - botkit.gemspec
72
130
  - lib/botkit.rb
131
+ - lib/botkit/bot.rb
132
+ - lib/botkit/message.rb
133
+ - lib/botkit/runner.rb
73
134
  - lib/botkit/version.rb
74
135
  homepage: https://rubygems.org/gems/botkit
75
136
  licenses: