slack-smart-bot 1.7.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -12
  3. data/lib/slack-smart-bot.rb +52 -43
  4. data/lib/slack-smart-bot_general_rules.rb +7 -4
  5. data/lib/slack-smart-bot_rules.rb +8 -6
  6. data/lib/slack/smart-bot/comm.rb +6 -1
  7. data/lib/slack/smart-bot/comm/ask.rb +12 -5
  8. data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
  9. data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
  10. data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
  11. data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
  12. data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
  13. data/lib/slack/smart-bot/comm/react.rb +21 -8
  14. data/lib/slack/smart-bot/comm/respond.rb +11 -6
  15. data/lib/slack/smart-bot/comm/send_file.rb +1 -1
  16. data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
  17. data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
  18. data/lib/slack/smart-bot/comm/unreact.rb +29 -0
  19. data/lib/slack/smart-bot/commands.rb +3 -1
  20. data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
  21. data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
  22. data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
  23. data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
  24. data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
  25. data/lib/slack/smart-bot/commands/general/use_rules.rb +2 -6
  26. data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
  27. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
  28. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +33 -9
  29. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
  30. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
  31. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +9 -2
  32. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
  33. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
  34. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
  35. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
  36. data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
  37. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
  38. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
  39. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
  40. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
  41. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
  42. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
  43. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
  44. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
  45. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
  46. data/lib/slack/smart-bot/listen.rb +6 -5
  47. data/lib/slack/smart-bot/process.rb +227 -186
  48. data/lib/slack/smart-bot/process_first.rb +104 -87
  49. data/lib/slack/smart-bot/treat_message.rb +116 -52
  50. data/lib/slack/smart-bot/utils.rb +2 -0
  51. data/lib/slack/smart-bot/utils/answer.rb +18 -0
  52. data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
  53. data/lib/slack/smart-bot/utils/build_help.rb +57 -5
  54. data/lib/slack/smart-bot/utils/create_routine_thread.rb +48 -8
  55. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
  56. data/lib/slack/smart-bot/utils/get_help.rb +79 -17
  57. data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
  58. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
  59. data/whats_new.txt +18 -0
  60. metadata +22 -12
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -135
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd95efb0ac282a17d1b463fe28293643c0b38b91b3261e0d3899e879950e4655
4
- data.tar.gz: 1d332d2651286f4bef95c1172d95bc6ce422166b50bf788773563747ebbf1c30
3
+ metadata.gz: 0566062f8e9af6bc724b505bc1ee0821027e93bf5302a36781a0506e66d2cdf7
4
+ data.tar.gz: 3d10378e17c6dc94f70784c5a68854fbdac9c4d6e752f5616728f27b7c4ab706
5
5
  SHA512:
6
- metadata.gz: f48dc2999a22da392d297cb789dfcc7552ce1ef7aad607283f705d39af5eac58ce2ca002b844178184e6bacdc13fe641ddbe762f8a999b17da7532a5cad234b8
7
- data.tar.gz: f4ac49668234f24295e79afd842218e40a1a918c1107392af84d3b31c6d8908fadb8319f2e4596ef896c44e7c36665714523fc554f4c8b70a3a5a1f02cc2c872
6
+ metadata.gz: 4cc5736de96995f20e0530a54c2f0ddf5fdc8dee3288e6f04bc938ef446b869508fc003f58b8ed030b89bdab37959aff6ca1e0d59e556df581ca0c5a2abc5b01
7
+ data.tar.gz: 929465da66b5ca3660b1bad1b360d7badc391d43596fcbe834a8e69f0aca3decd0b970b67dfbb063df8d77cb0c50b47d4b2b4ed84b99663719532406958b6b34
data/README.md CHANGED
@@ -10,6 +10,8 @@ The main scope of this ruby gem is to be used internally in your company so team
10
10
 
11
11
  slack-smart-bot can create bots on demand, create shortcuts, run ruby code... just on a chat channel, you can access it just from your mobile phone if you want and run those tests you forgot to run, get the results, restart a server... no limits.
12
12
 
13
+ ![](slack.png)
14
+
13
15
  # Table of Contents
