slack-smart-bot 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +91 -21
  3. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  4. data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
  5. data/lib/slack/smart-bot/comm/get_channel_members.rb +7 -3
  6. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  7. data/lib/slack/smart-bot/comm/get_users.rb +1 -1
  8. data/lib/slack/smart-bot/comm/respond.rb +18 -13
  9. data/lib/slack/smart-bot/comm/send_msg_user.rb +12 -11
  10. data/lib/slack/smart-bot/comm.rb +2 -0
  11. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  12. data/lib/slack/smart-bot/commands/general/add_announcement.rb +1 -1
  13. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  14. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  15. data/lib/slack/smart-bot/commands/general/bot_help.rb +20 -11
  16. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +1 -1
  17. data/lib/slack/smart-bot/commands/general/delete_share.rb +1 -1
  18. data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
  19. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  20. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  21. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  22. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  23. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  24. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  25. data/lib/slack/smart-bot/commands/general/see_announcements.rb +6 -4
  26. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  27. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +3 -4
  28. data/lib/slack/smart-bot/commands/general/see_statuses.rb +34 -21
  29. data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
  30. data/lib/slack/smart-bot/commands/general/share_messages.rb +1 -1
  31. data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
  32. data/lib/slack/smart-bot/commands/general_bot_commands.rb +271 -10
  33. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -1
  34. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +2 -1
  35. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -1
  36. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +2 -1
  37. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +2 -1
  38. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -1
  39. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +3 -2
  40. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +2 -1
  41. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +10 -9
  42. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +2 -1
  43. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +2 -1
  44. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -1
  45. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  46. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  47. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +3 -1
  48. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +15 -2
  49. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -1
  50. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +5 -4
  51. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
  52. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +1 -0
  53. data/lib/slack/smart-bot/commands/{general → on_bot/general}/leaderboard.rb +1 -0
  54. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +1 -0
  55. data/lib/slack/smart-bot/commands/{general → on_bot/general}/suggest_command.rb +6 -0
  56. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +1 -0
  57. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  58. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -1
  59. data/lib/slack/smart-bot/commands/on_bot/repl.rb +72 -15
  60. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +1 -0
  61. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +11 -2
  62. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +2 -1
  63. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +3 -2
  64. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +5 -4
  65. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -2
  66. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
  67. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +3 -2
  68. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +2 -1
  69. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +2 -1
  70. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +1 -0
  71. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  72. data/lib/slack/smart-bot/commands.rb +22 -7
  73. data/lib/slack/smart-bot/listen.rb +30 -30
  74. data/lib/slack/smart-bot/process.rb +38 -18
  75. data/lib/slack/smart-bot/process_first.rb +2 -2
  76. data/lib/slack/smart-bot/treat_message.rb +13 -17
  77. data/lib/slack/smart-bot/utils/build_help.rb +1 -1
  78. data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
  79. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  80. data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
  81. data/lib/slack/smart-bot/utils/get_bots_created.rb +27 -10
  82. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  83. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  84. data/lib/slack/smart-bot/utils/get_help.rb +34 -18
  85. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  86. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  87. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  88. data/lib/slack/smart-bot/utils/has_access.rb +25 -9
  89. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  90. data/lib/slack/smart-bot/utils/save_stats.rb +46 -43
  91. data/lib/slack/smart-bot/utils/save_status.rb +21 -6
  92. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  93. data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
  94. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  95. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  96. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  97. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  98. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  99. data/lib/slack/smart-bot/utils.rb +8 -0
  100. data/lib/slack-smart-bot.rb +28 -10
  101. data/lib/slack-smart-bot_general_commands.rb +16 -1
  102. data/whats_new.txt +16 -29
  103. metadata +64 -19
  104. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -314
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 258161d536cc6c07a7cdbf6e42a91069bc5715fb3b5807f635f4be4754ec6a36
4
- data.tar.gz: 72361374be67be8b22f3dff0465fc03aa9383045d75cc68385ffa401fff8edbd
3
+ metadata.gz: 1e5ea9ccfc9d1c52925f5bdd6ef89c35158c19f8fafad8f5af99d9a6b8456b43
4
+ data.tar.gz: 6c3853c8977a29f85cba5013b06b8178ca6f0b4783ff323fd0fa96d7ad92ad5b
5
5
  SHA512:
