slack-smart-bot 1.10.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +134 -23
  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 +24 -13
  9. data/lib/slack/smart-bot/comm/send_msg_user.rb +12 -11
  10. data/lib/slack/smart-bot/comm/set_status.rb +21 -0
  11. data/lib/slack/smart-bot/comm.rb +3 -0
  12. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  13. data/lib/slack/smart-bot/commands/general/add_announcement.rb +1 -1
  14. data/lib/slack/smart-bot/commands/general/add_memo_team.rb +117 -0
  15. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  16. data/lib/slack/smart-bot/commands/general/add_vacation.rb +51 -0
  17. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  18. data/lib/slack/smart-bot/commands/general/bot_help.rb +20 -11
  19. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +1 -1
  20. data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +69 -0
  21. data/lib/slack/smart-bot/commands/general/delete_share.rb +1 -1
  22. data/lib/slack/smart-bot/commands/general/delete_team.rb +54 -0
  23. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  24. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  25. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  26. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  27. data/lib/slack/smart-bot/commands/general/remove_vacation.rb +27 -0
  28. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  29. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  30. data/lib/slack/smart-bot/commands/general/see_announcements.rb +7 -5
  31. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  32. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +3 -4
  33. data/lib/slack/smart-bot/commands/general/see_statuses.rb +34 -21
  34. data/lib/slack/smart-bot/commands/general/see_teams.rb +402 -0
  35. data/lib/slack/smart-bot/commands/general/see_vacations.rb +58 -0
  36. data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +136 -0
  37. data/lib/slack/smart-bot/commands/general/set_memo_status.rb +58 -0
  38. data/lib/slack/smart-bot/commands/general/share_messages.rb +1 -1
  39. data/lib/slack/smart-bot/commands/general/update_team.rb +130 -0
  40. data/lib/slack/smart-bot/commands/general_bot_commands.rb +442 -13
  41. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -1
  42. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +2 -1
  43. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -1
  44. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +2 -1
  45. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +2 -1
  46. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -1
  47. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +3 -2
  48. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +2 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +10 -9
  50. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +2 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +2 -1
  52. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -1
  53. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  55. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +3 -1
  56. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +15 -2
  57. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -1
  58. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +5 -4
  59. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +416 -0
  60. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +1 -0
  61. data/lib/slack/smart-bot/commands/{general → on_bot/general}/leaderboard.rb +1 -0
  62. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +1 -0
  63. data/lib/slack/smart-bot/commands/{general → on_bot/general}/suggest_command.rb +6 -0
  64. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +1 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  66. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -1
  67. data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +32 -0
  68. data/lib/slack/smart-bot/commands/on_bot/repl.rb +73 -15
  69. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +1 -0
  70. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +117 -28
  71. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +2 -1
  72. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +3 -2
  73. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +5 -4
  74. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -2
  75. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
  76. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +6 -3
  77. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +2 -1
  78. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +2 -1
  79. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +1 -0
  80. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  81. data/lib/slack/smart-bot/commands.rb +30 -7
  82. data/lib/slack/smart-bot/listen.rb +30 -30
  83. data/lib/slack/smart-bot/process.rb +53 -23
  84. data/lib/slack/smart-bot/process_first.rb +2 -2
  85. data/lib/slack/smart-bot/treat_message.rb +23 -17
  86. data/lib/slack/smart-bot/utils/build_help.rb +1 -1
  87. data/lib/slack/smart-bot/utils/check_vacations.rb +43 -0
  88. data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
  89. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  90. data/lib/slack/smart-bot/utils/get_admins_channels.rb +33 -0
  91. data/lib/slack/smart-bot/utils/get_bots_created.rb +27 -10
  92. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  93. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  94. data/lib/slack/smart-bot/utils/get_help.rb +36 -19
  95. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  96. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  97. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  98. data/lib/slack/smart-bot/utils/get_vacations.rb +22 -0
  99. data/lib/slack/smart-bot/utils/has_access.rb +25 -9
  100. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  101. data/lib/slack/smart-bot/utils/save_stats.rb +52 -42
  102. data/lib/slack/smart-bot/utils/save_status.rb +22 -7
  103. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  104. data/lib/slack/smart-bot/utils/update_admins_channels.rb +25 -0
  105. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  106. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  107. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  108. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  109. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  110. data/lib/slack/smart-bot/utils/update_vacations.rb +16 -0
  111. data/lib/slack/smart-bot/utils.rb +11 -0
  112. data/lib/slack-smart-bot.rb +50 -12
  113. data/lib/slack-smart-bot_general_commands.rb +16 -1
  114. data/whats_new.txt +12 -30
  115. metadata +78 -21
  116. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -314
