slack-smart-bot 1.5.1 → 1.6.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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +89 -2
  3. data/lib/slack-smart-bot.rb +6 -1
  4. data/lib/slack/smart-bot/commands.rb +5 -0
  5. data/lib/slack/smart-bot/commands/general/bot_help.rb +44 -40
  6. data/lib/slack/smart-bot/commands/general/bot_status.rb +32 -28
  7. data/lib/slack/smart-bot/commands/general/bye_bot.rb +9 -1
  8. data/lib/slack/smart-bot/commands/general/hi_bot.rb +6 -1
  9. data/lib/slack/smart-bot/commands/general/use_rules.rb +33 -29
  10. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +40 -35
  11. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +1 -0
  12. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +32 -0
  13. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +30 -25
  14. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +43 -0
  15. data/lib/slack/smart-bot/commands/on_bot/repl.rb +202 -0
  16. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +33 -29
  17. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +73 -0
  18. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +24 -0
  19. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +23 -18
  20. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +32 -27
  21. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +79 -74
  22. data/lib/slack/smart-bot/listen.rb +2 -0
  23. data/lib/slack/smart-bot/process.rb +61 -9
  24. data/lib/slack/smart-bot/process_first.rb +17 -3
  25. data/lib/slack/smart-bot/treat_message.rb +24 -3
  26. data/lib/slack/smart-bot/utils.rb +3 -0
  27. data/lib/slack/smart-bot/utils/get_help.rb +1 -1
  28. data/lib/slack/smart-bot/utils/get_repls.rb +11 -0
  29. data/lib/slack/smart-bot/utils/update_repls.rb +8 -0
  30. metadata +28 -19
@@ -188,8 +188,13 @@ class SlackSmartBot
188
188
  on_demand = true
189
189
  end
190
190
  if @status == :on and