6
- metadata.gz: 0bdaabba591af2ef6690d71212a61a170a454f58eeb8424504d743d17f1d5062db808279bd29d6719791ecac141c9c23f29964349f0c8c94fa6a738b09cac4aa
7
- data.tar.gz: 50b5827289fb31fe757a6269eea9d89ee00fb8d2f81f1ed7bbcab0ccdff9114a7a7ff703e97c31fec259e2f65bde93f4b1780765a72d704966ece7d2b251c3c0
6
+ metadata.gz: 8d795ac13cfe68983064894f6fff8e7667cb939a78c9e2a044630aca021a4bd11c2be8a8cf6944fceebe8ea1b4ff5ca2d7455c4eb121edcd28ad8b89605ad4dc
7
+ data.tar.gz: e81573197080798f5cae34521b44744de6912895ba55049611f806059b171f69c5fe2d3bb30e790d1d158b2a06b71c449afcb61f96602fcdd070c240a9298f89
data/README.md CHANGED
@@ -31,8 +31,9 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
31
31
  * [Share Messages](#share-messages)
32
32
  * [See Statuses](#see-statuses)
33
33
  * [Routines](#routines)
34
- * [Limit who has access to a command](#limit-who-has-access-to-a-command)
34
+ * [Control who has access to a command](#control-who-has-access-to-a-command)
35
35
  * [See favorite commands](#see-favorite-commands)
36
+ * [Teams](#teams)
36
37
  * [Tips](#tips)
37
38
  + [Send a file](#send-a-file)
38
39
  + [Download a file](#download-a-file)
@@ -309,6 +310,10 @@ If you are a Master Admin on a Direct Message with the Smart Bot you can call th
309
310
 
310
311
  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.
311
312
 
313
+ You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.
314
+
315
+ To see the full list of available command ids on any channel call: `see command ids`
316
+
312
317
  #### Cloud Bots
313
318
  If you want to create a bot that will be running on a different machine: **_`create cloud bot on CHANNEL`_**. Even though the cloud bots are running on different machines, the management can be done through the MASTER CHANNEL. The new cloud bot will be managed by your Master Bot like the others, closing, pausing...
314
319
 
@@ -435,11 +440,11 @@ You can add any announcement on any channel where the SmartBot is a member by us
435
440
  It will store the message on the announcement list labeled with the color/emoji specified, white by default. Possible colors white, green, yellow and red. Aliases for announcement: statement, declaration, message.
436
441
 
437
442
  Examples:
438
- >**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
439
- >**_Peter>_** `add red message Customers db is down :x:`
440
- >**_Peter>_** `add yellow statement Don't access the linux server without VPN`
441
- >**_Peter>_** `add announcement Party will start at 20:00 :tada:`
442
- >**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
443
+ >**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
444
+ >**_Peter>_** `add red message Customers db is down :x:`
445
+ >**_Peter>_** `add yellow statement Don't access the linux server without VPN`
446
+ >**_Peter>_** `add announcement Party will start at 20:00 :tada:`
447
+ >**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
443
448
 
444
449
  To see the announcements of the channel: **_`see announcements`_**, **_`see COLOR announcements`_**, **_`see EMOJI announcements`_** and to delete a particular announcement: **_`delete announcement ID`_**
445
450
 
@@ -451,8 +456,8 @@ You can automatically share any new message that is posted on the channel and me
451
456
  This command is only available in public channels. The user adding the Share and the SmartBot need to be a member of both channels.
452
457
 
453
458
  Examples:
454
- >**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
455
- >**_Peter>_** `share messages "share post" on #announcements`
459
+ >**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
460
+ >**_Peter>_** `share messages "share post" on #announcements`
456
461
 
457
462
  To see the shares of the channel: **_`see shares`_** and to delete a particular share: **_`delete share ID`_**
458
463
 
@@ -462,11 +467,12 @@ To see a list of statuses of the members in the channel you can call `see status
462
467
  You need to be a member of the channel to be able to get this info.
463
468
 
464
469
  Examples:
465
- >**_Peter>_** `see statuses`
466
- >**_Peter>_** `who is on vacation?`
467
- >**_Peter>_** `who is not on vacation?`
468
- >**_Peter>_** `who is on vacation? #SalesChannel`
469
- >**_Peter>_** `who is on :working-from-home:`
470
+ >**_Peter>_** `see statuses`
471
+ >**_Peter>_** `who is on vacation?`
472
+ >**_Peter>_** `who is not on vacation?`
473
+ >**_Peter>_** `who is on vacation? #SalesChannel`
474
+ >**_Peter>_** `who is on :working-from-home:`
475
+ >**_Peter>_** `who is available?`
470
476
 
471
477
  ### Routines
472
478
  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.
@@ -495,9 +501,13 @@ Other routine commands:
495
501
  * **_`see routines`_**
496
502
  * **_`see result routine NAME`_**
497
503
 
498
- ### Limit who has access to a command
504
+ ### Control who has access to a command
505
+
506
+ You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.
507
+
508
+ To see the full list of available command ids on any channel call: `see command ids`
499
509
 
500
- If you want to define who has access to certain commands you can specify it on the settings when starting the Smart Bot:
510
+ If you want to define who has access to certain commands in all SmartBot instances, you can specify it on the settings when starting the Smart Bot:
501
511
 
502
512
  ```ruby
503
513
  settings = {
@@ -513,16 +523,23 @@ settings = {
513
523
  ```
514
524
  You can use the user name or the user id.
515
525
 
516
- If you want to change who has access to a certain command without restarting the Smart Bot you can do it on the rules file:
526
+ If you want to change who has access to a specific command without restarting the Smart Bot you can do it on the rules file, for example:
517
527
 
518
528
  ```ruby
519
- config.allow_access.repl = ['marioruiz', 'samcooke']
529
+ # helpadmin: ----------------------------------------------
530
+ # helpadmin: `update access`
531
+ # helpadmin: It will update the privileges to access commands or rules
532
+ # helpadmin:
533
+ when /\A\s*update\s+access\s*\z/i
534
+ save_stats(:update_access)
535
+ if is_admin?(user.name)
536
+ config.allow_access.repl = ['marioruiz', 'samcooke']
537
+ respond "updated on <##{@channel_id}>!"
538
+ else
539
+ respond 'Only admins can change the access rules'
540
+ end
520
541
  ```
521
542
 
522
- These are the commands that are possible to be limited plus all your SmartBot rules:
523
-
524
- `bot_help, bot_rules, bot_status, use_rules, add_shortcut, delete_shortcut, repl, run_repl, get_repl, delete_repl, see_repls, ruby_code, see_shortcuts, create_bot, add_announcement, delete_announcement, see_announcements`
525
-
526
543
  To check from a rule if the user has access to it:
527
544
 
528
545
  ```ruby
@@ -530,6 +547,22 @@ if has_access?(:your_command_id)
530
547
  end
531
548
  ```
532
549
 
550
+ Also you can allow or deny access for specific commands and users on any specific channel all you need is the Smartbot to be a member of the channel and use these commands on Slack:
551
+ `allow access COMMAND_ID`
552
+ `allow access COMMAND_ID @user1 @user99`
553
+ It will allow the specified command to be used on the channel.
554
+ If @user specified, only those users will have access to the command
555
+ Only admins of the channel can use this command.
556
+
557
+ `deny access COMMAND_ID`
558
+ It won't allow the specified command to be used on the channel.
559
+ Only admins of the channel can use this command
560
+
561
+ `see access COMMAND_ID`
562
+ it will show the access rights for the specified command
563
+
564
+ The authorization is controlled by `save_stats` so it will be check out when calling `save_stats` or by calling `has_access?(:your_command_id)`
565
+
533
566
  ### See favorite commands
534
567
 
535
568
  It will display the favorite commands in that channel.
@@ -540,6 +573,43 @@ Examples:
540
573
  >**_`my favourite commands`_**
541
574
  >**_`most used commands`_**
542
575
 
576
+ ### Teams
577
+
578
+ You can add, update, see, ping and delete teams. When calling `see TEAM_NAME team` the availability of the members will be displayed.
579
+ `add team TEAM_NAME PROPERTIES` will add a team with the info supplied. In case it is supplied a channel with type 'members' the members of that channel would be considered members of the team.
580
+
581
+ Examples:
582
+ >**_`add team devweb members #devweb support #devweb-support : We take care of the website`_**
583
+ >**_`add team devweb qa @jim dev @johnja @cooke @luisa members #devweb support #devweb-support : We take care of the website`_**
584
+ >**_`add team sandex manager @sarah members #sandex : We take care of the sand`_**
585
+
586
+ By calling `update team` you will update a team with the info supplied.
587
+
588
+ Examples:
589
+ >**_`update team sales : Support for customers`_**
590
+ >**_`update sales team delete @sarah @peter`_**
591
+ >**_`update sales team add public #salesff`_**
592
+ >**_`update sales team add qa @john @ben @ana`_**
593
+
594
+ It is possible to search teams by user, info, channel or team name. In case calling `see team TEAM_NAME` or `TEAM_NAME team` it will show also the availavility of the members: on vacation, in a meeting, sick leave, away or available.
595
+
596
+ Examples:
597
+ >**_`see teams`_**
598
+ >**_`see Sales team`_**
599
+ >**_`which teams #salesff`_**
600
+ >**_`which teams @sarah`_**
601
+ >**_`which team does @john belongs to?`_**
602
+
603
+ By calling `ping team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all available members of the MEMBER_TYPE supplied.
604
+ If you call `contact team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all members of the MEMBER_TYPE supplied.
605
+
606
+ Examples:
607
+ >**_`ping team sales development What's the status on last deployment?`_**
608
+ >**_`contact team sales qa Please finish testing of dev02 feature before noon`_**
609
+
610
+ Other team commands: **_`delete team TEAM_NAME`_**
611
+
612
+
543
613
  ### Tips
544
614
 
545
615
  #### Send a file
@@ -0,0 +1,13 @@
1
+ class SlackSmartBot
2
+ def delete(channel, ts)
3
+ result = true
4
+ begin
5
+ resp = client.web_client.chat_delete(channel: channel, as_user: true, ts: ts)
6
+ result = resp.ok.to_s == 'true'
7
+ rescue Exception => exc
8
+ result = false
9
+ @logger.fatal exc.inspect
10
+ end
11
+ return result
12
+ end
13
+ end
@@ -11,8 +11,8 @@ class SlackSmartBot
11
11
  get_bots_created()
12
12
  end
13
13
  text = get_help(rules_file, dest, user.name, typem==:on_extended, true)
14
-
15
- ff = text.scan(/\s*`\s*([^`]+)\s*`\s*/i).flatten
14
+
15
+ ff = text.scan(/^\s*`\s*([^`]+)\s*`\s*$/i).flatten
16
16
  ff.delete("!THE_COMMAND")
17
17
  ff.delete("@NAME_OF_BOT THE_COMMAND")
18
18
  ff.delete("NAME_OF_BOT THE_COMMAND")
@@ -1,10 +1,14 @@
1
1
  #todo: add pagination for case more than 1000 members in the channel
2
2
  def get_channel_members(channel_id)
3
3
  begin
4
- if config.simulate and config.key?(:client)
5
- client.web_client.conversations_members[channel_id.to_sym].members
4
+ if channel_id.nil?
5
+ return nil
6
6
  else
7
- client.web_client.conversations_members(channel: channel_id, limit: 1000).members
7
+ if config.simulate and config.key?(:client)
8
+ client.web_client.conversations_members[channel_id.to_sym].members
9
+ else
10
+ client.web_client.conversations_members(channel: channel_id, limit: 1000).members
11
+ end
8
12
  end
9
13
  rescue Exception => stack
10
14
  @logger.warn stack
@@ -0,0 +1,20 @@
1
+ class SlackSmartBot
2
+
3
+ def get_presence(user)
4
+ begin
5
+ if user.to_s.length>0
6
+ if config.simulate and config.key?(:client)
7
+ if user[0]=='@' #name
8
+ client.web_client.users_get_presence.select{|k, v| v[:name] == user[1..-1]}.values[-1]
9
+ else #id
10
+ client.web_client.users_get_presence[user.to_sym]
11
+ end
12
+ else
13
+ client.web_client.users_getPresence(user: user)
14
+ end
15
+ end
16
+ rescue Exception => stack
17
+ @logger.warn stack
18
+ end
19
+ end
20
+ end
@@ -9,7 +9,7 @@ class SlackSmartBot
9
9
  else
10
10
  begin
11
11
  resp = client.web_client.users_list(limit: 1000, cursor: cursor)
12
- if resp.key?(:members) and resp[:members].is_a(Array) and resp[:members].size > 0
12
+ if resp.key?(:members) and resp[:members].is_a?(Array) and resp[:members].size > 0
13
13
  users << resp[:members]
14
14
  end
15
15
  cursor = resp.get_values(:next_cursor).values[-1]
@@ -1,6 +1,7 @@
1
1
  class SlackSmartBot
2
- def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false)
2
+ def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false, return_message: false, max_chars_per_message: 4000)
3
3
  result = true
4
+ resp = nil
4
5
  if (msg.to_s != "" or !msg.to_s.match?(/^A\s*\z/) or !blocks.empty?) and Thread.current[:routine_type].to_s != "bgroutine"
5
6
  if !web_client.is_a?(TrueClass) and !web_client.is_a?(FalseClass)
6
7
  (!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
@@ -41,15 +42,18 @@ class SlackSmartBot
41
42
  else
42
43
  wait = 0
43
44
  end
44
-
45
- msgs = [] # max of 4000 characters per message
46
- txt = ""
47
- msg.split("\n").each do |m|
48
- if (m + txt).size > 4000
49
- msgs << txt.chars.each_slice(4000).map(&:join) unless txt == ""
50
- txt = ""
45
+ msgs = [] # max of max_chars_per_message characters per message
46
+ if max_chars_per_message.nil?
47
+ txt = msg
48
+ else
49
+ txt = ""
50
+ msg.split("\n").each do |m|
51
+ if (m + txt).size > max_chars_per_message
52
+ msgs << txt.chars.each_slice(max_chars_per_message).map(&:join) unless txt == ""
53
+ txt = ""
54
+ end
55
+ txt += (m + "\n")
51
56
  end
52
- txt += (m + "\n")
53
57
  end
54
58
  msgs << txt
55
59
  msgs.flatten!
@@ -119,14 +123,14 @@ class SlackSmartBot
119
123
  end
120
124
  elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
121
125
  msgs.each do |msg|
122
- send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
126
+ resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
123
127
  sleep wait
124
128
  end
125
129
  elsif dest[0] == "@"
126
130
  begin
127
131
  user_info = @users.select { |u| u.id == dest[1..-1] or u.name == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
128
132
  msgs.each do |msg|
129
- send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
133
+ resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
130
134
  sleep wait
131
135
  end
132
136
  rescue Exception => stack
@@ -193,14 +197,14 @@ class SlackSmartBot
193
197
  end
194
198
  elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
195
199
  blocks.each_slice(40).to_a.each do |blockstmp|
196
- send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
200
+ resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
197
201
  sleep wait
198
202
  end
199
203
  elsif dest[0] == "@"
200
204
  begin
201
205
  user_info = @users.select { |u| u.id == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
202
206
  blocks.each_slice(40).to_a.each do |blockstmp|
203
- send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
207
+ resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
204
208
  sleep wait
205
209
  end
206
210
  rescue Exception => stack
@@ -225,6 +229,7 @@ class SlackSmartBot
225
229
  if Thread.current.key?(:routine) and Thread.current[:routine]
226
230
  File.write("#{config.path}/routines/#{@channel_id}/#{Thread.current[:routine_name]}_output.txt", msg, mode: "a+")
227
231
  end
232
+ result = resp if return_message
228
233
  return result
229
234
  end
230
235
  end
@@ -1,12 +1,12 @@
1
1
  class SlackSmartBot
2
2
 
3
3
  #to send messages without listening for a response to users
4
- def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [])
4
+ def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [], web_client: true)
5
+ resp = nil
5
6
  unless msg == "" and blocks.empty?
6
7
  begin
7
8
  on_thread = Thread.current[:on_thread] if on_thread.nil?
8
- (!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
9
- web_client = true if !blocks.empty?
9
+ web_client = true if !blocks.empty? or !unfurl_links or !unfurl_media
10
10
  if id_user[0] == "D"
11
11
  if config[:simulate]
12
12
  open("#{config.path}/buffer_complete.log", "a") { |f|
@@ -15,15 +15,15 @@ class SlackSmartBot
15
15
  else
16
16
  if web_client
17
17
  if on_thread
18
- client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
18
+ resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
19
19
  else
20
- client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
20
+ resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
21
21
  end
22
22
  else
23
23
  if on_thread
24
- client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
24
+ resp = client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
25
25
  else
26
- client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
26
+ resp = client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
27
27
  end
28
28
  end
29
29
  end
@@ -42,15 +42,15 @@ class SlackSmartBot
42
42
  im = client.web_client.conversations_open(users: id_user)
43
43
  if web_client
44
44
  if on_thread
45
- client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
45
+ resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
46
46
  else
47
- client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
47
+ resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
48
48
  end
49
49
  else
50
50
  if on_thread
51
- client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
51
+ resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
52
52
  else
53
- client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
53
+ resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
54
54
  end
55
55
  end
56
56
  end
@@ -65,6 +65,7 @@ class SlackSmartBot
65
65
  @logger.warn stack
66
66
  end
67
67
  end
68
+ return resp
68
69
  end
69
70
 
70
71
  end
@@ -13,3 +13,5 @@ require_relative 'comm/get_users'
13
13
  require_relative 'comm/event_hello'
14
14
  require_relative 'comm/get_channel_members'
15
15
  require_relative 'comm/get_channels'
16
+ require_relative 'comm/delete'
17
+ require_relative 'comm/get_presence'
@@ -0,0 +1,51 @@
1
+ class SlackSmartBot
2
+ def add_admin(user, admin_user)
3
+ save_stats(__method__)
4
+ if Thread.current[:dest][0]=='D'
5
+ respond "This command cannot be called from a DM"
6
+ else
7
+ if Thread.current[:typem] == :on_call
8
+ channel = Thread.current[:dchannel]
9
+ elsif Thread.current[:using_channel].to_s==''
10
+ channel = Thread.current[:dest]
11
+ else
12
+ channel = Thread.current[:using_channel]
13
+ end
14
+ messages = []
15
+ admins = config.masters.dup
16
+ channels = get_channels()
17
+ channel_found = channels.detect { |c| c.id == channel }
18
+ if !channel_found.nil? and channel_found.creator.to_s != ''
19
+ creator_info = @users.select{|u| u.id == channel_found.creator or (u.key?(:enterprise_user) and u.enterprise_user.id == channel_found.creator)}[-1]
20
+ admins << creator_info.name
21
+ end
22
+ if Thread.current[:typem] == :on_bot or Thread.current[:typem] == :on_master
23
+ admins << config.admins.dup
24
+ end
25
+ if @admins_channels.key?(channel) and @admins_channels[channel].size > 0
26
+ admins << @admins_channels[channel]
27
+ end
28
+ admins.flatten!
29
+ admins.uniq!
30
+ admins.delete(nil)
31
+ if admins.include?(user.name)
32
+ admin_info = @users.select{|u| u.id == admin_user or (u.key?(:enterprise_user) and u.enterprise_user.id == admin_user)}[-1]
33
+ if admins.include?(admin_info.name)
34
+ messages << "This user is already an admin of this channel."
35
+ else
36
+ @admins_channels[channel] ||= []
37
+ @admins_channels[channel] << admin_info.name
38
+ update_admins_channels()
39
+ messages << "The user is an admin of this channel from now on."
40
+ admins << admin_info.name
41
+ end
42
+ messages << "*Admins*: <@#{admins.join('>, <@')}>"
43
+ else
44
+ messages << "Only the creator of the channel, Master admins or admins can add a new admin for this channel."
45
+ messages << "*Admins*: <@#{admins.join('>, <@')}>"
46
+ end
47
+
48
+ respond messages.join("\n")
49
+ end
50
+ end
51
+ end
@@ -8,7 +8,7 @@ class SlackSmartBot
8
8
  else
9
9
  channel = Thread.current[:dest]
10
10
  end
11
- if File.exists?("#{config.path}/announcements/#{channel}.csv") and !@announcements.key?(channel)
11
+ if File.exist?("#{config.path}/announcements/#{channel}.csv") and !@announcements.key?(channel)
12
12
  t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
13
13
  @announcements[channel] = t
14
14
  num = t[:message_id].max + 1
@@ -0,0 +1,80 @@
1
+ class SlackSmartBot
2
+ def add_team(user, name, options, info)
3
+ save_stats(__method__)
4
+
5
+ get_teams()
6
+ if @teams.key?(name.to_sym)
7
+ respond "It seems like the team *#{name}* already exists.\nRelated commands `update team TEAM_NAME PROPERTIES`, `delete team TEAM_NAME`, `see team TEAM_NAME`, `see teams`"
8
+ else
9
+ wrong = false
10
+ team = { members: {}, channels: {} }
11
+ last_type = nil
12
+ type_detected = false
13
+ options.split(/\s+/).each do |opt|
14
+ type_detected = false
15
+ if opt.match?(/^\s*$/)
16
+ #blank
17
+ elsif opt.match?(/^[\w\-]+$/i)
18
+ last_type = opt
19
+ type_detected = true
20
+ elsif opt.match(/<@(\w+)>/i)
21
+ team[:members][last_type] ||= []
22
+ if last_type.nil?
23
+ wrong = true
24
+ respond "You need to specify the TYPE for the member."
25
+ break
26
+ else
27
+ member_id = $1
28
+ member_info = @users.select { |u| u.id == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
29
+ if member_info.nil?
30
+ @users = get_users()
31
+ member_info = @users.select { |u| u.id == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
32
+ end
33
+ team[:members][last_type] << member_info.name
34
+ end
35
+ elsif opt.match(/<#(\w+)\|[^>]*>/i)
36
+ team[:channels][last_type] ||= []
37
+ if last_type.nil?
38
+ wrong = true
39
+ respond "You need to specify the TYPE for the channel."
40
+ break
41
+ else
42
+ channel_id = $1
43
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel_id)
44
+ channel = @channels_name[channel_id]
45
+ channel_members = get_channel_members(channel_id) unless channel.nil?
46
+ if channel.nil? or !channel_members.include?(config.nick_id)
47
+ respond ":exclamation: Add the Smart Bot to *<##{channel_id}>* channel first."
48
+ wrong = true
49
+ break
50
+ else
51
+ team[:channels][last_type] << channel
52
+ end
53
+ end
54
+ else
55
+ respond "It seems like the members or channel list is not correct. Please double check."
56
+ wrong = true
57
+ break
58
+ end
59
+ end
60
+ if type_detected #type added but not added a channel or user
61
+ respond "It seems like the parameters supplied are not correct. Please double check."
62
+ wrong = true
63
+ end
64
+
65
+ unless wrong
66
+ get_teams()
67
+ team[:info] = info
68
+ team[:status] = :added
69
+ team[:user] = user.name
70
+ team[:creator] = user.name
71
+ team[:date] = Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")[0..18]
72
+ new_team = {}
73
+ new_team[name.to_sym] = team
74
+ update_teams(new_team)
75
+ respond "The *#{name}* team has been added."
76
+ see_teams(user, name, add_stats: false)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,67 @@
1
+ class SlackSmartBot
2
+ def allow_access(user, command_id, opt)
3
+ save_stats(__method__)
4
+ not_allowed = ["hi_bot", "bye_bot", "allow_access", "deny_access", "get_bot_logs", "add_routine", "pause_bot", "pause_routine", "remove_routine", "run_routine", "start_bot",
5
+ "start_routine", "delete_message", "send_message", "kill_bot_on_channel", "exit_bot", "notify_message", "publish_announcements", "set_general_message",
6
+ "set_maintenance", "bot_help", "bot_rules"]
7
+ if !is_admin?(user.name)
8
+ respond "Only admins of this channel can use this command. Take a look who is an admin of this channel by calling `see admins`"
9
+ elsif Thread.current[:dest][0] == "D"
10
+ respond "This command cannot be called from a DM"
11
+ elsif not_allowed.include?(command_id)
12
+ respond "Sorry but the access for `#{command_id}` cannot be changed."
13
+ else
14
+ if Thread.current[:typem] == :on_call
15
+ channel = Thread.current[:dchannel]
16
+ elsif Thread.current[:using_channel].to_s == ""
17
+ channel = Thread.current[:dest]
18
+ else
19
+ channel = Thread.current[:using_channel]
20
+ end
21
+ command_ids = get_command_ids()
22
+ if command_ids.values.flatten.include?(command_id)
23
+ wrong_user = false
24
+ access_users = []
25
+ opt.each do |o|
26
+ if o.match(/\A\s*<@([^>]+)>\s*\z/)
27
+ access_users << $1
28
+ else
29
+ respond "Hmm, I've done some research on this and it looks like #{o} is not a valid Slack user.\nMake sure you are writing @USER and it is recognized by *Slack*\n"
30
+ wrong_user = true
31
+ break
32
+ end
33
+ end
34
+ unless wrong_user
35
+ if !@access_channels.key?(channel)
36
+ @access_channels[channel] = {}
37
+ end
38
+
39
+ if access_users.empty? # all users will be able to access
40
+ @access_channels[channel].delete(command_id)
41
+ else
42
+ if @access_channels.key?(channel) and !@access_channels[channel].key?(command_id)
43
+ @access_channels[channel][command_id] = []
44
+ end
45
+ access_users_names = []
46
+ access_users.each do |us|
47
+ user_info = @users.select { |u| u.id == us or (u.key?(:enterprise_user) and u.enterprise_user.id == us) }[-1]
48
+ access_users_names << user_info.name unless user_info.nil?
49
+ end
50
+ @access_channels[channel][command_id] += access_users_names
51
+ @access_channels[channel][command_id].flatten!
52
+ @access_channels[channel][command_id].uniq!
53
+ @access_channels[channel][command_id].delete(nil)
54
+ end
55
+ update_access_channels()
56
+ if !@access_channels[channel].key?(command_id)
57
+ respond "All users will have access to this command on this channel."
58
+ else
59
+ respond "These users will have access to this command on this channel: <@#{@access_channels[channel][command_id].join(">, <@")}>"
60
+ end
61
+ end
62
+ else
63
+ respond "It seems like #{command_id} is not valid. Please be sure that exists by calling `see command ids`"
64
+ end
65
+ end
66
+ end
67
+ end