slack-smart-bot 1.7.0 → 1.9.2

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 +53 -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 +38 -12
  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 +6 -9
  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 +42 -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 +230 -186
  48. data/lib/slack/smart-bot/process_first.rb +104 -87
  49. data/lib/slack/smart-bot/treat_message.rb +128 -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 +24 -0
  60. metadata +23 -13
  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: 974b9b2da39dd58e4e404572932ace72c5b9d1136956543ac890cf7bc91ab61e
4
+ data.tar.gz: a304bbeeecc5177c5014c86902c20d9682e6addfc00ab3f5ee33aeca4dba2215
5
5
  SHA512:
6
- metadata.gz: f48dc2999a22da392d297cb789dfcc7552ce1ef7aad607283f705d39af5eac58ce2ca002b844178184e6bacdc13fe641ddbe762f8a999b17da7532a5cad234b8
7
- data.tar.gz: f4ac49668234f24295e79afd842218e40a1a918c1107392af84d3b31c6d8908fadb8319f2e4596ef896c44e7c36665714523fc554f4c8b70a3a5a1f02cc2c872
6
+ metadata.gz: 85e6d1e343b0523b25c5c630d37fcda402a8529d2ae8a1f5473694a65e9311293b4d628bc0e9a18e3910bd68123276b30039e1a50115c97bd029db19a2a9738a
7
+ data.tar.gz: 90c2441764b9faceeb74d1281c19fccc84c960d4344f5822c5d50293d1de55d300d10373a60e0cf876270aced23f20686844e2cb0503dfb0a30004adeec8e27c
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)
@@ -59,6 +61,7 @@ class SlackSmartBot
59
61
  Dir.mkdir("#{config.path}/logs") unless Dir.exist?("#{config.path}/logs")
60
62
  Dir.mkdir("#{config.path}/shortcuts") unless Dir.exist?("#{config.path}/shortcuts")
61
63
  Dir.mkdir("#{config.path}/routines") unless Dir.exist?("#{config.path}/routines")
64
+ File.delete("#{config.path}/config_tmp.status") if File.exist?("#{config.path}/config_tmp.status")
62
65
 
63
66
  config.masters = MASTER_USERS if config.masters.to_s=='' and defined?(MASTER_USERS)
64
67
  config.master_channel = MASTER_CHANNEL if config.master_channel.to_s=='' and defined?(MASTER_CHANNEL)
@@ -89,7 +92,7 @@ class SlackSmartBot
89
92
  config.on_master_bot = false
90
93
  end
91
94
 
92
- if !config.key?(:token) or config.token.to_s == ''
95
+ if (!config.key?(:token) or config.token.to_s == '') and !config.simulate
93
96
  abort "You need to supply a valid token key on the settings. key: :token"
94
97
  elsif !config.key?(:masters) or !config.masters.is_a?(Array) or config.masters.size == 0
95
98
  abort "You need to supply a masters array on the settings containing the user names of the master admins. key: :masters"
@@ -104,7 +107,8 @@ class SlackSmartBot
104
107
  logfile = File.basename(config.rules_file.gsub("_rules_", "_logs_"), ".rb") + ".log"
105
108
  config.log_file = logfile
106
109
  @logger = Logger.new("#{config.path}/logs/#{logfile}")
107
-
110
+ @last_respond = Time.now
111
+
108
112
  config_log = config.dup
109
113
  config_log.delete(:token)
110
114
  @logger.info "Initializing bot: #{config_log.inspect}"
@@ -114,15 +118,21 @@ class SlackSmartBot
114
118
 
115
119
  self.config = config
116
120
 
117
- Slack.configure do |conf|
118
- conf.token = config[:token]
121
+ unless config.simulate and config.key?(:client)
122
+ Slack.configure do |conf|
123
+ conf.token = config[:token]
124
+ end
119
125
  end
120
126
  restarts = 0
121
127
  created = false
122
128
  while restarts < 200 and !created
123
129
  begin
124
130
  @logger.info "Connecting #{config_log.inspect}"
125
- self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
131
+ if config.simulate and config.key?(:client)
132
+ self.client = config.client
133
+ else
134
+ self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
135
+ end
126
136
  created = true
127
137
  rescue Exception => e
128
138
  restarts += 1
@@ -143,6 +153,8 @@ class SlackSmartBot
143
153
  @bots_created = Hash.new()
144
154
  @shortcuts = Hash.new()
145
155
  @shortcuts[:all] = Hash.new()
156
+ @shortcuts_global = Hash.new()
157
+ @shortcuts_global[:all] = Hash.new()
146
158
  @rules_imported = Hash.new()
147
159
  @routines = Hash.new()
148
160
  @repls = Hash.new()
@@ -153,6 +165,12 @@ class SlackSmartBot
153
165
  @shortcuts = eval(file_sc)
154
166
  end
155
167
  end
168
+ if File.exist?("#{config.path}/shortcuts/shortcuts_global.rb")
169
+ file_sc = IO.readlines("#{config.path}/shortcuts/shortcuts_global.rb").join
170
+ unless file_sc.to_s() == ""
171
+ @shortcuts_global = eval(file_sc)
172
+ end
173
+ end
156
174
 
157
175
  get_routines()
158
176
  get_repls()
@@ -177,48 +195,41 @@ class SlackSmartBot
177
195
  get_rules_imported()
178
196
 
179
197
  begin
198
+ #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
199
  @admin_users_id = []
200
+ @master_admin_users_id = []
181
201
  config.admins.each do |au|
182
- user_info = client.web_client.users_info(user: "@#{au}")
202
+ user_info = get_user_info("@#{au}")
183
203
  @admin_users_id << user_info.user.id
204
+ if config.masters.include?(au)
205
+ @master_admin_users_id << user_info.user.id
206
+ end
207
+ sleep 1
208
+ end
209
+ (config.masters-config.admins).each do |au|
210
+ user_info = get_user_info("@#{au}")
211
+ @master_admin_users_id << user_info.user.id
184
212
  sleep 1
185
213
  end
186
214
  rescue Slack::Web::Api::Errors::TooManyRequestsError
187
215
  @logger.fatal "TooManyRequestsError"
188
216
  abort("TooManyRequestsError please re run the bot and be sure of executing first: killall ruby")
189
217
  rescue Exception => stack
218
+ pp stack if config.testing
190
219
  abort("The admin user specified on settings: #{config.admins.join(", ")}, doesn't exist on Slack. Execution aborted")
191
220
  end
192
221
 
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
222
+ if config.simulate and config.key?(:client)
223
+ event_hello()
224
+ else
225
+ client.on :hello do
226
+ event_hello()
217
227
  end
218
228
  end
219
229
 
220
230
  @status = config.status_init
221
231
  @questions = Hash.new()
232
+ @answer = Hash.new()
222
233
  @repl_sessions = Hash.new()
223
234
  @channels_id = Hash.new()
224
235
  @channels_name = Hash.new()
@@ -243,20 +254,19 @@ class SlackSmartBot
243
254
  end
244
255
  end
245
256
  end
257
+ else
258
+ client.on :close do |_data|
259
+ m = "Connection closing, exiting. #{Time.now}"
260
+ @logger.info m
261
+ @logger.info _data
262
+ end
263
+
264
+ client.on :closed do |_data|
265
+ m = "Connection has been disconnected. #{Time.now}"
266
+ @logger.info m
267
+ @logger.info _data
268
+ end
246
269
  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
270
  self
261
271
  end
262
272
 
@@ -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