@@ -0,0 +1,130 @@
1
+ class SlackSmartBot
2
+ def update_team(user, team_name, new_name: "", new_info: "", delete_opts: "", add_opts: "")
3
+ save_stats(__method__)
4
+ get_teams()
5
+ if @teams.key?(team_name.to_sym)
6
+ assigned_members = @teams[team_name.to_sym].members.values.flatten
7
+ assigned_members.uniq!
8
+ all_team_members = assigned_members.dup
9
+ team_members = []
10
+ if @teams[team_name.to_sym].channels.key?("members")
11
+ @teams[team_name.to_sym].channels["members"].each do |ch|
12
+ get_channels_name_and_id() unless @channels_id.key?(ch)
13
+ tm = get_channel_members(@channels_id[ch])
14
+ tm.each do |m|
15
+ user_info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) }[-1]
16
+ team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
17
+ end
18
+ end
19
+ end
20
+ team_members.flatten!
21
+ team_members.uniq!
22
+ all_team_members += team_members
23
+ all_team_members.uniq!
24
+ end
25
+ if !@teams.key?(team_name.to_sym)
26
+ respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
27
+ elsif !(all_team_members + [@teams[team_name.to_sym].creator] + config.masters).flatten.include?(user.name)
28
+ respond "You have to be a member of the team, the creator or a Master admin to be able to update this team."
29
+ else
30
+ wrong = false
31
+ if new_name != ""
32
+ team = @teams[team_name.to_sym].deep_copy
33
+ @teams[new_name.to_sym] = team
34
+ @teams.delete(team_name.to_sym)
35
+ message = "The *#{team_name}* team has been renamed #{new_name}."
36
+ team_name = new_name
37
+ elsif new_info != ""
38
+ @teams[team_name.to_sym].info = new_info
39
+ elsif delete_opts != ""
40
+ last_type = nil
41
+ delete_opts.split(" ").each do |opt|
42
+ if opt.match?(/^\s*$/)
43
+ #blank
44
+ elsif opt.match?(/^[\w\-]+$/i)
45
+ last_type = opt
46
+ elsif opt.match(/<?@(\w+)>?/i) #accepts also @username for the case the user has been deactivated
47
+ member_id = $1
48
+ member_info = @users.select { |u| u.id == member_id or u.name == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
49
+ if last_type.nil?
50
+ @teams[team_name.to_sym].members.each do |type, members|
51
+ @teams[team_name.to_sym].members[type].delete(member_info.name)
52
+ end
53
+ else
54
+ @teams[team_name.to_sym].members[last_type] ||= []
55
+ @teams[team_name.to_sym].members[last_type].delete(member_info.name)
56
+ end
57
+ elsif opt.match(/<#(\w+)\|[^>]*>/i)
58
+ channel_id = $1
59
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel_id)
60
+ channel = @channels_name[channel_id]
61
+ if last_type.nil?
62
+ @teams[team_name.to_sym].channels.each do |type, channels|
63
+ @teams[team_name.to_sym].channels[type].delete(channel)
64
+ end
65
+ else
66
+ @teams[team_name.to_sym].channels[last_type] ||= []
67
+ @teams[team_name.to_sym].channels[last_type].delete(channel)
68
+ end
69
+ else
70
+ respond "It seems like the members or channel list is not correct. Please double check."
71
+ wrong = true
72
+ break
73
+ end
74
+ end
75
+ tmembers = @teams[team_name.to_sym].members.deep_copy
76
+ tmembers.each do |type, members|
77
+ @teams[team_name.to_sym].members.delete(type) if members.empty?
78
+ end
79
+ tchannels = @teams[team_name.to_sym].channels.deep_copy
80
+ tchannels.each do |type, channels|
81
+ @teams[team_name.to_sym].channels.delete(type) if channels.empty?
82
+ end
83
+ elsif add_opts != ""
84
+ last_type = nil
85
+ add_opts.split(" ").each do |opt|
86
+ if opt.match?(/^\s*$/)
87
+ #blank
88
+ elsif opt.match?(/^[\w\-]+$/i)
89
+ last_type = opt
90
+ elsif opt.match(/<@(\w+)>/i)
91
+ member_id = $1
92
+ last_type = 'no_type' if last_type.nil?
93
+ member_info = @users.select { |u| u.id == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
94
+ @teams[team_name.to_sym].members[last_type] ||= []
95
+ @teams[team_name.to_sym].members[last_type] << member_info.name
96
+ @teams[team_name.to_sym].members[last_type].uniq!
97
+ elsif opt.match(/<#(\w+)\|[^>]*>/i)
98
+ channel_id = $1
99
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel_id)
100
+ channel = @channels_name[channel_id]
101
+ @teams[team_name.to_sym].channels[last_type] ||= []
102
+ @teams[team_name.to_sym].channels[last_type] << channel
103
+ @teams[team_name.to_sym].channels[last_type].uniq!
104
+ else
105
+ respond "It seems like the members or channel list is not correct. Please double check."
106
+ wrong = true
107
+ break
108
+ end
109
+ end
110
+ tmembers = @teams[team_name.to_sym].members.deep_copy
111
+ tmembers.each do |type, members|
112
+ @teams[team_name.to_sym].members.delete(type) if members.empty?
113
+ end
114
+ tchannels = @teams[team_name.to_sym].channels.deep_copy
115
+ tchannels.each do |type, channels|
116
+ @teams[team_name.to_sym].channels.delete(type) if channels.empty?
117
+ end
118
+ end
119
+ unless wrong
120
+ message ||= "The *#{team_name}* team has been updated."
121
+ @teams[team_name.to_sym].status = :updated
122
+ @teams[team_name.to_sym].user = user.name
123
+ @teams[team_name.to_sym].date = Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")[0..18]
124
+ update_teams()
125
+ end
126
+ respond message
127
+ see_teams(user, team_name, add_stats: false) unless wrong
128
+ end
129
+ end
130
+ end