14
16
 
15
17
  - [Installation and configuration](#installation-and-configuration)
@@ -114,23 +116,24 @@ def rules(user, command, processed, dest)
114
116
  # help: it will sleep the bot for 10 seconds
115
117
  # help:
116
118
  when /^go\sto\ssleep/i
117
- unless @questions.keys.include?(from)
119
+ if answer.empty?
118
120
  ask "do you want me to take a siesta?"
119
121
  else
120
- case @questions[from]
122
+ case answer
121
123
  when /yes/i, /yep/i, /sure/i
122
- @questions.delete(from)
124
+ answer_delete
123
125
  respond "I'll be sleeping for 10 secs... just for you"
124
126
  respond "zZzzzzzZZZZZZzzzzzzz!"
125
127
  react :sleeping
126
128
  sleep 10
129
+ unreact :sleeping
127
130
  react :sunny
128
131
  when /no/i, /nope/i, /cancel/i
129
- @questions.delete(from)
132
+ answer_delete
130
133
  respond "Thanks, I'm happy to be awake"
131
134
  else
132
135
  respond "I don't understand"
133
- ask "are you sure do you want me to sleep? (yes or no)"
136
+ ask "are you sure you want me to sleep? (yes or no)"
134
137
  end
135
138
  end
136
139
 
@@ -152,6 +155,8 @@ def rules(user, command, processed, dest)
152
155
  else
153
156
  respond "#{user.name}: #{stdout} #{stderr}"
154
157
  end
158
+
159
+ unreact :runner
155
160
 
156
161
  else
157
162
  unless processed
@@ -198,7 +203,7 @@ Examples run a command on demand:
198
203
  >**_Peter>_** `^echo Example`
199
204
  >. . . . . . . . .**_Smart-Bot>_** `Example`
200
205
 
201
- Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME.
206
+ Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME. You can supply more than one channel then all the bots will respond.
202
207
 
203
208
  Example:
204
209
  >**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
@@ -218,9 +223,9 @@ Examples:
218
223
  >. . . . . . . . .**_Smart-Bot>_** `b`
219
224
 
220
225
  ### Bot Help
221
- To get a full list of all commands and rules for a specific Smart Bot: **_`bot help`_**. It will show only the specific available commands for the user requesting.
226
+ To get a full list of all commands and rules for a specific Smart Bot: **_`bot help`_**. It will show only the specific available commands for the user requesting. By default it will display only a short version of the bot help, call **_`bot help expanded`_** to get a expanded version of all commands.
222
227
 
223
- If you want to search just for a specific command: **_`bot help COMMAND`_**
228
+ If you want to search just for a specific command: **_`bot help COMMAND`_** It will display expanded explanations for the command.
224
229
 
225
230
  To show only the specific rules of the Smart Bot defined on the rules file: **_`bot rules`_** or **_`bot rules COMMAND`_**
226
231
 
@@ -236,6 +241,7 @@ Remember when you add code to your rules you need to specify the help that will
236
241
  For the examples use _ and for the rules `. This is a good example of a Help supplied on rules source code:
237
242
 
238
243
  ```ruby
244
+ # help: ----------------------------------------------
239
245
  # help: `run TYPE tests on LOCATION`
240
246
  # help: `execute TYPE tests on LOCATION`
241
247
  # help: run the specified tests on the indicated location
@@ -247,6 +253,8 @@ For the examples use _ and for the rules `. This is a good example of a Help sup
247
253
  # help: _execute smoke tests on db1_
248
254
  ```
249
255
 
256
+ To see what's new just call `What's new`
257
+
250
258
  ### Bot Management
251
259
  To create a new bot on a channel, run on MASTER CHANNEL: **_`create bot on CHANNEL`_**. The admins of this new bot on that channel will be the MASTER ADMINS, the creator of the bot and the creator of that channel. It will create a new rules file linked to this new bot.
252
260
 
@@ -256,9 +264,11 @@ If you want to pause a bot, from the channel of the bot: **_`pause bot`_**. To s
256
264
 
257
265
  To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
258
266
 
267
+ If you need it you can set the SmartBot on maintenance mode by running: **_`set maintenance on`_**. A message to be displayed can be added if not the default message will be used. Run **_`set maintenance off`_** when you want the SmartBot to be running in normal conditions again.
268
+
259
269
  To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
260
270
 
261
- If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. Take a look at `bot help bot stats` for more info.
271
+ If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. As a normal user you will get your own stats when calling **_`bot stats`_**. Take a look at `bot help bot stats` for more info.
262
272
 
263
273
  You can also get the bot logs of the bot channel you are using by calling `get bot logs`. You need to be a Master Admin user on a DM with the Smart Bot.
264
274
 
@@ -306,7 +316,7 @@ If you declare on your rules file a method called `project_folder` returning the
306
316
 
307
317
  By default it will be automatically loaded the gems: `string_pattern`, `nice_hash` and `nice_http`
308
318
 
309
- To pre-execute some ruby when starting the session add the code to `.smart-bot-repl` file on the project root folder defined on `project_folder`
319
+ To pre-execute some ruby when starting the session add the code to `.smart-bot-repl` file on the project root folder defined on `project_folder`. Then that file will be always executed before the REPL started or created. In that case if we want to avoid to run that file before the REPL we can do it adding the word 'clean' before the command `clean repl`.
310
320
 
311
321
  If you want to see the methods of a class or module you created use `ls TheModuleOrClass`
312
322
 
@@ -364,7 +374,7 @@ That shortcut will be available for you, in case you want to make it available f
364
374
  Example:
365
375
  >**_Peter>_** `!add shortcut for all spanish bank account: ruby require 'iso/iban'; 3.times {puts ISO::IBAN.random('ES')}`
366
376
  >**_Smart-Bot>_** `shortcut added`
367
- >**_Peter>_** `!spanish bank account`
377
+ >**_John>_** `!spanish bank account`
368
378
  >**_Smart-Bot>_** `ES4664553191352006861448`
369
379
  `ES4799209592433480943244`
370
380
  `ES8888795057132445752702`
@@ -383,7 +393,7 @@ Example:
383
393
  To see available shortcuts: **_`see shortcuts`_** and to delete a particular shortcut: **_`delete shortcut NAME`_**
384
394
 
385
395
  ### Routines
386
- To add specific commands to be run automatically every certain amount of time or a specific time: **_`add routine NAME every NUMBER PERIOD COMMAND`_** or **_`add routine NAME at TIME COMMAND`_**
396
+ To add specific commands to be run automatically every certain amount of time or a specific time: **_`add routine NAME every NUMBER PERIOD COMMAND`_** or **_`add routine NAME at TIME COMMAND`_**. Also just before the command you can supply the channel where you want to publish the results, if not channel supplied then it would be the SmartBot Channel or on the DM if the command is run from there. Remember the SmartBot needs to have access to the channel where you want to publish.
387
397
 
388
398
  If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
389
399
 
@@ -391,6 +401,8 @@ Examples:
391
401
  >**_`add routine run_tests every 3h !run tests on customers`_**
392
402
  >**_`add routine clean_db at 17:05 !clean customers temp db`_**
393
403
  >**_`add silent routine clean_db at 17:05 !clean customers temp db`_**
404
+ >**_`add routine clean_custdb on Mondays at 05:00 !clean customers db`_**
405
+ >**_`add routine clean_custdb on Tuesdays at 09:00 #SREChannel !clean customers db`_**
394
406
 
395
407
  Also instead of adding a Command to be executed, you can attach a file, then the routine will be created and the attached file will be executed on the criteria specified. Only Master Admins are allowed to use it this way.
396
408
 
@@ -41,6 +41,8 @@ class SlackSmartBot
41
41
  config[:simulate] = false unless config.key?(:simulate)
42
42
  config[:stats] = false unless config.key?(:stats)
43
43
  config[:allow_access] = Hash.new unless config.key?(:allow_access)
44
+ config[:on_maintenance] = false unless config.key?(:on_maintenance)
45
+ config[:on_maintenance_message] = "Sorry I'm on maintenance so I cannot attend your request." unless config.key?(:on_maintenance_message)
44
46
 
45
47
  if config.path.to_s!='' and config.file.to_s==''
46
48
  config.file = File.basename($0)
@@ -89,7 +91,7 @@ class SlackSmartBot
89
91
  config.on_master_bot = false
90
92
  end
91
93
 
92
- if !config.key?(:token) or config.token.to_s == ''
94
+ if (!config.key?(:token) or config.token.to_s == '') and !config.simulate
93
95
  abort "You need to supply a valid token key on the settings. key: :token"
94
96
  elsif !config.key?(:masters) or !config.masters.is_a?(Array) or config.masters.size == 0
95
97
  abort "You need to supply a masters array on the settings containing the user names of the master admins. key: :masters"
@@ -104,7 +106,8 @@ class SlackSmartBot
104
106
  logfile = File.basename(config.rules_file.gsub("_rules_", "_logs_"), ".rb") + ".log"
105
107
  config.log_file = logfile
106
108
  @logger = Logger.new("#{config.path}/logs/#{logfile}")
107
-
109
+ @last_respond = Time.now
110
+
108
111
  config_log = config.dup
109
112
  config_log.delete(:token)
110
113
  @logger.info "Initializing bot: #{config_log.inspect}"
@@ -114,15 +117,21 @@ class SlackSmartBot
114
117
 
115
118
  self.config = config
116
119
 
117
- Slack.configure do |conf|
118
- conf.token = config[:token]
120
+ unless config.simulate and config.key?(:client)
121
+ Slack.configure do |conf|
122
+ conf.token = config[:token]
123
+ end
119
124
  end
120
125
  restarts = 0
121
126
  created = false
122
127
  while restarts < 200 and !created
123
128
  begin
124
129
  @logger.info "Connecting #{config_log.inspect}"
125
- self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
130
+ if config.simulate and config.key?(:client)
131
+ self.client = config.client
132
+ else
133
+ self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
134
+ end
126
135
  created = true
127
136
  rescue Exception => e
128
137
  restarts += 1
@@ -143,6 +152,8 @@ class SlackSmartBot
143
152
  @bots_created = Hash.new()
144
153
  @shortcuts = Hash.new()
145
154
  @shortcuts[:all] = Hash.new()
155
+ @shortcuts_global = Hash.new()
156
+ @shortcuts_global[:all] = Hash.new()
146
157
  @rules_imported = Hash.new()
147
158
  @routines = Hash.new()
148
159
  @repls = Hash.new()
@@ -153,6 +164,12 @@ class SlackSmartBot
153
164
  @shortcuts = eval(file_sc)
154
165
  end
155
166
  end
167
+ if File.exist?("#{config.path}/shortcuts/shortcuts_global.rb")
168
+ file_sc = IO.readlines("#{config.path}/shortcuts/shortcuts_global.rb").join
169
+ unless file_sc.to_s() == ""
170
+ @shortcuts_global = eval(file_sc)
171
+ end
172
+ end
156
173
 
157
174
  get_routines()
158
175
  get_repls()
@@ -177,48 +194,41 @@ class SlackSmartBot
177
194
  get_rules_imported()
178
195
 
179
196
  begin
197
+ #todo: take in consideration the case that the value supplied on config.masters and config.admins are the ids and not the user names
180
198
  @admin_users_id = []
199
+ @master_admin_users_id = []
181
200
  config.admins.each do |au|
182
- user_info = client.web_client.users_info(user: "@#{au}")
201
+ user_info = get_user_info("@#{au}")
183
202
  @admin_users_id << user_info.user.id
203
+ if config.masters.include?(au)
204
+ @master_admin_users_id << user_info.user.id
205
+ end
206
+ sleep 1
207
+ end
208
+ (config.masters-config.admins).each do |au|
209
+ user_info = get_user_info("@#{au}")
210
+ @master_admin_users_id << user_info.user.id
184
211
  sleep 1
185
212
  end
186
213
  rescue Slack::Web::Api::Errors::TooManyRequestsError
187
214
  @logger.fatal "TooManyRequestsError"
188
215
  abort("TooManyRequestsError please re run the bot and be sure of executing first: killall ruby")
189
216
  rescue Exception => stack
217
+ pp stack if config.testing
190
218
  abort("The admin user specified on settings: #{config.admins.join(", ")}, doesn't exist on Slack. Execution aborted")
191
219
  end
192
220
 
193
- client.on :hello do
194
- m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
195
- puts m
196
- @logger.info m
197
- config.nick = client.self.name
198
- config.nick_id = client.self.id
199
- @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
200
-
201
- gems_remote = `gem list slack-smart-bot --remote`
202
- version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
203
- version_message = ""
204
- if version_remote != VERSION
205
- version_message = ". There is a new available version: #{version_remote}."
206
- end
207
- if !config[:silent] or ENV['BOT_SILENT'].to_s == 'false'
208
- ENV['BOT_SILENT'] = 'true' if config[:silent] == 'true' and ENV['BOT_SILENT'].to_s != 'true'
209
- respond "Smart Bot started v#{VERSION}#{version_message}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
210
- end
211
- @routines.each do |ch, rout|
212
- rout.each do |k, v|
213
- if !v[:running] and v[:channel_name] == config.channel
214
- create_routine_thread(k)
215
- end
216
- end
221
+ if config.simulate and config.key?(:client)
222
+ event_hello()
223
+ else
224
+ client.on :hello do
225
+ event_hello()
217
226
  end
218
227
  end
219
228
 
220
229
  @status = config.status_init
221
230
  @questions = Hash.new()
231
+ @answer = Hash.new()
222
232
  @repl_sessions = Hash.new()
223
233
  @channels_id = Hash.new()
224
234
  @channels_name = Hash.new()
@@ -243,20 +253,19 @@ class SlackSmartBot
243
253
  end
244
254
  end
245
255
  end
256
+ else
257
+ client.on :close do |_data|
258
+ m = "Connection closing, exiting. #{Time.now}"
259
+ @logger.info m
260
+ @logger.info _data
261
+ end
262
+
263
+ client.on :closed do |_data|
264
+ m = "Connection has been disconnected. #{Time.now}"
265
+ @logger.info m
266
+ @logger.info _data
267
+ end
246
268
  end
247
-
248
- client.on :close do |_data|
249
- m = "Connection closing, exiting. #{Time.now}"
250
- @logger.info m
251
- @logger.info _data
252
- end
253
-
254
- client.on :closed do |_data|
255
- m = "Connection has been disconnected. #{Time.now}"
256
- @logger.info m
257
- @logger.info _data
258
- end
259
-
260
269
  self
261
270
  end
262
271
 
@@ -8,12 +8,15 @@ def general_rules(user, command, processed, dest, files = [], rules_file = "")
8
8
 
9
9
  # help: ----------------------------------------------
10
10
  # help: `echo SOMETHING`
11
- # help: repeats SOMETHING
11
+ # help: `INTEGER echo SOMETHING`
12
+ # help: repeats SOMETHING. If INTEGER supplied then that number of times.
12
13
  # help: Examples:
13
14
  # help: _echo I am the Smart Bot_
14
- when /^echo\s(.+)/i
15
- save_stats :echo
16
- respond $1
15
+ # help: _100 echo :heart:_
16
+ when /^(\d*)\s*echo\s(.+)/i
17
+ save_stats :echo
18
+ $1.to_s == '' ? times = 1 : times = $1.to_i
19
+ respond ($2*times).to_s
17
20
 
18
21
  else
19
22
  return false
@@ -2,7 +2,7 @@
2
2
  #path to the project folder
3
3
  # for example "#{`eval echo ~$USER`.chop}/projects/the_project"
4
4
  def project_folder()
5
- "#{`eval echo ~$USER`.chop}/"
5
+ "#{Dir.pwd}/"
6
6
  end
7
7
 
8
8
  #link to the project
@@ -50,23 +50,24 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
50
50
  # help:
51
51
  when /^go\sto\ssleep/i
52
52
  save_stats :go_to_sleep
53
- unless @questions.keys.include?(from)
53
+ if answer.empty?
54
54
  ask "do you want me to take a siesta?"
55
55
  else
56
- case @questions[from]
56
+ case answer
57
57
  when /yes/i, /yep/i, /sure/i
58
- @questions.delete(from)
58
+ answer_delete
59
59
  respond "I'll be sleeping for 5 secs... just for you"
60
60
  respond "zZzzzzzZZZZZZzzzzzzz!"
61
61
  react :sleeping
62
62
  sleep 5
63
+ unreact :sleeping
63
64
  react :sunny
64
65
  when /no/i, /nope/i, /cancel/i
65
- @questions.delete(from)
66
+ answer_delete
66
67
  respond "Thanks, I'm happy to be awake"
67
68
  else
68
69
  respond "I don't understand"
69
- ask "are you sure do you want me to sleep? (yes or no)"
70
+ ask "are you sure you want me to sleep? (yes or no)"
70
71
  end
71
72
  end
72
73
 
@@ -81,6 +82,7 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
81
82
  process_to_run = "ruby -v"
82
83
  process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
83
84
  stdout, stderr, status = Open3.capture3(process_to_run)
85
+ unreact :runner
84
86
  if stderr == ""
85
87
  if stdout == ""
86
88
  respond "#{display_name}: Nothing returned."
@@ -5,4 +5,9 @@ require_relative 'comm/respond'
5
5
  require_relative 'comm/send_file'
6
6
  require_relative 'comm/send_msg_channel'
7
7
  require_relative 'comm/send_msg_user'
8
- require_relative 'comm/react'
8
+ require_relative 'comm/react'
9
+ require_relative 'comm/unreact'
10
+ require_relative 'comm/get_user_info'
11
+ require_relative 'comm/event_hello'
12
+ require_relative 'comm/get_channel_members'
13
+ require_relative 'comm/get_channels'
@@ -16,7 +16,7 @@ class SlackSmartBot
16
16
  if dest.nil?
17
17
  if config[:simulate]
18
18
  open("#{config.path}/buffer_complete.log", "a") { |f|
19
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}~~~"
19
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
20
20
  }
