slack-smart-bot 0.6.6 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slack-smart-bot.rb +64 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e7f5fe180d59d53a3b04c4f5a6a71521f3153add97d4d2c7b467d0e14c7d70
|
4
|
+
data.tar.gz: 4c503562cc952a1c8bc892ee862bfc2d25de84e829a216b302dc6e771a2eb2db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f960f7c7d0fd5e6949ac4b942dac8715da5a5275d514aea9faac5febb0f58ca74dfaae0b5fd9f9f969f79284ec50d982bd17449950cb8cc297b335f12661c69e
|
7
|
+
data.tar.gz: 729157c3ed6944b91aaeca4748f6a179f89df8cb953dee392d949d512800c507620e8f588d8f5b62d02bb267a1ca5b917ea763b5eaf30af999fd7e76f75f65de
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -211,11 +211,12 @@ class SlackSmartBot
|
|
211
211
|
channels = wclient.channels_list.channels
|
212
212
|
channel_found = channels.detect { |c| c.name == channel_rules_name }
|
213
213
|
members = wclient.conversations_members(channel: @channels_id[channel_rules_name]).members unless channel_found.nil?
|
214
|
-
|
215
214
|
if channel_found.nil?
|
216
215
|
@logger.fatal "Not possible to find the channel #{channel_rules_name}"
|
217
216
|
elsif channel_found.name == MASTER_CHANNEL
|
218
217
|
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
218
|
+
elsif @status != :on
|
219
|
+
respond "The bot in that channel is not :on", dest
|
219
220
|
elsif data.user == channel_found.creator or members.include?(data.user)
|
220
221
|
res = process_first(user_info.user, command, dest, channel_rules)
|
221
222
|
else
|
@@ -246,16 +247,22 @@ class SlackSmartBot
|
|
246
247
|
#todo: verify if on slack on anytime nick == config[:nick]
|
247
248
|
if nick == config[:nick] or nick == (config[:nick] + " · Bot") #if message is coming from the bot
|
248
249
|
begin
|
249
|
-
@logger.info "#{nick}: #{text}"
|
250
250
|
case text
|
251
251
|
when /^Bot has been killed by/
|
252
|
+
@logger.info "#{nick}: #{text}"
|
252
253
|
exit!
|
253
254
|
when /^Changed status on (.+) to :(.+)/i
|
254
|
-
|
255
|
+
channel_name = $1
|
255
256
|
status = $2
|
256
|
-
|
257
|
-
|
258
|
-
|
257
|
+
if ON_MASTER_BOT or CHANNEL == channel_name
|
258
|
+
@bots_created[@channels_id[channel_name]][:status] = status.to_sym
|
259
|
+
update_bots_file()
|
260
|
+
if CHANNEL == channel_name
|
261
|
+
@logger.info "#{nick}: #{text}"
|
262
|
+
else #on master bot
|
263
|
+
@logger.info "Changed status on #{channel_name} to :#{status}"
|
264
|
+
end
|
265
|
+
end
|
259
266
|
end
|
260
267
|
return :next #don't continue analyzing
|
261
268
|
rescue Exception => stack
|
@@ -291,6 +298,7 @@ class SlackSmartBot
|
|
291
298
|
begin
|
292
299
|
t = Thread.new do
|
293
300
|
begin
|
301
|
+
done = false
|
294
302
|
processed = process(user, command, dest, dchannel)
|
295
303
|
@logger.info "command: #{nick}> #{command}" if processed
|
296
304
|
on_demand = false
|
@@ -316,21 +324,28 @@ class SlackSmartBot
|
|
316
324
|
end
|
317
325
|
end
|
318
326
|
if @bots_created.key?(@rules_imported[user.id][dchannel])
|
319
|
-
|
327
|
+
if @bots_created[@rules_imported[user.id][dchannel]][:status] == :on
|
328
|
+
rules_file = @bots_created[@rules_imported[user.id][dchannel]][:rules_file]
|
329
|
+
else
|
330
|
+
respond 'The bot on that channel is not :on', dest
|
331
|
+
done = true
|
332
|
+
end
|
320
333
|
end
|
321
334
|
end
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
335
|
+
unless done
|
336
|
+
begin
|
337
|
+
eval(File.new(rules_file).read) if File.exist?(rules_file)
|
338
|
+
rescue Exception => stack
|
339
|
+
@logger.fatal "ERROR ON RULES FILE: #{rules_file}"
|
340
|
+
@logger.fatal stack
|
341
|
+
end
|
342
|
+
if defined?(rules)
|
343
|
+
command[0] = "" if command[0] == "!"
|
344
|
+
command.gsub!(/^@\w+:*\s*/, "")
|
345
|
+
rules(user, command, processed, dest)
|
346
|
+
else
|
347
|
+
@logger.warn "It seems like rules method is not defined"
|
348
|
+
end
|
334
349
|
end
|
335
350
|
elsif @rules_imported.key?(user.id) and @rules_imported[user.id].key?(user.id)
|
336
351
|
unless @bots_created.key?(@rules_imported[user.id][user.id])
|
@@ -341,21 +356,28 @@ class SlackSmartBot
|
|
341
356
|
end
|
342
357
|
|
343
358
|
if @bots_created.key?(@rules_imported[user.id][user.id])
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
359
|
+
if @bots_created[@rules_imported[user.id][user.id]][:status] == :on
|
360
|
+
rules_file = @bots_created[@rules_imported[user.id][user.id]][:rules_file]
|
361
|
+
begin
|
362
|
+
eval(File.new(rules_file).read) if File.exist?(rules_file)
|
363
|
+
rescue Exception => stack
|
364
|
+
@logger.fatal "ERROR ON imported RULES FILE: #{rules_file}"
|
365
|
+
@logger.fatal stack
|
366
|
+
end
|
367
|
+
else
|
368
|
+
respond "The bot on <##{@rules_imported[user.id][user.id]}|#{@bots_created[@rules_imported[user.id][user.id]][:channel_name]}> is not :on", dest
|
369
|
+
done = true
|
350
370
|
end
|
351
371
|
end
|
352
372
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
373
|
+
unless done
|
374
|
+
if defined?(rules)
|
375
|
+
command[0] = "" if command[0] == "!"
|
376
|
+
command.gsub!(/^@\w+:*\s*/, "")
|
377
|
+
rules(user, command, processed, dest)
|
378
|
+
else
|
379
|
+
@logger.warn "It seems like rules method is not defined"
|
380
|
+
end
|
359
381
|
end
|
360
382
|
else
|
361
383
|
@logger.info "it is a direct message with no rules file selected so no rules file executed."
|
@@ -470,8 +492,7 @@ class SlackSmartBot
|
|
470
492
|
respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
|
471
493
|
@status = :on
|
472
494
|
unless ON_MASTER_BOT
|
473
|
-
|
474
|
-
send_msg_channel @channels_name[MASTER_CHANNEL], "Changed status on #{@channels_name[CHANNEL]} to :on"
|
495
|
+
send_msg_channel MASTER_CHANNEL, "Changed status on #{CHANNEL} to :on"
|
475
496
|
end
|
476
497
|
else
|
477
498
|
respond "Only admin users can change my status", dest
|
@@ -489,8 +510,7 @@ class SlackSmartBot
|
|
489
510
|
respond "zZzzzzZzzzzZZZZZZzzzzzzzz", dest
|
490
511
|
@status = :paused
|
491
512
|
unless ON_MASTER_BOT
|
492
|
-
|
493
|
-
send_msg_channel @channels_name[MASTER_CHANNEL], "Changed status on #{@channels_name[CHANNEL]} to :paused"
|
513
|
+
send_msg_channel MASTER_CHANNEL, "Changed status on #{CHANNEL} to :paused"
|
494
514
|
end
|
495
515
|
else
|
496
516
|
respond "Only admin users can put me on pause", dest
|
@@ -564,6 +584,7 @@ class SlackSmartBot
|
|
564
584
|
end
|
565
585
|
channels = wclient.channels_list.channels
|
566
586
|
channel_found = channels.detect { |c| c.name == channel }
|
587
|
+
members = wclient.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
567
588
|
|
568
589
|
if channel_id.nil?
|
569
590
|
respond "There is no channel with that name: #{channel}, please be sure is written exactly the same", dest
|
@@ -571,7 +592,7 @@ class SlackSmartBot
|
|
571
592
|
respond "There is already a bot in this channel: #{channel}", dest
|
572
593
|
elsif @bots_created.keys.include?(channel_id)
|
573
594
|
respond "There is already a bot in this channel: #{channel}, kill it before", dest
|
574
|
-
elsif config[:nick_id] != channel_found.creator and !
|
595
|
+
elsif config[:nick_id] != channel_found.creator and !members.include?(config[:nick_id])
|
575
596
|
respond "You need to add first to the channel the smart bot user: #{config[:nick]}", dest
|
576
597
|
else
|
577
598
|
if channel_id != config[:channel]
|
@@ -670,12 +691,18 @@ class SlackSmartBot
|
|
670
691
|
channel = $2
|
671
692
|
channels = wclient.channels_list.channels
|
672
693
|
channel_found = channels.detect { |c| c.name == channel }
|
694
|
+
members = wclient.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
695
|
+
|
673
696
|
if channel_found.nil?
|
674
697
|
respond "The channel you are trying to use doesn't exist", dest
|
675
698
|
elsif channel_found.name == MASTER_CHANNEL
|
676
699
|
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
700
|
+
elsif !@bots_created.key?(@channels_id[channel])
|
701
|
+
respond "There is no bot running on that channel.", dest
|
702
|
+
elsif @bots_created.key?(@channels_id[channel]) and @bots_created[@channels_id[channel]][:status] != :on
|
703
|
+
respond "The bot in that channel is not :on", dest
|
677
704
|
else
|
678
|
-
if user.id == channel_found.creator or
|
705
|
+
if user.id == channel_found.creator or members.include?(user.id)
|
679
706
|
@rules_imported[user.id] = {} unless @rules_imported.key?(user.id)
|
680
707
|
if dest[0] == "C" #todo: take in consideration bots that are not master
|
681
708
|
@rules_imported[user.id][dchannel] = channel_found.id
|
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: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|