191
- (@questions.keys.include?(nick) or
192
- (@listening.include?(nick) and typem != :on_extended) or
191
+ (@questions.key?(nick) or
192
+ (@repl_sessions.key?(nick) and dest==@repl_sessions[nick][:dest] and
193
+ ((@repl_sessions[nick][:on_thread] and thread_ts == @repl_sessions[nick][:thread_ts]) or
194
+ (!@repl_sessions[nick][:on_thread] and !Thread.current[:on_thread] ))) or
195
+ (@listening.key?(nick) and typem != :on_extended and
196
+ ((@listening[nick].key?(dest) and !Thread.current[:on_thread]) or
197
+ (@listening[nick].key?(thread_ts) and Thread.current[:on_thread] ) )) or
193
198
  dest[0] == "D" or on_demand)
194
199
  @logger.info "command: #{nick}> #{command}" unless processed
195
200
  #todo: verify this
@@ -228,7 +233,7 @@ class SlackSmartBot
228
233
  if @bots_created.key?(@rules_imported[user.id][user.id])
229
234
  if @bots_created[@rules_imported[user.id][user.id]][:status] == :on
230
235
  begin
231
- eval(File.new(config.path+rules_file).read) if File.exist?(config.path+rules_file)
236
+ eval(File.new(config.path+rules_file).read) if File.exist?(config.path+rules_file) and !['.','..'].include?(config.path + rules_file)
232
237
  rescue Exception => stack
233
238
  @logger.fatal "ERROR ON imported RULES FILE: #{rules_file}"
234
239
  @logger.fatal stack
@@ -263,6 +268,15 @@ class SlackSmartBot
263
268
  dont_understand('')
264
269
  end
265
270
  end
271
+
272
+ if processed and @listening.key?(nick)
273
+ if Thread.current[:on_thread] and @listening[nick].key?(Thread.current[:thread_ts])
274
+ @listening[nick][Thread.current[:thread_ts]] = Time.now
275
+ elsif !Thread.current[:on_thread] and @listening[nick].key?(dest)
276
+ @listening[nick][dest] = Time.now
277
+ end
278
+ end
279
+
266
280
  end
267
281
  rescue Exception => stack
268
282
  @logger.fatal stack
@@ -1,5 +1,6 @@
1
1
  class SlackSmartBot
2
2
  def treat_message(data, remove_blocks = true)
3
+
3
4
  begin
4
5
  unless data.text.to_s.match(/\A\s*\z/)
5
6
  #to remove italic, bold... from data.text since there is no method on slack api
@@ -10,8 +11,15 @@ class SlackSmartBot
10
11
  if b.elements.size > 0
11
12
  b.elements.each do |e|
12
13
  if e.type == 'rich_text_section'
13
- if e.elements.size > 0 and e.elements.type.uniq == ['text']
14
- data.text = e.elements.text.join
14
+ if e.elements.size > 0 and (e.elements.type.uniq - ['link', 'text']) == []
15
+ data.text = ''
16
+ e.elements.each do |el|
17
+ if el.type == 'text'
18
+ data.text += el.text
19
+ else
20
+ data.text += el.url
21
+ end
22
+ end
15
23
  end
16
24
  break
17
25
  end
@@ -95,10 +103,18 @@ class SlackSmartBot
95
103
  end
96
104
  end
97
105
  unless typem == :dont_treat
106
+ if (Time.now - @last_activity_check) > 60 * 30 #every 30 minutes
107
+ @last_activity_check = Time.now
108
+ @listening.each do |k,v|
109
+ v.each do |kk, vv|
110
+ @listening[k].delete(kk) if (Time.now - vv) > 60 * 30
111
+ end
112
+ @listening.delete(k) if @listening[k].empty?
113
+ end
114
+ end
98
115
  begin
99
116
  #todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
100
117
  user_info = client.web_client.users_info(user: data.user)
101
-
102
118
  if @questions.key?(user_info.user.name)
103
119
  if data.text.match?(/^\s*(Bye|Bæ|Good\sBye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s(#{@salutations.join("|")})\s*$/i)
104
120
  @questions.delete(user_info.user.name)
@@ -107,6 +123,11 @@ class SlackSmartBot
107
123
  command = @questions[user_info.user.name]
108
124
  @questions[user_info.user.name] = data.text
109
125
  end
126
+ elsif @repl_sessions.key?(user_info.user.name) and dest==@repl_sessions[user_info.user.name][:dest] and
127
+ ((@repl_sessions[user_info.user.name][:on_thread] and data.thread_ts == @repl_sessions[user_info.user.name][:thread_ts]) or
128
+ (!@repl_sessions[user_info.user.name][:on_thread] and data.thread_ts.to_s == '' ))
129
+ @repl_sessions[user_info.user.name][:command] = data.text
130
+ command = 'repl'
110
131
  else
111
132
  command = data.text
112
133
  end
@@ -11,3 +11,6 @@ require_relative 'utils/update_routines'
11
11
  require_relative 'utils/update_rules_imported'
12
12
  require_relative 'utils/update_shortcuts_file'
13
13
  require_relative 'utils/save_stats'
14
+ require_relative 'utils/get_repls'
15
+ require_relative 'utils/update_repls'
16
+
@@ -2,7 +2,7 @@ class SlackSmartBot
2
2
  def get_help(rules_file, dest, from, only_rules = false)
3
3
  order = {
4
4
  general: [:hi_bot, :bye_bot, :bot_help, :bot_status, :use_rules, :stop_using_rules],
5
- on_bot: [:ruby_code, :add_shortcut, :delete_shortcut, :see_shortcuts],
5
+ on_bot: [:ruby_code, :repl, :get_repl, :run_repl, :delete_repl, :see_repls, :add_shortcut, :delete_shortcut, :see_shortcuts],
6
6
  on_bot_admin: [:extend_rules, :stop_using_rules_on, :start_bot, :pause_bot, :add_routine,
7
7
  :see_routines, :start_routine, :pause_routine, :remove_routine, :run_routine]
8
8
  }
@@ -0,0 +1,11 @@
1
+ class SlackSmartBot
2
+
3
+ def get_repls(channel = @channel_id)
4
+ if File.exist?("#{config.path}/repl/repls_#{channel}.rb")
5
+ file_conf = IO.readlines("#{config.path}/repl/repls_#{channel}.rb").join
6
+ unless file_conf.to_s() == ""
7
+ @repls = eval(file_conf)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class SlackSmartBot
2
+
3
+ def update_repls(channel = @channel_id)
4
+ file = File.open("#{config.path}/repl/repls_#{channel}.rb", "w")
5
+ file.write (@repls.inspect)
6
+ file.close
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-smart-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client
@@ -36,20 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.7'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.7.24
39
+ version: '1.8'
43
40
  type: :runtime
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
46
43
  requirements:
47
44
  - - "~>"
48
45
  - !ruby/object:Gem::Version
49
- version: '1.7'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 1.7.24
46
+ version: '1.8'
53
47
  - !ruby/object:Gem::Dependency
54
48
  name: nice_hash
55
49
  requirement: !ruby/object:Gem::Requirement
@@ -79,25 +73,33 @@ dependencies:
79
73
  - !ruby/object:Gem::Version
80
74
  version: 0.8.0
81
75
  - !ruby/object:Gem::Dependency
82
- name: rspec
76
+ name: awesome_print
83
77
  requirement: !ruby/object:Gem::Requirement
84
78
  requirements:
85
- - - ">="
79
+ - - "~>"
86
80
  - !ruby/object:Gem::Version
87
- version: 3.8.0
81
+ version: '1.8'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
88
86
  - - "~>"
89
87
  - !ruby/object:Gem::Version
90
- version: '3.8'
88
+ version: '1.8'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.9'
91
96
  type: :development
92
97
  prerelease: false
93
98
  version_requirements: !ruby/object:Gem::Requirement
94
99
  requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: 3.8.0
98
100
  - - "~>"
99
101
  - !ruby/object:Gem::Version
100
- version: '3.8'
102
+ version: '3.9'
101
103
  description: "Create a Slack bot that is smart and so easy to expand, create new bots
102
104
  on demand, run ruby code on chat, create shortcuts... \n The main scope of this
103
105
  gem is to be used internally in the company so teams can create team channels with
@@ -147,8 +149,13 @@ files:
147
149
  - lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb
148
150
  - lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb
149
151
  - lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb
152
+ - lib/slack/smart-bot/commands/on_bot/delete_repl.rb
150
153
  - lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb
154
+ - lib/slack/smart-bot/commands/on_bot/get_repl.rb
155
+ - lib/slack/smart-bot/commands/on_bot/repl.rb
151
156
  - lib/slack/smart-bot/commands/on_bot/ruby_code.rb
157
+ - lib/slack/smart-bot/commands/on_bot/run_repl.rb
158
+ - lib/slack/smart-bot/commands/on_bot/see_repls.rb
152
159
  - lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb
153
160
  - lib/slack/smart-bot/commands/on_extended/bot_rules.rb
154
161
  - lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb
@@ -165,11 +172,13 @@ files:
165
172
  - lib/slack/smart-bot/utils/get_bots_created.rb
166
173
  - lib/slack/smart-bot/utils/get_channels_name_and_id.rb
167
174
  - lib/slack/smart-bot/utils/get_help.rb
175
+ - lib/slack/smart-bot/utils/get_repls.rb
168
176
  - lib/slack/smart-bot/utils/get_routines.rb
169
177
  - lib/slack/smart-bot/utils/get_rules_imported.rb
170
178
  - lib/slack/smart-bot/utils/remove_hash_keys.rb
171
179
  - lib/slack/smart-bot/utils/save_stats.rb
172
180
  - lib/slack/smart-bot/utils/update_bots_file.rb
181
+ - lib/slack/smart-bot/utils/update_repls.rb
173
182
  - lib/slack/smart-bot/utils/update_routines.rb
174
183
  - lib/slack/smart-bot/utils/update_rules_imported.rb
175
184
  - lib/slack/smart-bot/utils/update_shortcuts_file.rb
@@ -185,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
194
  requirements:
186
195
  - - ">="
187
196
  - !ruby/object:Gem::Version
188
- version: '2.4'
197
+ version: '2.5'
189
198
  required_rubygems_version: !ruby/object:Gem::Requirement
190
199
  requirements:
191
200
  - - ">="