21
21
  else
22
22
  if Thread.current[:on_thread]
@@ -27,13 +27,13 @@ class SlackSmartBot
27
27
  end
28
28
  if config[:testing] and config.on_master_bot
29
29
  open("#{config.path}/buffer.log", "a") { |f|
30
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}"
30
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
31
31
  }
32
32
  end
33
33
  elsif dest[0] == "C" or dest[0] == "G" # channel
34
34
  if config[:simulate]
35
35
  open("#{config.path}/buffer_complete.log", "a") { |f|
36
- f.puts "|#{dest}|#{config[:nick_id]}|#{message}~~~"
36
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
37
37
  }
38
38
  else
39
39
  if Thread.current[:on_thread]
@@ -44,13 +44,20 @@ class SlackSmartBot
44
44
  end
45
45
  if config[:testing] and config.on_master_bot
46
46
  open("#{config.path}/buffer.log", "a") { |f|
47
- f.puts "|#{dest}|#{config[:nick_id]}|#{message}"
47
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
48
48
  }
49
49
  end
50
50
  elsif dest[0] == "D" #private message
51
51
  send_msg_user(dest, message)
52
52
  end
53
- @questions[to] = context
53
+ if Thread.current[:on_thread]
54
+ qdest = Thread.current[:thread_ts]
55
+ else
56
+ qdest = dest
57
+ end
58
+ @answer[to] = {} unless @answer.key?(to)
59
+ @answer[to][qdest] = context
60
+ @questions[to] = context # to be backwards compatible #todo remove it when 2.0
54
61
  end
55
62
 
56
63
  end
@@ -10,7 +10,7 @@ class SlackSmartBot
10
10
  if typem==:on_extended
11
11
  get_bots_created()
12
12
  end
13
- text = get_help(rules_file, dest, user.name, typem==:on_extended)
13
+ text = get_help(rules_file, dest, user.name, typem==:on_extended, true)
14
14
 
15
15
  ff = text.scan(/\s*`\s*([^`]+)\s*`\s*/i).flatten
16
16
  ff.delete("!THE_COMMAND")