slack-smart-bot 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -3
  3. data/lib/slack/smart-bot/comm/respond.rb +8 -2
  4. data/lib/slack/smart-bot/comm/set_status.rb +21 -0
  5. data/lib/slack/smart-bot/comm.rb +1 -0
  6. data/lib/slack/smart-bot/commands/general/add_memo_team.rb +117 -0
  7. data/lib/slack/smart-bot/commands/general/add_vacation.rb +51 -0
  8. data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +69 -0
  9. data/lib/slack/smart-bot/commands/general/delete_team.rb +21 -1
  10. data/lib/slack/smart-bot/commands/general/remove_vacation.rb +27 -0
  11. data/lib/slack/smart-bot/commands/general/see_announcements.rb +1 -1
  12. data/lib/slack/smart-bot/commands/general/see_statuses.rb +1 -1
  13. data/lib/slack/smart-bot/commands/general/see_teams.rb +182 -32
  14. data/lib/slack/smart-bot/commands/general/see_vacations.rb +58 -0
  15. data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +136 -0
  16. data/lib/slack/smart-bot/commands/general/set_memo_status.rb +58 -0
  17. data/lib/slack/smart-bot/commands/general/update_team.rb +22 -1
  18. data/lib/slack/smart-bot/commands/general_bot_commands.rb +172 -4
  19. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +21 -5
  20. data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +32 -0
  21. data/lib/slack/smart-bot/commands/on_bot/repl.rb +1 -0
  22. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +113 -33
  23. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +3 -1
  24. data/lib/slack/smart-bot/commands.rb +8 -0
  25. data/lib/slack/smart-bot/process.rb +17 -7
  26. data/lib/slack/smart-bot/treat_message.rb +11 -1
  27. data/lib/slack/smart-bot/utils/check_vacations.rb +43 -0
  28. data/lib/slack/smart-bot/utils/get_admins_channels.rb +23 -3
  29. data/lib/slack/smart-bot/utils/get_command_ids.rb +1 -1
  30. data/lib/slack/smart-bot/utils/get_help.rb +4 -3
  31. data/lib/slack/smart-bot/utils/get_vacations.rb +22 -0
  32. data/lib/slack/smart-bot/utils/save_stats.rb +9 -2
  33. data/lib/slack/smart-bot/utils/save_status.rb +1 -1
  34. data/lib/slack/smart-bot/utils/update_admins_channels.rb +20 -3
  35. data/lib/slack/smart-bot/utils/update_vacations.rb +16 -0
  36. data/lib/slack/smart-bot/utils.rb +3 -0
  37. data/lib/slack-smart-bot.rb +22 -2
  38. data/whats_new.txt +12 -17
  39. metadata +19 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e5ea9ccfc9d1c52925f5bdd6ef89c35158c19f8fafad8f5af99d9a6b8456b43
4
- data.tar.gz: 6c3853c8977a29f85cba5013b06b8178ca6f0b4783ff323fd0fa96d7ad92ad5b
3
+ metadata.gz: 1b862b6537e267ad0582f3ca4e60eefa63ef9513a6e2b4d0bf0dd05ac5689ef4
4
+ data.tar.gz: 1f08183c3eb4e33f63f1b1b4a1fc1e078ceb4835655d03435eca27aa2491f749
5
5
  SHA512:
6
- metadata.gz: 8d795ac13cfe68983064894f6fff8e7667cb939a78c9e2a044630aca021a4bd11c2be8a8cf6944fceebe8ea1b4ff5ca2d7455c4eb121edcd28ad8b89605ad4dc
7
- data.tar.gz: e81573197080798f5cae34521b44744de6912895ba55049611f806059b171f69c5fe2d3bb30e790d1d158b2a06b71c449afcb61f96602fcdd070c240a9298f89
6
+ metadata.gz: 286cc08cac4c0f4cc7dbb32583a2d1f27d7b41bfa2e53330a407850ed80ce993ec63c036c0b1c88a6113b4261701315bd8b2a34eac91e1a9d156eadd029e50de
7
+ data.tar.gz: a7b84c3d33cb1eda1a59d2d677b091f3b7aab488824d7ee7ba62af1eaa71a2311bb9decd3f7844baedf2fc569bc9f72b9baad023d50393627d70e40c8ba7be6e
data/README.md CHANGED
@@ -34,6 +34,7 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
34
34
  * [Control who has access to a command](#control-who-has-access-to-a-command)
35
35
  * [See favorite commands](#see-favorite-commands)
36
36
  * [Teams](#teams)
37
+ * [Time off management](#time-off-management)
37
38
  * [Tips](#tips)
38
39
  + [Send a file](#send-a-file)
39
40
  + [Download a file](#download-a-file)
@@ -377,7 +378,7 @@ Running Example:
377
378
  >**_Smart-Bot>_** `Session name: *Create10RandomUsers*`
378
379
  >**_Peter>_** `http = NiceHttp.new("https://reqres.in/")`
379
380
  >**_Smart-Bot>_** `#<NiceHttp:0x00007fc6e216e328 @host="reqres.in", @port=443...>`
380
- >**_Peter>_** `request = { path: '/api/users' }`
381
+ >**_Peter>_** `request ||= { path: '/api/users' }`
381
382
  >**_Smart-Bot>_** `{ :path => "/api/users" }`
382
383
  >**_Peter>_** `request.data = { name: '1-10:L', job: 'leader|worker' }`
383
384
  >**_Smart-Bot>_** `{ :name => "1-10:L", :job => "leader|worker" }`
@@ -395,8 +396,11 @@ Running Example:
395
396
  >**_Smart-Bot>_** `Running REPL Create10RandomUsers`
396
397
  >**_Smart-Bot>_** `Create10RandomUsers: 10 Random Users Created`
397
398
 
399
+ You can run repls and supply parameters to the repl that will be executed on the same session just before the repl. [More info](https://github.com/MarioRuiz/slack-smart-bot/issues/60)
400
+ Example:
401
+ >**_Peter>_** ``run repl Create10RandomUsers `request = {path: '/api-dev/users/'}` ``
398
402
 
399
- Other REPL commands: `see repls`, `run repl SESSION_NAME ENV_VAR=value`, `get repl SESSION_NAME`, `delete repl SESSION_NAME`
403
+ Other REPL commands: `see repls`, `run repl SESSION_NAME ENV_VAR=value`, `get repl SESSION_NAME`, `delete repl SESSION_NAME`, `kill repl RUN_REPL_ID`
400
404
 
401
405
  ### Sending notifications
402
406
  You can send notifications from MASTER CHANNEL by using **_`notify MESSAGE`_**. All Bot Channels will be notified.
@@ -607,8 +611,45 @@ Examples:
607
611
  >**_`ping team sales development What's the status on last deployment?`_**
608
612
  >**_`contact team sales qa Please finish testing of dev02 feature before noon`_**
609
613
 
610
- Other team commands: **_`delete team TEAM_NAME`_**
614
+ It is also possible to add notes for the team, even you can specify if those notes are private so only the members of the team can see them or even personal so only you will. You can use different types of notes: memo, note, issue, task, feature, bug, jira, github. Also you can indicate the topic of the note. To be able to add or delete notes you need to be a member of that team.
615
+ In case of 'jira' type then you can supply an URL or a JQL and it will show all the JIRA issues as memos. To be able to use it you need to specify on the SmartBot settings the credentials for the Basic Authentication on JIRA:
616
+ `jira: {host: HOST, user: USER, password: PASSWORD}`
617
+ In case of 'github' type then you can supply an URL filtering the Github issues you want to add as memos. To be able to use it you need to specify on the SmartBot settings the Github token:
618
+ `github: {token: GITHUB_TOKEN}`
619
+
620
+ If you want to change the memo status use the command `set STATUS on memo ID TEAM_NAME team`. For example: `set :runner: on memo 7 Sales team`
621
+
622
+ Examples:
623
+ >**_`add memo to sales team : Add tests for Michigan feature`_**
624
+ >**_`add private note to sales team : Bills will need to be deployed before Friday`_**
625
+ >**_`add memo to dev team web : Check last version`_**
626
+ >**_`add private bug to dev team SRE : Logs should not be accessible from outside VPN`_**
627
+ >**_`add memo sales team : Add tests for Michigan feature`_**
628
+ >**_`add memo team sales: Add tests for Michigan feature`_**
629
+ >**_`add jira to sales team : labels = SalesT AND status != Done`_**
630
+ >**_`add github to sales team : https://github.com/PeterBale/SalesBoom/issues?q=is%3Aissue+is%3Aopen+`_**
631
+ >**_`set :runner: on memo 7 team Sales`_**
632
+
633
+ Other team commands: **_`delete team TEAM_NAME`_**, **_`delete memo ID from team TEAM_NAME`_**, **_`set STATUS on memo ID TEAM_NAME team`_**
634
+
635
+ ### Time off management
636
+
637
+ You will be able to add or remove vacation and sick periods by using `add vacation/sick from YYYY/MM/DD to YYYY/MM/DD`. The SmartBot will automatically set the users status to 🌴 or 🤒 and the expiration date when the user is on vacation or sick. The SmartBot won't be allowed to change the status of workspace admins or owners.
638
+
639
+ The vacation plan will be displayed also with the team when calling `see team NAME` for all team members.
640
+
641
+ Also, you can see the vacation plan for the team for a specific period: `vacations team NAME YYYY/MM/DD`
642
+
643
+ To be able to use this command you need to allow the 'users.profile:write' scope on your Slack App and an admin user of the workspace needs to install the app. Set the user token on the SmartBot settings:
644
+
645
+ ```ruby
646
+ settings = {
647
+ token: ENV["SLACK_BOT_TOKEN"],
648
+ user_token: ENV['SLACK_USER_TOKEN']
649
+ }
650
+ ```
611
651
 
652
+ Other 'time off' commands: **_`remove time off ID`_**, **_`see my time off`_**, **_`see vacations @USER`_**, **_`time off team NAME`_**
612
653
 
613
654
  ### Tips
614
655
 
@@ -49,14 +49,20 @@ class SlackSmartBot
49
49
  txt = ""
50
50
  msg.split("\n").each do |m|
51
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 = ""
52
+ unless txt == ""
53
+ txt[0] = '.' if txt.match?(/\A\s\s\s/) #first line of message in slack don't show spaces at the begining so we force it by changing first char
54
+ t = txt.chars.each_slice(max_chars_per_message).map(&:join)
55
+ msgs << t
56
+ txt = ""
57
+ end
54
58
  end
55
59
  txt += (m + "\n")
60
+ txt[0] = '.' if txt.match?(/\A\s\s\s/) #first line of message in slack don't show spaces at the begining so we force it by changing first char
56
61
  end
57
62
  end
58
63
  msgs << txt
59
64
  msgs.flatten!
65
+ msgs.delete_if{|e| e.match?(/\A\s*\z/)}
60
66
  if dest.nil?
61
67
  if config[:simulate]
62
68
  open("#{config.path}/buffer_complete.log", "a") { |f|
@@ -0,0 +1,21 @@
1
+ class SlackSmartBot
2
+ def set_status(user_id, status: nil, message: nil, expiration: nil)
3
+ unless client_user.nil?
4
+ if expiration.is_a?(String) and expiration.match?(/^\d\d\d\d\/\d\d\/\d\d$/)
5
+ expiration = Date.parse(expiration, '%Y/%m/%d').to_time.to_i
6
+ elsif expiration.is_a?(Date)
7
+ expiration = expiration.to_time.to_i
8
+ end
9
+ params = []
10
+ params << "'status_emoji': '#{status}'" unless status.nil?
11
+ params << "'status_text': '#{message}'" unless message.nil?
12
+ params << "'status_expiration': '#{expiration}'" unless expiration.nil?
13
+ begin
14
+ resp = client_user.users_profile_set(user: user_id, profile: "{ #{params.join(', ')} }")
15
+ rescue Exception => exc
16
+ @logger.fatal exc.inspect
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -15,3 +15,4 @@ require_relative 'comm/get_channel_members'
15
15
  require_relative 'comm/get_channels'
16
16
  require_relative 'comm/delete'
17
17
  require_relative 'comm/get_presence'
18
+ require_relative 'comm/set_status'
@@ -0,0 +1,117 @@
1
+ class SlackSmartBot
2
+ def add_memo_team(user, privacy, team_name, topic, type, message)
3
+ save_stats(__method__)
4
+
5
+ get_teams()
6
+ if @teams.key?(team_name.to_sym)
7
+ assigned_members = @teams[team_name.to_sym].members.values.flatten
8
+ assigned_members.uniq!
9
+ all_team_members = assigned_members.dup
10
+ team_members = []
11
+ if @teams[team_name.to_sym].channels.key?("members")
12
+ @teams[team_name.to_sym].channels["members"].each do |ch|
13
+ get_channels_name_and_id() unless @channels_id.key?(ch)
14
+ tm = get_channel_members(@channels_id[ch])
15
+ tm.each do |m|
16
+ user_info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) }[-1]
17
+ team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
18
+ end
19
+ end
20
+ end
21
+ team_members.flatten!
22
+ team_members.uniq!
23
+ all_team_members += team_members
24
+ all_team_members.uniq!
25
+ end
26
+ if type == "jira"
27
+ able_to_connect_jira = false
28
+ begin
29
+ http = NiceHttp.new(config.jira.host)
30
+ http.headers.authorization = NiceHttpUtils.basic_authentication(user: config.jira.user, password: config.jira.password)
31
+ message.gsub!(/^\s*</, "")
32
+ message.gsub!(/\>$/, "")
33
+ message.gsub!(/\|.+$/, "")
34
+ message.gsub!(/^#{config.jira.host}/, "")
35
+ if message.include?("/browse/")
36
+ message = message.scan(/\/browse\/(.+)/).join
37
+ resp = http.get("/rest/api/latest/issue/#{message}")
38
+ else
39
+ message.gsub!(/^\/issues\/\?jql=/, "")
40
+ message.gsub!(" ", "%20")
41
+ resp = http.get("/rest/api/latest/search/?jql=#{message}")
42
+ end
43
+ if resp.code == 200
44
+ able_to_connect_jira = true
45
+ else
46
+ error_code = resp.code
47
+ if resp.code == 400
48
+ error_message = resp.data.json(:errorMessages)[-1]
49
+ else
50
+ error_message = ""
51
+ end
52
+ end
53
+ http.close
54
+ rescue => exception
55
+ @logger.fatal exception
56
+ end
57
+ elsif type == "github"
58
+ able_to_connect_github = false
59
+ begin
60
+ http = NiceHttp.new(config.github.host)
61
+ http.headers.authorization = "token #{config.github.token}"
62
+ message.gsub!(/^\s*</, "")
63
+ message.gsub!(/\>$/, "")
64
+ message.gsub!(/\|.+$/, "")
65
+ message.gsub!(/^#{config.github.host}/, "")
66
+ message.gsub!("https://github.com", "")
67
+ message.slice!(0) if message[0] == "/"
68
+ resp = http.get("/repos#{message}")
69
+ if resp.code == 200
70
+ able_to_connect_github = true
71
+ else
72
+ error_code = resp.code
73
+ if resp.code == 401
74
+ error_message = resp.data.json(:message)[-1]
75
+ else
76
+ error_message = ""
77
+ end
78
+ end
79
+ http.close
80
+ rescue => exception
81
+ @logger.fatal exception
82
+ end
83
+ end
84
+
85
+ if !@teams.key?(team_name.to_sym)
86
+ respond "It seems like the team *#{team_name}* doesn't exist\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
87
+ elsif !(all_team_members + config.masters).flatten.include?(user.name)
88
+ respond "You have to be a member of the team or a Master admin to be able to add a memo to the team."
89
+ elsif type == "jira" and !able_to_connect_jira
90
+ if error_message == ""
91
+ respond "You need to supply the correct credentials for JIRA on the SmartBot settings: `jira: { host: HOST, user: USER, password: PASSWORD }` and a correct JQL string or JQL url"
92
+ else
93
+ respond "You need to supply a correct JQL string or JQL url: #{error_message}"
94
+ end
95
+ else
96
+ topic = :no_topic if topic == ""
97
+ @teams[team_name.to_sym][:memos] ||= []
98
+ if @teams[team_name.to_sym][:memos].empty?
99
+ memo_id = 1
100
+ else
101
+ memo_id = @teams[team_name.to_sym][:memos].memo_id.flatten.max + 1
102
+ end
103
+ @teams[team_name.to_sym][:memos] << {
104
+ memo_id: memo_id,
105
+ topic: topic,
106
+ type: type,
107
+ privacy: privacy,
108
+ user: user.name,
109
+ date: Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")[0..18],
110
+ message: message,
111
+ status: ':new: '
112
+ }
113
+ update_teams()
114
+ respond "The memo has been added to *#{team_name}* team."
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,51 @@
1
+ class SlackSmartBot
2
+
3
+ def add_vacation(user, type, from, to)
4
+ save_stats(__method__)
5
+ get_vacations()
6
+ from.gsub!('-','/')
7
+ to.gsub!('-','/')
8
+ if type.match?(/sick\s+baby/i) or type.match?(/sick\s+child/i)
9
+ type = 'sick child'
10
+ end
11
+
12
+ if from=='today'
13
+ from = Date.today.strftime("%Y/%m/%d")
14
+ elsif from =='tomorrow'
15
+ from = (Date.today+1).strftime("%Y/%m/%d")
16
+ elsif from.match?(/next\s+week/)
17
+ from = Date.today + ((1 - Date.today.wday) % 7)
18
+ to = (from + 6).strftime("%Y/%m/%d")
19
+ from = from.strftime("%Y/%m/%d")
20
+ end
21
+
22
+ to = from if to.empty?
23
+ wrong = false
24
+ begin
25
+ from_date = Date.parse(from)
26
+ to_date = Date.parse(to)
27
+ rescue
28
+ wrong = true
29
+ respond "It seems like the date is not in the correct format: YYYY/MM/DD or is a wrong date."
30
+ end
31
+ unless wrong
32
+ if Date.parse(from).strftime("%Y/%m/%d") != from
33
+ respond "It seems like the date #{from} is not in the correct format: YYYY/MM/DD or is a wrong date."
34
+ elsif Date.parse(to).strftime("%Y/%m/%d") != to
35
+ respond "It seems like the date #{to} is not in the correct format: YYYY/MM/DD or is a wrong date."
36
+ else
37
+ vacations = @vacations.deep_copy
38
+ vacations[user.name] ||= { user_id: user.id, periods: [] }
39
+ if vacations[user.name].periods.empty?
40
+ vacation_id = 1
41
+ else
42
+ vacation_id = vacations[user.name].periods[-1].vacation_id + 1
43
+ end
44
+ vacations[user.name].periods << { vacation_id: vacation_id, type: type.downcase, from: from, to: to }
45
+ update_vacations({user.name => vacations[user.name]})
46
+ respond "Period has been added ##{vacation_id}"
47
+ check_vacations(date: Date.today, user: user.name, set_status: true, only_first_day: false)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,69 @@
1
+ class SlackSmartBot
2
+ def delete_memo_team(user, team_name, memo_id)
3
+ save_stats(__method__) if answer.empty?
4
+
5
+ get_teams()
6
+ if @teams.key?(team_name.to_sym)
7
+ assigned_members = @teams[team_name.to_sym].members.values.flatten
8
+ assigned_members.uniq!
9
+ all_team_members = assigned_members.dup
10
+ team_members = []
11
+ if @teams[team_name.to_sym].channels.key?("members")
12
+ @teams[team_name.to_sym].channels["members"].each do |ch|
13
+ get_channels_name_and_id() unless @channels_id.key?(ch)
14
+ tm = get_channel_members(@channels_id[ch])
15
+ tm.each do |m|
16
+ user_info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) }[-1]
17
+ team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
18
+ end
19
+ end
20
+ end
21
+ team_members.flatten!
22
+ team_members.uniq!
23
+ all_team_members += team_members
24
+ all_team_members.uniq!
25
+ end
26
+
27
+ if !@teams.key?(team_name.to_sym)
28
+ respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
29
+ elsif !(all_team_members + config.masters).flatten.include?(user.name)
30
+ respond "You have to be a member of the team or a Master admin to be able to delete a memo of the team."
31
+ elsif !@teams[team_name.to_sym].key?(:memos) or @teams[team_name.to_sym][:memos].empty? or !@teams[team_name.to_sym][:memos].memo_id.include?(memo_id.to_i)
32
+ respond "It seems like there is no memo with id #{memo_id}"
33
+ elsif @teams[team_name.to_sym][:memos].memo_id.include?(memo_id.to_i)
34
+ memo_selected = @teams[team_name.to_sym][:memos].select { |m| m.memo_id == memo_id.to_i }[-1]
35
+ if memo_selected.privacy == 'personal' and memo_selected.user != user.name
36
+ respond "Only the creator can delete a personal memo."
37
+ else
38
+ if answer.empty?
39
+ message = @teams[team_name.to_sym][:memos].select { |memo| memo.memo_id == memo_id.to_i }.message.join
40
+ ask "do you really want to delete the memo #{memo_id} (#{message}) from #{team_name} team? (yes/no)"
41
+ else
42
+ case answer
43
+ when /yes/i, /yep/i, /sure/i
44
+ answer_delete
45
+ memos = []
46
+ message = ""
47
+ get_teams()
48
+ @teams[team_name.to_sym][:memos].each do |memo|
49
+ if memo.memo_id != memo_id.to_i
50
+ memos << memo
51
+ else
52
+ message = memo.message
53
+ end
54
+ end
55
+ @teams[team_name.to_sym][:memos] = memos
56
+ update_teams()
57
+ respond "The memo has been deleted from team #{team_name}: #{message}"
58
+ when /no/i, /nope/i, /cancel/i
59
+ answer_delete
60
+ respond "Ok, the memo was not deleted"
61
+ else
62
+ respond "I don't understand"
63
+ ask "do you really want to delete the memo from #{team_name} team? (yes/no)"
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -6,9 +6,29 @@ class SlackSmartBot
6
6
  respond "This command cannot be called from a DM"
7
7
  else
8
8
  get_teams()
9
+ if @teams.key?(team_name.to_sym)
10
+ assigned_members = @teams[team_name.to_sym].members.values.flatten
11
+ assigned_members.uniq!
12
+ all_team_members = assigned_members.dup
13
+ team_members = []
14
+ if @teams[team_name.to_sym].channels.key?("members")
15
+ @teams[team_name.to_sym].channels["members"].each do |ch|
16
+ get_channels_name_and_id() unless @channels_id.key?(ch)
17
+ tm = get_channel_members(@channels_id[ch])
18
+ tm.each do |m|
19
+ user_info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) }[-1]
20
+ team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
21
+ end
22
+ end
23
+ end
24
+ team_members.flatten!
25
+ team_members.uniq!
26
+ all_team_members += team_members
27
+ all_team_members.uniq!
28
+ end
9
29
  if !@teams.key?(team_name.to_sym)
10
30
  respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
11
- elsif !(@teams[team_name.to_sym].members.values + [@teams[team_name.to_sym].creator] + config.masters).flatten.include?(user.name)
31
+ elsif !(all_team_members + [@teams[team_name.to_sym].creator] + config.masters).flatten.include?(user.name)
12
32
  respond "You have to be a member of the team, the creator or a Master admin to be able to delete this team."
13
33
  else
14
34
  if answer.empty?
@@ -0,0 +1,27 @@
1
+ class SlackSmartBot
2
+ def remove_vacation(user, vacation_id)
3
+ save_stats(__method__)
4
+
5
+ get_vacations()
6
+ if !@vacations.key?(user.name)
7
+ respond "It seems like you don't have any time off added."
8
+ elsif @vacations[user.name].periods.empty? or !@vacations[user.name].periods.vacation_id.include?(vacation_id)
9
+ respond "It seems like the ID supplied doesn't exist. Please call `see my time off` and check the ID."
10
+ else
11
+ vacations = @vacations[user.name].deep_copy
12
+ vacation = vacations.periods.select {|v| v.vacation_id == vacation_id }[-1]
13
+ vacations.periods.delete_if {|v| v.vacation_id == vacation_id }
14
+ update_vacations({user.name => vacations})
15
+ respond "Your time off has been removed."
16
+ if vacation.from <= Date.today.strftime("%Y/%m/%d") and vacation.to >= Date.today.strftime("%Y/%m/%d")
17
+ info = get_user_info(vacations.user_id)
18
+ emoji = info.user.profile.status_emoji
19
+ if (vacation.type == 'vacation' and emoji == ':palm_tree:') or (vacation.type == 'sick' and emoji == ':face_with_thermometer:') or
20
+ (vacation.type == 'sick child' and emoji == ':baby:')
21
+ set_status(vacations.user_id, status: '', expiration: '', message: '')
22
+ end
23
+ check_vacations(date: Date.today, user: user.name, set_status: true, only_first_day: false)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -59,7 +59,7 @@ class SlackSmartBot
59
59
  message = []
60
60
  @announcements[channel_id].each do |m|
61
61
  if m[:user_deleted] == '' and (type == 'all' or type == '' or type==m[:type])
62
- if m[:type].match?(/:\w+:/)
62
+ if m[:type].match?(/:[\w\-]+:/)
63
63
  emoji = m[:type]
64
64
  elsif m[:type] == 'white'
65
65
  emoji = ':white_square:'
@@ -26,7 +26,7 @@ class SlackSmartBot
26
26
  if types == ['available']
27
27
  only_active = true
28
28
  not_on = true
29
- types = [':palm_tree:', ':spiral_calendar_pad:', ':face_with_thermometer:']
29
+ types = [':palm_tree:', ':spiral_calendar_pad:', ':face_with_thermometer:', ':baby:']
30
30
  end
31
31
  members.each do |member|
32
32
  info = get_user_info(member)