slack-smart-bot 0.8.1 → 0.8.2
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.
- checksums.yaml +4 -4
- data/README.md +2 -7
- data/lib/slack-smart-bot.rb +252 -193
- data/lib/slack-smart-bot_rules.rb +4 -3
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1750567f74fe728f40a4c8ec8699d6a21844d72faf0299a841a5c161a4fa4616
|
4
|
+
data.tar.gz: 3fd9575a4e00fb2e7860ade60dc45d821c20450e470cb94caa66e655e2b262ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a571a4d625efc505fe30e279308bf925f5050bb0f9dd691aff351ba83871272dea0564a334a98bb6e930db981a7fdaca4cd7edbd6cadf682ca04065af8ddbf3a
|
7
|
+
data.tar.gz: 1a5ff7c6f770696818646c4a148e3e036565376f5d27f0ffc9205df1c58b5273442f31a3da5adc4cc4546fa1cd81b28084db360cfb4da551492ddd38528b93cf
|
data/README.md
CHANGED
@@ -274,22 +274,19 @@ Apart of the specific commands you define on the rules file of the channel, you
|
|
274
274
|
|
275
275
|
>It will display the shortcuts stored for the user and for :all
|
276
276
|
|
277
|
-
**_`id channel CHANNEL_NAME`_**
|
278
|
-
>shows the id of a channel name
|
279
|
-
|
280
277
|
**_`use rules from CHANNEL`_**
|
281
278
|
|
282
279
|
>it will use the rules from the specified channel.
|
283
280
|
|
284
281
|
>you need to be part of that channel to be able to use the rules.
|
285
282
|
|
286
|
-
>only when on a private conversation
|
283
|
+
>only when on a private conversation.
|
287
284
|
|
288
285
|
**_`stop using rules from CHANNEL`_**
|
289
286
|
|
290
287
|
>it will stop using the rules from the specified channel.
|
291
288
|
|
292
|
-
>only when on a private conversation
|
289
|
+
>only when on a private conversation.
|
293
290
|
|
294
291
|
**_`extend rules to CHANNEL_NAME`_**
|
295
292
|
|
@@ -305,8 +302,6 @@ Apart of the specific commands you define on the rules file of the channel, you
|
|
305
302
|
### Available commands from channels without a Smart Bot
|
306
303
|
**_`@BOT_NAME on #CHANNEL_NAME COMMAND`_**
|
307
304
|
|
308
|
-
**_`@BOT_NAME #CHANNEL_NAME COMMAND`_**
|
309
|
-
|
310
305
|
>It will run the supplied command using the rules on the channel supplied.
|
311
306
|
|
312
307
|
>You need to join the specified channel to be able to use those rules.
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -29,6 +29,7 @@ SHORTCUTS_FILE = "slack-smart-bot_shortcuts_#{CHANNEL}.rb".gsub(" ", "_")
|
|
29
29
|
|
30
30
|
class SlackSmartBot
|
31
31
|
attr_accessor :config, :client
|
32
|
+
attr_reader :master_bot_id, :channel_id
|
32
33
|
VERSION = Gem.loaded_specs.values.select { |x| x.name == "slack-smart-bot" }[0].version.to_s
|
33
34
|
|
34
35
|
def initialize(config)
|
@@ -112,6 +113,8 @@ class SlackSmartBot
|
|
112
113
|
@channels_id = Hash.new()
|
113
114
|
@channels_name = Hash.new()
|
114
115
|
get_channels_name_and_id()
|
116
|
+
@channel_id = @channels_id[CHANNEL].dup
|
117
|
+
@master_bot_id = @channels_id[MASTER_CHANNEL].dup
|
115
118
|
|
116
119
|
client.on :close do |_data|
|
117
120
|
m = "Connection closing, exiting. #{Time.now}"
|
@@ -197,63 +200,106 @@ class SlackSmartBot
|
|
197
200
|
end
|
198
201
|
#todo: sometimes data.user is nil, check the problem.
|
199
202
|
@logger.warn "!dest is nil. user: #{data.user}, channel: #{data.channel}, message: #{data.text}" if dest.nil?
|
200
|
-
|
201
|
-
|
203
|
+
|
204
|
+
typem = :dont_treat
|
205
|
+
if !dest.nil?
|
206
|
+
if data.text.match(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>\s*:?\s*(.*)/im)
|
207
|
+
channel_rules = $2
|
208
|
+
channel_rules_name = $3
|
209
|
+
#to be treated only on the bot of the requested channel
|
210
|
+
if @channel_id == channel_rules
|
211
|
+
data.text = $4
|
212
|
+
typem = :on_call
|
213
|
+
end
|
214
|
+
|
215
|
+
elsif dest == @master_bot_id
|
216
|
+
if ON_MASTER_BOT #only to be treated on master mot channel
|
217
|
+
typem = :on_master
|
218
|
+
end
|
219
|
+
elsif @bots_created.key?(dest)
|
220
|
+
if @channel_id == dest #only to be treated by the bot on the channel
|
221
|
+
typem = :on_bot
|
222
|
+
end
|
223
|
+
elsif dest[0]=="D" #Direct message
|
224
|
+
if ON_MASTER_BOT #only to be treated by master bot
|
225
|
+
typem = :on_dm
|
226
|
+
end
|
227
|
+
elsif dest[0]=="G" #private group
|
228
|
+
if ON_MASTER_BOT #only to be treated by master bot
|
229
|
+
typem = :on_pg
|
230
|
+
end
|
231
|
+
elsif dest[0]=='C'
|
232
|
+
#only to be treated on the channel of the bot. excluding running ruby
|
233
|
+
if !ON_MASTER_BOT and @bots_created[@channel_id][:extended].include?(@channels_name[dest]) and
|
234
|
+
!data.text.match?(/^!?\s*(ruby|code)\s+/)
|
235
|
+
typem = :on_extended
|
236
|
+
elsif ON_MASTER_BOT and data.text.match?(/^!?\s*(ruby|code)\s+/) #or in case of running ruby, the master bot
|
237
|
+
@bots_created.each do |k,v|
|
238
|
+
if v.key?(:extended) and v[:extended].include?(@channels_name[dest])
|
239
|
+
typem = :on_extended
|
240
|
+
break
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
unless typem == :dont_treat
|
202
248
|
begin
|
249
|
+
command = data.text
|
250
|
+
|
203
251
|
#todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
|
204
252
|
user_info = client.web_client.users_info(user: data.user)
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
253
|
+
|
254
|
+
#when added special characters on the message
|
255
|
+
if command.size >= 2 and
|
256
|
+
((command[0] == "`" and command[-1] == "`") or (command[0] == "*" and command[-1] == "*") or (command[0] == "_" and command[-1] == "_"))
|
257
|
+
command = command[1..-2]
|
209
258
|
end
|
259
|
+
|
260
|
+
#ruby file attached
|
210
261
|
if !data.files.nil? and data.files.size == 1 and
|
211
|
-
(
|
212
|
-
(
|
262
|
+
(command.match?(/^(ruby|code)\s*$/) or (command.match?(/^\s*$/) and data.files[0].filetype == "ruby") or
|
263
|
+
(typem==:on_call and data.files[0].filetype == "ruby"))
|
213
264
|
res = Faraday.new("https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }).get(data.files[0].url_private)
|
214
|
-
|
265
|
+
command = "#{command} ruby #{res.body.to_s.force_encoding("UTF-8")}"
|
215
266
|
end
|
216
267
|
|
217
|
-
if
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
268
|
+
if typem == :on_call
|
269
|
+
command = "!" + command unless command[0] == "!" or command.match?(/^\s*$/)
|
270
|
+
|
271
|
+
channels = client.web_client.channels_list.channels
|
272
|
+
channel_found = channels.detect { |c| c.name == channel_rules_name }
|
273
|
+
members = client.web_client.conversations_members(channel: @channels_id[channel_rules_name]).members unless channel_found.nil?
|
274
|
+
if channel_found.nil?
|
275
|
+
@logger.fatal "Not possible to find the channel #{channel_rules_name}"
|
276
|
+
elsif channel_found.name == MASTER_CHANNEL
|
277
|
+
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
278
|
+
elsif @status != :on
|
279
|
+
respond "The bot in that channel is not :on", dest
|
280
|
+
elsif data.user == channel_found.creator or members.include?(data.user)
|
281
|
+
res = process_first(user_info.user, command, dest, channel_rules, typem)
|
282
|
+
else
|
283
|
+
respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
|
224
284
|
end
|
225
285
|
|
226
|
-
command = "!" + command unless command[0] == "!"
|
227
|
-
|
228
|
-
if @channels_id[CHANNEL] == channel_rules #to be treated only on the bot of the requested channel
|
229
|
-
dest = data.channel
|
230
|
-
|
231
|
-
channels = client.web_client.channels_list.channels
|
232
|
-
channel_found = channels.detect { |c| c.name == channel_rules_name }
|
233
|
-
members = client.web_client.conversations_members(channel: @channels_id[channel_rules_name]).members unless channel_found.nil?
|
234
|
-
if channel_found.nil?
|
235
|
-
@logger.fatal "Not possible to find the channel #{channel_rules_name}"
|
236
|
-
elsif channel_found.name == MASTER_CHANNEL
|
237
|
-
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
238
|
-
elsif @status != :on
|
239
|
-
respond "The bot in that channel is not :on", dest
|
240
|
-
elsif data.user == channel_found.creator or members.include?(data.user)
|
241
|
-
res = process_first(user_info.user, command, dest, channel_rules)
|
242
|
-
else
|
243
|
-
respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
|
244
|
-
end
|
245
|
-
end
|
246
286
|
elsif @questions.keys.include?(user_info.user.name)
|
247
287
|
#todo: @questions key should be the id not the name. change it everywhere
|
248
288
|
dest = data.channel
|
249
|
-
res = process_first(user_info.user,
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
289
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
290
|
+
|
291
|
+
elsif ON_MASTER_BOT and typem ==:on_extended and
|
292
|
+
command.size > 0 and command[0] != "-"
|
293
|
+
# to run ruby only from the master bot for the case more than one extended
|
294
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
295
|
+
|
296
|
+
elsif !ON_MASTER_BOT and @bots_created[@channel_id].key?(:extended) and
|
297
|
+
@bots_created[@channel_id][:extended].include?(@channels_name[data.channel]) and
|
298
|
+
command.size > 0 and command[0] != "-"
|
299
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
300
|
+
elsif (dest[0] == "D" or @channel_id == data.channel or data.user == config[:nick_id]) and
|
301
|
+
command.size > 0 and command[0] != "-"
|
302
|
+
res = process_first(user_info.user, command, dest, data.channel, typem)
|
257
303
|
# if @botname on #channel_rules: do something
|
258
304
|
end
|
259
305
|
rescue Exception => stack
|
@@ -266,11 +312,14 @@ class SlackSmartBot
|
|
266
312
|
client.start!
|
267
313
|
end
|
268
314
|
|
269
|
-
def process_first(user, text, dest, dchannel)
|
315
|
+
def process_first(user, text, dest, dchannel, typem)
|
270
316
|
nick = user.name
|
271
317
|
rules_file = ""
|
272
318
|
|
273
|
-
if
|
319
|
+
if typem == :on_call
|
320
|
+
rules_file = RULES_FILE
|
321
|
+
|
322
|
+
elsif dest[0] == "C" or dest[0] == "G" # on a channel or private channel
|
274
323
|
rules_file = RULES_FILE
|
275
324
|
|
276
325
|
if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(dchannel)
|
@@ -337,7 +386,7 @@ class SlackSmartBot
|
|
337
386
|
elsif @shortcuts.keys.include?(:all) and @shortcuts[:all].keys.include?(command)
|
338
387
|
text = @shortcuts[:all][command].dup
|
339
388
|
else
|
340
|
-
respond "Shortcut not found", dest
|
389
|
+
respond "Shortcut not found", dest unless dest[0]=="C" and dchannel != dest #on extended channel
|
341
390
|
return :next
|
342
391
|
end
|
343
392
|
text = "!" + text if addexcl and text[0] != "!"
|
@@ -352,7 +401,7 @@ class SlackSmartBot
|
|
352
401
|
begin
|
353
402
|
t = Thread.new do
|
354
403
|
begin
|
355
|
-
processed = process(user, command, dest, dchannel, rules_file)
|
404
|
+
processed = process(user, command, dest, dchannel, rules_file, typem)
|
356
405
|
@logger.info "command: #{nick}> #{command}" if processed
|
357
406
|
on_demand = false
|
358
407
|
if command.match(/^@?(#{config[:nick]}):*\s+(.+)/im) or
|
@@ -361,20 +410,15 @@ class SlackSmartBot
|
|
361
410
|
command = $2
|
362
411
|
on_demand = true
|
363
412
|
end
|
364
|
-
if dest[0]=="C" and dchannel != dest # on extended channel only specific rules
|
365
|
-
only_on_demand = true
|
366
|
-
else
|
367
|
-
only_on_demand = false
|
368
|
-
end
|
369
413
|
if @status == :on and
|
370
414
|
(@questions.keys.include?(nick) or
|
371
|
-
(@listening.include?(nick) and
|
415
|
+
(@listening.include?(nick) and typem!=:on_extended) or
|
372
416
|
dest[0] == "D" or on_demand)
|
373
417
|
@logger.info "command: #{nick}> #{command}" unless processed
|
374
418
|
#todo: verify this
|
375
419
|
|
376
|
-
if dest[0] == "C" or dest[0] == "G"
|
377
|
-
if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(dchannel)
|
420
|
+
if dest[0] == "C" or dest[0] == "G" or (dest[0]=="D" and typem==:on_call)
|
421
|
+
if typem!=:on_call and @rules_imported.key?(user.id) and @rules_imported[user.id].key?(dchannel)
|
378
422
|
if @bots_created.key?(@rules_imported[user.id][dchannel])
|
379
423
|
if @bots_created[@rules_imported[user.id][dchannel]][:status] != :on
|
380
424
|
respond "The bot on that channel is not :on", dest
|
@@ -442,12 +486,12 @@ class SlackSmartBot
|
|
442
486
|
#help:
|
443
487
|
#help: *General commands:*
|
444
488
|
#help:
|
445
|
-
def process(user, command, dest, dchannel, rules_file)
|
489
|
+
def process(user, command, dest, dchannel, rules_file, typem)
|
446
490
|
from = user.name
|
447
491
|
firstname = from.split(/ /).first
|
448
492
|
processed = true
|
449
493
|
|
450
|
-
|
494
|
+
if typem == :on_master or typem == :on_bot or typem ==:on_pg or typem == :on_dm
|
451
495
|
case command
|
452
496
|
|
453
497
|
#help: ----------------------------------------------
|
@@ -541,7 +585,7 @@ class SlackSmartBot
|
|
541
585
|
|
542
586
|
#help: ===================================
|
543
587
|
#help:
|
544
|
-
#help: *These commands will run only when on a private conversation with the bot
|
588
|
+
#help: *These commands will run only when on a private conversation with the bot:*
|
545
589
|
#help:
|
546
590
|
#help: ----------------------------------------------
|
547
591
|
#help: `use rules from CHANNEL`
|
@@ -869,10 +913,8 @@ class SlackSmartBot
|
|
869
913
|
else
|
870
914
|
processed = false
|
871
915
|
end
|
872
|
-
only_on_demand = false
|
873
916
|
else
|
874
917
|
processed = false
|
875
|
-
only_on_demand = true
|
876
918
|
end
|
877
919
|
|
878
920
|
on_demand = false
|
@@ -886,8 +928,8 @@ class SlackSmartBot
|
|
886
928
|
#only when :on and (listening or on demand or direct message)
|
887
929
|
if @status == :on and
|
888
930
|
(@questions.keys.include?(from) or
|
889
|
-
(@listening.include?(from) and
|
890
|
-
|
931
|
+
(@listening.include?(from) and typem!=:on_extended) or
|
932
|
+
typem == :on_dm or typem ==:on_pg or on_demand)
|
891
933
|
processed2 = true
|
892
934
|
|
893
935
|
#help: ===================================
|
@@ -900,10 +942,12 @@ class SlackSmartBot
|
|
900
942
|
case command
|
901
943
|
|
902
944
|
when /^bot\s+rules$/i
|
903
|
-
if
|
945
|
+
if typem == :on_extended or typem == :on_call #for the other cases above.
|
904
946
|
help_message_rules = ''
|
905
947
|
message = "-\n\n\n===================================\n*Rules from channel <##{@channels_id[CHANNEL]}>*\n"
|
906
|
-
|
948
|
+
if typem == :on_extended
|
949
|
+
message += "To run the commands on this extended channel, add `!` before the command.\n"
|
950
|
+
end
|
907
951
|
help_message_rules = IO.readlines(rules_file).join
|
908
952
|
message += help_message_rules.scan(/#\s*help\s*:(.*)/).join("\n")
|
909
953
|
respond message, dest
|
@@ -929,64 +973,68 @@ class SlackSmartBot
|
|
929
973
|
#helpadmin:
|
930
974
|
when /^extend\s+rules\s+(to\s+)<#C\w+\|(.+)>/i, /^extend\s+rules\s+(to\s+)(.+)/i,
|
931
975
|
/^use\s+rules\s+(on\s+)<#C\w+\|(.+)>/i, /^use\s+rules\s+(on\s+)(.+)/i
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
channel = $2
|
938
|
-
channels = client.web_client.channels_list.channels
|
939
|
-
channel_found = channels.detect { |c| c.name == channel }
|
940
|
-
members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
941
|
-
get_bots_created()
|
942
|
-
channels_in_use = []
|
943
|
-
@bots_created.each do |k,v|
|
944
|
-
if v.key?(:extended) and v[:extended].include?(channel)
|
945
|
-
channels_in_use << v[:channel_name]
|
946
|
-
end
|
947
|
-
end
|
948
|
-
|
949
|
-
if channel_found.nil?
|
950
|
-
respond "The channel you specified doesn't exist", dest
|
951
|
-
elsif @bots_created.key?(@channels_id[channel])
|
952
|
-
respond "There is a bot already running on that channel.", dest
|
953
|
-
elsif @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
|
954
|
-
respond "The rules are already extended to that channel.", dest
|
955
|
-
elsif !members.include?(config[:nick_id])
|
956
|
-
respond "You need to add first to the channel the smart bot user: #{config[:nick]}", dest
|
957
|
-
elsif !members.include?(user.id)
|
958
|
-
respond "You need to join that channel first", dest
|
976
|
+
unless typem == :on_extended
|
977
|
+
if ON_MASTER_BOT
|
978
|
+
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
979
|
+
elsif !ADMIN_USERS.include?(from) #not admin
|
980
|
+
respond "Only admins can extend the rules. Admins on this channel: #{ADMIN_USERS}", dest
|
959
981
|
else
|
960
|
-
|
961
|
-
|
982
|
+
channel = $2
|
983
|
+
channels = client.web_client.channels_list.channels
|
984
|
+
channel_found = channels.detect { |c| c.name == channel }
|
985
|
+
members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
|
986
|
+
get_bots_created()
|
987
|
+
channels_in_use = []
|
988
|
+
@bots_created.each do |k,v|
|
989
|
+
if v.key?(:extended) and v[:extended].include?(channel)
|
990
|
+
channels_in_use << v[:channel_name]
|
991
|
+
end
|
992
|
+
end
|
993
|
+
|
994
|
+
if channel_found.nil?
|
995
|
+
respond "The channel you specified doesn't exist", dest
|
996
|
+
elsif @bots_created.key?(@channels_id[channel])
|
997
|
+
respond "There is a bot already running on that channel.", dest
|
998
|
+
elsif @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
|
999
|
+
respond "The rules are already extended to that channel.", dest
|
1000
|
+
elsif !members.include?(config[:nick_id])
|
1001
|
+
respond "You need to add first to the channel the smart bot user: #{config[:nick]}", dest
|
1002
|
+
elsif !members.include?(user.id)
|
1003
|
+
respond "You need to join that channel first", dest
|
1004
|
+
else
|
1005
|
+
channels_in_use.each do |channel_in_use|
|
1006
|
+
respond "The rules from channel <##{@channels_id[channel_in_use]}> are already in use on that channel", dest
|
1007
|
+
end
|
1008
|
+
@bots_created[@channels_id[CHANNEL]][:extended] = [] unless @bots_created[@channels_id[CHANNEL]].key?(:extended)
|
1009
|
+
@bots_created[@channels_id[CHANNEL]][:extended] << channel
|
1010
|
+
update_bots_file()
|
1011
|
+
respond "Now the rules from <##{@channels_id[CHANNEL]}> are available on <##{@channels_id[channel]}>", dest
|
1012
|
+
respond "<@#{user.id}> extended the rules from <##{@channels_id[CHANNEL]}> to this channel so now you can talk to the Smart Bot on demand using those rules.", @channels_id[channel]
|
1013
|
+
respond "Use `!` before the command you want to run", @channels_id[channel]
|
1014
|
+
respond "To see the specific rules for this bot on this channel: `!bot rules`", @channels_id[channel]
|
962
1015
|
end
|
963
|
-
@bots_created[@channels_id[CHANNEL]][:extended] = [] unless @bots_created[@channels_id[CHANNEL]].key?(:extended)
|
964
|
-
@bots_created[@channels_id[CHANNEL]][:extended] << channel
|
965
|
-
update_bots_file()
|
966
|
-
respond "Now the rules from <##{@channels_id[CHANNEL]}> are available on <##{@channels_id[channel]}>", dest
|
967
|
-
respond "<@#{user.id}> extended the rules from <##{@channels_id[CHANNEL]}> to this channel so now you can talk to the Smart Bot on demand using those rules.", @channels_id[channel]
|
968
|
-
respond "Use `!` before the command you want to run", @channels_id[channel]
|
969
|
-
respond "To see the specific rules for this bot on this channel: `!bot rules`", @channels_id[channel]
|
970
1016
|
end
|
971
1017
|
end
|
972
1018
|
|
973
|
-
#
|
974
|
-
#
|
975
|
-
#
|
976
|
-
#
|
1019
|
+
#helpadmin: ----------------------------------------------
|
1020
|
+
#helpadmin: `stop using rules on CHANNEL_NAME`
|
1021
|
+
#helpadmin: it will stop using the extended rules on the specified channel.
|
1022
|
+
#helpadmin:
|
977
1023
|
when /^stop using rules (on\s+)<#C\w+\|(.+)>/i, /^stop using rules (on\s+)(.+)/i
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
channel = $2
|
982
|
-
get_bots_created()
|
983
|
-
if @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
|
984
|
-
@bots_created[@channels_id[CHANNEL]][:extended].delete(channel)
|
985
|
-
update_bots_file()
|
986
|
-
respond "The rules won't be accessible from <##{@channels_id[CHANNEL]}> from now on.", dest
|
987
|
-
respond "<@#{user.id}> removed the access to the rules of <##{@channels_id[CHANNEL]}> from this channel.", @channels_id[channel]
|
1024
|
+
unless typem == :on_extended
|
1025
|
+
if !ADMIN_USERS.include?(from) #not admin
|
1026
|
+
respond "Only admins can extend or stop using the rules. Admins on this channel: #{ADMIN_USERS}", dest
|
988
1027
|
else
|
989
|
-
|
1028
|
+
channel = $2
|
1029
|
+
get_bots_created()
|
1030
|
+
if @bots_created[@channels_id[CHANNEL]][:extended].include?(channel)
|
1031
|
+
@bots_created[@channels_id[CHANNEL]][:extended].delete(channel)
|
1032
|
+
update_bots_file()
|
1033
|
+
respond "The rules won't be accessible from <##{@channels_id[CHANNEL]}> from now on.", dest
|
1034
|
+
respond "<@#{user.id}> removed the access to the rules of <##{@channels_id[CHANNEL]}> from this channel.", @channels_id[channel]
|
1035
|
+
else
|
1036
|
+
respond "The rules were not accessible from <##{@channels_id[channel]}>", dest
|
1037
|
+
end
|
990
1038
|
end
|
991
1039
|
end
|
992
1040
|
|
@@ -1007,37 +1055,39 @@ class SlackSmartBot
|
|
1007
1055
|
#help: _Spanish Account_
|
1008
1056
|
#help:
|
1009
1057
|
when /^(add\s)?shortcut\s(for\sall)?\s*(.+)\s*:\s*(.+)/i, /^(add\s)sc\s(for\sall)?\s*(.+)\s*:\s*(.+)/i
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
#are you sure? to avoid overwriting existing
|
1026
|
-
unless @questions.keys.include?(from)
|
1027
|
-
ask("The shortcut already exists, are you sure you want to overwrite it?", command, from, dest)
|
1058
|
+
unless typem == :on_extended
|
1059
|
+
for_all = $2
|
1060
|
+
shortcut_name = $3.to_s.downcase
|
1061
|
+
command_to_run = $4
|
1062
|
+
@shortcuts[from] = Hash.new() unless @shortcuts.keys.include?(from)
|
1063
|
+
|
1064
|
+
if !ADMIN_USERS.include?(from) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[from].include?(shortcut_name)
|
1065
|
+
respond "Only the creator of the shortcut or an admin user can modify it", dest
|
1066
|
+
elsif !@shortcuts[from].include?(shortcut_name)
|
1067
|
+
#new shortcut
|
1068
|
+
@shortcuts[from][shortcut_name] = command_to_run
|
1069
|
+
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
1070
|
+
update_shortcuts_file()
|
1071
|
+
respond "shortcut added", dest
|
1028
1072
|
else
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
update_shortcuts_file()
|
1034
|
-
respond "shortcut added", dest
|
1035
|
-
@questions.delete(from)
|
1036
|
-
when /^no/i
|
1037
|
-
respond "ok, I won't add it", dest
|
1038
|
-
@questions.delete(from)
|
1073
|
+
|
1074
|
+
#are you sure? to avoid overwriting existing
|
1075
|
+
unless @questions.keys.include?(from)
|
1076
|
+
ask("The shortcut already exists, are you sure you want to overwrite it?", command, from, dest)
|
1039
1077
|
else
|
1040
|
-
|
1078
|
+
case @questions[from]
|
1079
|
+
when /^(yes|yep)/i
|
1080
|
+
@shortcuts[from][shortcut_name] = command_to_run
|
1081
|
+
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
1082
|
+
update_shortcuts_file()
|
1083
|
+
respond "shortcut added", dest
|
1084
|
+
@questions.delete(from)
|
1085
|
+
when /^no/i
|
1086
|
+
respond "ok, I won't add it", dest
|
1087
|
+
@questions.delete(from)
|
1088
|
+
else
|
1089
|
+
respond "I don't understand, yes or no?", dest
|
1090
|
+
end
|
1041
1091
|
end
|
1042
1092
|
end
|
1043
1093
|
end
|
@@ -1048,34 +1098,36 @@ class SlackSmartBot
|
|
1048
1098
|
#help: It will delete the shortcut with the supplied name
|
1049
1099
|
#help:
|
1050
1100
|
when /^delete\s+shortcut\s+(.+)/i, /^delete\s+sc\s+(.+)/i
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
case @questions[from]
|
1063
|
-
when /^(yes|yep)/i
|
1064
|
-
respond "shortcut deleted!", dest
|
1065
|
-
respond "#{shortcut}: #{@shortcuts[from][shortcut]}", dest
|
1066
|
-
@shortcuts[from].delete(shortcut)
|
1067
|
-
@shortcuts[:all].delete(shortcut)
|
1068
|
-
@questions.delete(from)
|
1069
|
-
update_shortcuts_file()
|
1070
|
-
when /^no/i
|
1071
|
-
respond "ok, I won't delete it", dest
|
1072
|
-
@questions.delete(from)
|
1101
|
+
unless typem == :on_extended
|
1102
|
+
shortcut = $1.to_s.downcase
|
1103
|
+
deleted = false
|
1104
|
+
|
1105
|
+
if !ADMIN_USERS.include?(from) and @shortcuts[:all].include?(shortcut) and !@shortcuts[from].include?(shortcut)
|
1106
|
+
respond "Only the creator of the shortcut or an admin user can delete it", dest
|
1107
|
+
elsif (@shortcuts.keys.include?(from) and @shortcuts[from].keys.include?(shortcut)) or
|
1108
|
+
(ADMIN_USERS.include?(from) and @shortcuts[:all].include?(shortcut))
|
1109
|
+
#are you sure? to avoid deleting by mistake
|
1110
|
+
unless @questions.keys.include?(from)
|
1111
|
+
ask("are you sure you want to delete it?", command, from, dest)
|
1073
1112
|
else
|
1074
|
-
|
1113
|
+
case @questions[from]
|
1114
|
+
when /^(yes|yep)/i
|
1115
|
+
respond "shortcut deleted!", dest
|
1116
|
+
respond "#{shortcut}: #{@shortcuts[from][shortcut]}", dest
|
1117
|
+
@shortcuts[from].delete(shortcut)
|
1118
|
+
@shortcuts[:all].delete(shortcut)
|
1119
|
+
@questions.delete(from)
|
1120
|
+
update_shortcuts_file()
|
1121
|
+
when /^no/i
|
1122
|
+
respond "ok, I won't delete it", dest
|
1123
|
+
@questions.delete(from)
|
1124
|
+
else
|
1125
|
+
respond "I don't understand, yes or no?", dest
|
1126
|
+
end
|
1075
1127
|
end
|
1128
|
+
else
|
1129
|
+
respond "shortcut not found", dest
|
1076
1130
|
end
|
1077
|
-
else
|
1078
|
-
respond "shortcut not found", dest
|
1079
1131
|
end
|
1080
1132
|
|
1081
1133
|
#help: ----------------------------------------------
|
@@ -1084,39 +1136,43 @@ class SlackSmartBot
|
|
1084
1136
|
#help: It will display the shortcuts stored for the user and for :all
|
1085
1137
|
#help:
|
1086
1138
|
when /^see\sshortcuts/i, /^see\ssc/i
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
}
|
1093
|
-
respond msg, dest
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
if @shortcuts.keys.include?(from) and @shortcuts[from].keys.size > 0
|
1097
|
-
new_hash = @shortcuts[from].dup
|
1098
|
-
@shortcuts[:all].keys.each { |k| new_hash.delete(k) }
|
1099
|
-
if new_hash.keys.size > 0
|
1100
|
-
msg = "*Available shortcuts for #{from}:*\n"
|
1101
|
-
new_hash.each { |name, value|
|
1139
|
+
unless typem == :on_extended
|
1140
|
+
msg = ""
|
1141
|
+
if @shortcuts[:all].keys.size > 0
|
1142
|
+
msg = "*Available shortcuts for all:*\n"
|
1143
|
+
@shortcuts[:all].each { |name, value|
|
1102
1144
|
msg += " _#{name}: #{value}_\n"
|
1103
1145
|
}
|
1104
1146
|
respond msg, dest
|
1105
1147
|
end
|
1148
|
+
|
1149
|
+
if @shortcuts.keys.include?(from) and @shortcuts[from].keys.size > 0
|
1150
|
+
new_hash = @shortcuts[from].dup
|
1151
|
+
@shortcuts[:all].keys.each { |k| new_hash.delete(k) }
|
1152
|
+
if new_hash.keys.size > 0
|
1153
|
+
msg = "*Available shortcuts for #{from}:*\n"
|
1154
|
+
new_hash.each { |name, value|
|
1155
|
+
msg += " _#{name}: #{value}_\n"
|
1156
|
+
}
|
1157
|
+
respond msg, dest
|
1158
|
+
end
|
1159
|
+
end
|
1160
|
+
respond "No shortcuts found", dest if msg == ""
|
1106
1161
|
end
|
1107
|
-
respond "No shortcuts found", dest if msg == ""
|
1108
1162
|
|
1109
1163
|
#help: ----------------------------------------------
|
1110
1164
|
#help: `id channel CHANNEL_NAME`
|
1111
1165
|
#help: shows the id of a channel name
|
1112
1166
|
#help:
|
1113
1167
|
when /^id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1168
|
+
unless typem == :on_extended
|
1169
|
+
channel_name = $1
|
1170
|
+
get_channels_name_and_id()
|
1171
|
+
if @channels_id.keys.include?(channel_name)
|
1172
|
+
respond "the id of #{channel_name} is #{@channels_id[channel_name]}", dest
|
1173
|
+
else
|
1174
|
+
respond "channel: #{channel_name} not found", dest
|
1175
|
+
end
|
1120
1176
|
end
|
1121
1177
|
|
1122
1178
|
#help: ----------------------------------------------
|
@@ -1167,9 +1223,12 @@ class SlackSmartBot
|
|
1167
1223
|
else
|
1168
1224
|
respond "Sorry I cannot run this due security reasons", dest
|
1169
1225
|
end
|
1226
|
+
|
1227
|
+
|
1170
1228
|
else
|
1171
1229
|
processed2 = false
|
1172
|
-
end
|
1230
|
+
end #of case
|
1231
|
+
|
1173
1232
|
processed = true if processed or processed2
|
1174
1233
|
end
|
1175
1234
|
|
@@ -108,17 +108,18 @@ def rules(user, command, processed, dest)
|
|
108
108
|
|
109
109
|
# Examples sending a file to slack:
|
110
110
|
# send_file(to, msg, filepath, title, format, type = "text")
|
111
|
-
# send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", '
|
112
|
-
# send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", '
|
111
|
+
# send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'title', 'text/plain', "text")
|
112
|
+
# send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", 'title', 'image/jpeg', "jpg")
|
113
113
|
|
114
114
|
else
|
115
115
|
unless processed
|
116
|
-
if
|
116
|
+
if @channel_id == dest or dest[0]=="D" or dest[0] == "G" #not on extended channels
|
117
117
|
resp = %w{ what huh sorry }.sample
|
118
118
|
respond "#{firstname}: #{resp}?", dest
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
122
123
|
rescue => exception
|
123
124
|
if defined?(@logger)
|
124
125
|
@logger.fatal exception
|
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.8.
|
4
|
+
version: 0.8.2
|
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-08-
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
@@ -34,22 +34,22 @@ dependencies:
|
|
34
34
|
name: async-websocket
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0.8'
|
40
37
|
- - ">="
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: 0.8.0
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.8'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '0.8'
|
50
47
|
- - ">="
|
51
48
|
- !ruby/object:Gem::Version
|
52
49
|
version: 0.8.0
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.8'
|
53
53
|
description: "Create a Slack bot that is smart and so easy to expand, create new bots
|
54
54
|
on demand, run ruby code on chat, create shortcuts... \n The main scope of this
|
55
55
|
gem is to be used internally in the company so teams can create team channels with
|
@@ -89,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.6
|
92
|
+
rubygems_version: 3.0.3
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
95
|
summary: Create a Slack bot that is smart and so easy to expand, create new bots on
|