slack-ruby-bot-boilerplate 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ module SlackRespondent
2
+ module Commands
3
+ module Support
4
+ class Match
5
+ extend Forwardable
6
+
7
+ delegate MatchData.public_instance_methods(false) => :@match_data
8
+
9
+ attr_reader :attachment, :attachment_field
10
+
11
+ def initialize(match_data, attachment = nil, attachment_field = nil)
12
+ unless match_data.is_a? MatchData
13
+ raise ArgumentError, 'match_data should be a type of MatchData'
14
+ end
15
+ @match_data = match_data
16
+ @attachment = attachment
17
+ @attachment_field = attachment_field
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module SlackRespondent
2
+ module Commands
3
+ class Unknown < Base
4
+ def self.call(client, data, _match)
5
+ client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!")
6
+ end
7
+
8
+ def self.pattern
9
+ /^(.*)$/
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ module SlackRespondent
2
+ module Config
3
+ extend self
4
+
5
+ ATTRS = %i[token url aliases user user_id team team_id allow_message_loops send_gifs logger].freeze
6
+ attr_accessor(*ATTRS)
7
+
8
+ def allow_message_loops?
9
+ allow_message_loops
10
+ end
11
+
12
+ def send_gifs?
13
+ return false unless defined?(Giphy)
14
+ v = boolean_from_env('SLACK_RUBY_BOT_SEND_GIFS')
15
+ send_gifs.nil? ? (v.nil? || v) : send_gifs
16
+ end
17
+
18
+ def reset!
19
+ ATTRS.each { |attr| send("#{attr}=", nil) }
20
+ end
21
+
22
+ private
23
+
24
+ def boolean_from_env(key)
25
+ value = ENV[key]
26
+ case value
27
+ when nil
28
+ nil
29
+ when 0, 'false', 'no'
30
+ false
31
+ when 1, 'true', 'yes'
32
+ true
33
+ else
34
+ raise ArgumentError, "Invalid value for #{key}: #{value}."
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module SlackRespondent
2
+ module Reactions
3
+ def self.included(base)
4
+ base.cattr_accessor :reactions
5
+ end
6
+
7
+ def on(event_name, command)
8
+ self.reactions ||= {}
9
+
10
+ self.reactions[event_name] ||= []
11
+ self.reactions[event_name].insert(0, command)
12
+ end
13
+
14
+ def react(event_type, data)
15
+
16
+ result = false
17
+ reactions[event_type].each do |reaction|
18
+ if reaction.invoke(client, data.event)
19
+ result = true
20
+ break
21
+ end
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ def config
28
+ SlackRespondent.config
29
+ end
30
+
31
+ private
32
+
33
+ def client
34
+ @client ||= SlackRespondent::ClientWrapper.new
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ module SlackRespondent
2
+ module Loggable
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def logger
10
+ @logger ||= SlackRespondent::Config.logger || begin
11
+ $stdout.sync = true
12
+ Logger.new($stdout)
13
+ end
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ def logger
19
+ self.class.logger
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module SlackRespondent
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'slack_respondent/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'slack-ruby-bot-boilerplate'
6
+ s.version = SlackRespondent::VERSION
7
+ s.authors = ['Ilyas Valiullov']
8
+ s.email = 'ilyas.valiullov@gmail.com'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.required_rubygems_version = '>= 1.3.6'
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- spec/*`.split("\n")
13
+ s.require_paths = ['lib']
14
+ s.homepage = 'https://github.com/IlyasValiullov/slack-ruby-bot-boilerplate'
15
+ s.licenses = ['MIT']
16
+ s.summary = 'Slack bot boilerplate for response on different events.'
17
+ s.add_dependency 'hashie'
18
+ s.add_dependency 'slack-ruby-client'
19
+ s.add_development_dependency 'rack-test'
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'rspec'
22
+ s.add_development_dependency 'rubocop', '0.58.2'
23
+ s.add_development_dependency 'vcr'
24
+ s.add_development_dependency 'webmock'
25
+ end
Binary file
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack-ruby-bot-boilerplate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilyas Valiullov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
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: slack-ruby-client
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.58.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.58.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email: ilyas.valiullov@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".gitignore"
132
+ - ".rspec"
133
+ - ".rubocop.yml"
134
+ - ".rubocop_todo.yml"
135
+ - ".travis.yml"
136
+ - CHANGELOG.md
137
+ - CONTRIBUTING.md
138
+ - DEPLOYMENT.md
139
+ - Gemfile
140
+ - LICENSE.md
141
+ - README.md
142
+ - Rakefile
143
+ - TUTORIAL.md
144
+ - UPGRADING.md
145
+ - lib/config/application.rb
146
+ - lib/config/boot.rb
147
+ - lib/config/environment.rb
148
+ - lib/slack_respondent.rb
149
+ - lib/slack_respondent/client.rb
150
+ - lib/slack_respondent/commands.rb
151
+ - lib/slack_respondent/commands/about.rb
152
+ - lib/slack_respondent/commands/base.rb
153
+ - lib/slack_respondent/commands/help.rb
154
+ - lib/slack_respondent/commands/hi.rb
155
+ - lib/slack_respondent/commands/support/attrs.rb
156
+ - lib/slack_respondent/commands/support/help.rb
157
+ - lib/slack_respondent/commands/support/match.rb
158
+ - lib/slack_respondent/commands/unknown.rb
159
+ - lib/slack_respondent/config.rb
160
+ - lib/slack_respondent/reactions.rb
161
+ - lib/slack_respondent/support/loggable.rb
162
+ - lib/slack_respondent/version.rb
163
+ - slack-ruby-bot-boilerplate.gemspec
164
+ - slack.png
165
+ homepage: https://github.com/IlyasValiullov/slack-ruby-bot-boilerplate
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.6
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.7.7
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Slack bot boilerplate for response on different events.
189
+ test_files: []