slack-smart-bot 1.14.2 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +222 -37
- data/img/chat_gpt.png +0 -0
- data/img/chat_gpt_session.png +0 -0
- data/img/chat_gpt_share.png +0 -0
- data/img/command_add_sc.png +0 -0
- data/img/command_bot_help_echo.png +0 -0
- data/img/command_loop.png +0 -0
- data/img/command_my_timeoff.png +0 -0
- data/img/command_recap.png +0 -0
- data/img/command_repl1.png +0 -0
- data/img/command_repl2.png +0 -0
- data/img/command_ruby.png +0 -0
- data/img/command_run_repl.png +0 -0
- data/img/command_see_announcements.png +0 -0
- data/img/command_see_statuses.png +0 -0
- data/img/command_see_team.png +0 -0
- data/img/command_summarize.png +0 -0
- data/img/commands_inline.png +0 -0
- data/img/commands_on_demand.png +0 -0
- data/img/commands_on_external_call.png +0 -0
- data/img/image_editing.png +0 -0
- data/img/image_generation.png +0 -0
- data/img/image_variations.png +0 -0
- data/img/openai-300.png +0 -0
- data/img/openai.png +0 -0
- data/img/slack-300.png +0 -0
- data/img/slack.png +0 -0
- data/img/smart-bot-150.png +0 -0
- data/img/smart-bot-profile-pic-2.png +0 -0
- data/img/smart-bot-profile-pic.png +0 -0
- data/img/smart-bot.png +0 -0
- data/img/whisper.png +0 -0
- data/lib/slack/smart-bot/ai/open_ai/connect.rb +165 -43
- data/lib/slack/smart-bot/ai/open_ai/models.rb +61 -9
- data/lib/slack/smart-bot/ai/open_ai/send_gpt_chat.rb +67 -11
- data/lib/slack/smart-bot/ai/open_ai/send_image_edit.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/send_image_generation.rb +4 -4
- data/lib/slack/smart-bot/ai/open_ai/send_image_variation.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/whisper_transcribe.rb +4 -3
- data/lib/slack/smart-bot/comm/ask.rb +20 -8
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -1
- data/lib/slack/smart-bot/comm/get_channel_members.rb +2 -1
- data/lib/slack/smart-bot/comm/get_presence.rb +1 -0
- data/lib/slack/smart-bot/comm/get_smartbot_team_info.rb +10 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +45 -6
- data/lib/slack/smart-bot/comm/get_users.rb +8 -1
- data/lib/slack/smart-bot/comm/respond.rb +225 -196
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +10 -9
- data/lib/slack/smart-bot/comm/unreact.rb +2 -2
- data/lib/slack/smart-bot/comm.rb +1 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +16 -6
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +3 -3
- data/lib/slack/smart-bot/commands/general/add_vacation.rb +28 -12
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb +272 -23
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_add_collaborator.rb +42 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_copy_session.rb +89 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_delete_session.rb +45 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_get_prompts.rb +41 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_list_sessions.rb +81 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_share_session.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_use_model.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_edit_image.rb +14 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_generate_image.rb +15 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_models.rb +29 -17
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_variations_image.rb +16 -13
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_whisper.rb +13 -7
- data/lib/slack/smart-bot/commands/general/allow_access.rb +8 -4
- data/lib/slack/smart-bot/commands/general/bot_help.rb +24 -10
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +9 -5
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +2 -1
- data/lib/slack/smart-bot/commands/general/delete_share.rb +2 -1
- data/lib/slack/smart-bot/commands/general/deny_access.rb +1 -1
- data/lib/slack/smart-bot/commands/general/get_smartbot_readme.rb +15 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +10 -4
- data/lib/slack/smart-bot/commands/general/personal_settings.rb +26 -8
- data/lib/slack/smart-bot/commands/general/poster.rb +26 -2
- data/lib/slack/smart-bot/commands/general/public_holidays.rb +14 -24
- data/lib/slack/smart-bot/commands/general/recap.rb +399 -0
- data/lib/slack/smart-bot/commands/general/remove_admin.rb +19 -9
- data/lib/slack/smart-bot/commands/general/remove_vacation.rb +23 -6
- data/lib/slack/smart-bot/commands/general/see_access.rb +2 -1
- data/lib/slack/smart-bot/commands/general/see_admins.rb +8 -4
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +5 -5
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +4 -4
- data/lib/slack/smart-bot/commands/general/see_shares.rb +1 -1
- data/lib/slack/smart-bot/commands/general/see_vacations.rb +34 -17
- data/lib/slack/smart-bot/commands/general/set_public_holidays.rb +4 -2
- data/lib/slack/smart-bot/commands/general/share_messages.rb +3 -3
- data/lib/slack/smart-bot/commands/general/summarize.rb +191 -0
- data/lib/slack/smart-bot/commands/general/teams/add_team.rb +4 -8
- data/lib/slack/smart-bot/commands/general/teams/delete_team.rb +3 -3
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team.rb +34 -29
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team_comment.rb +1 -1
- data/lib/slack/smart-bot/commands/general/teams/memos/delete_memo_team.rb +6 -4
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memo_team.rb +26 -15
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memos_team.rb +33 -24
- data/lib/slack/smart-bot/commands/general/teams/memos/set_memo_status.rb +4 -4
- data/lib/slack/smart-bot/commands/general/teams/ping_team.rb +10 -8
- data/lib/slack/smart-bot/commands/general/teams/see_teams.rb +73 -61
- data/lib/slack/smart-bot/commands/general/teams/see_vacations_team.rb +28 -13
- data/lib/slack/smart-bot/commands/general/teams/update_team.rb +9 -9
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +1152 -839
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +18 -17
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +11 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +5 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/admin_master/update_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +21 -20
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +40 -7
- data/lib/slack/smart-bot/commands/on_bot/general/bot_status.rb +6 -2
- data/lib/slack/smart-bot/commands/on_bot/general/stop_using_rules.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/general/use_rules.rb +4 -3
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -4
- data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +109 -53
- data/lib/slack/smart-bot/commands/on_bot/repl_client.rb +35 -29
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -2
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +22 -12
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +12 -7
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -2
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +3 -3
- data/lib/slack/smart-bot/commands.rb +10 -0
- data/lib/slack/smart-bot/config.rb +126 -0
- data/lib/slack/smart-bot/listen.rb +12 -11
- data/lib/slack/smart-bot/process.rb +62 -55
- data/lib/slack/smart-bot/process_first.rb +106 -65
- data/lib/slack/smart-bot/treat_message.rb +79 -47
- data/lib/slack/smart-bot/utils/answer.rb +11 -3
- data/lib/slack/smart-bot/utils/answer_delete.rb +11 -3
- data/lib/slack/smart-bot/utils/check_vacations.rb +21 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +13 -13
- data/lib/slack/smart-bot/utils/display_calendar.rb +42 -8
- data/lib/slack/smart-bot/utils/encryption/decrypt.rb +16 -9
- data/lib/slack/smart-bot/utils/encryption/encrypt.rb +14 -11
- data/lib/slack/smart-bot/utils/find_user.rb +71 -0
- data/lib/slack/smart-bot/utils/get_access_channels.rb +22 -3
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +3 -4
- data/lib/slack/smart-bot/utils/get_command_ids.rb +5 -5
- data/lib/slack/smart-bot/utils/get_countries_candelarific.rb +18 -0
- data/lib/slack/smart-bot/utils/get_help.rb +21 -19
- data/lib/slack/smart-bot/utils/get_openai_sessions.rb +47 -0
- data/lib/slack/smart-bot/utils/get_personal_settings.rb +29 -3
- data/lib/slack/smart-bot/utils/get_rules_imported.rb +27 -6
- data/lib/slack/smart-bot/utils/get_shares.rb +1 -1
- data/lib/slack/smart-bot/utils/get_team_members.rb +4 -4
- data/lib/slack/smart-bot/utils/get_vacations.rb +15 -7
- data/lib/slack/smart-bot/utils/has_access.rb +10 -4
- data/lib/slack/smart-bot/utils/is_admin.rb +25 -17
- data/lib/slack/smart-bot/utils/local_time.rb +29 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +5 -3
- data/lib/slack/smart-bot/utils/update_access_channels.rb +19 -3
- data/lib/slack/smart-bot/utils/update_openai_sessions.rb +42 -0
- data/lib/slack/smart-bot/utils/update_personal_settings.rb +11 -3
- data/lib/slack/smart-bot/utils/update_rules_imported.rb +18 -3
- data/lib/slack/smart-bot/utils/update_vacations.rb +5 -2
- data/lib/slack/smart-bot/utils/upgrade_to_use_team_ids.rb +276 -0
- data/lib/slack/smart-bot/utils.rb +6 -1
- data/lib/slack-smart-bot.rb +181 -76
- data/lib/slack-smart-bot_general_commands.rb +10 -9
- data/whats_new.txt +30 -13
- metadata +128 -20
@@ -5,14 +5,22 @@ class SlackSmartBot
|
|
5
5
|
get_personal_settings()
|
6
6
|
@personal_settings.merge!(user_personal_settings)
|
7
7
|
end
|
8
|
-
user = Thread.current[:user]
|
9
|
-
|
8
|
+
user = Thread.current[:user].dup
|
9
|
+
team_id = user.team_id
|
10
|
+
team_id_user = Thread.current[:team_id_user]
|
11
|
+
|
12
|
+
unless Dir.exist?("#{config.path}/personal_settings/#{team_id}")
|
13
|
+
Dir.mkdir("#{config.path}/personal_settings/#{team_id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
personal_settings_file = File.join(config.path, "personal_settings/#{team_id}", "ps_#{user.name}.yaml")
|
10
17
|
|
11
18
|
File.open(personal_settings_file, 'w') {|file|
|
12
19
|
file.flock(File::LOCK_EX)
|
13
|
-
file.write(Utils::Encryption.encrypt(@personal_settings[
|
20
|
+
file.write(Utils::Encryption.encrypt(@personal_settings[team_id_user].to_yaml, config))
|
14
21
|
file.flock(File::LOCK_UN)
|
15
22
|
}
|
23
|
+
get_personal_settings() #to update the @personal_settings_hash
|
16
24
|
@datetime_personal_settings_file[personal_settings_file] = File.mtime(personal_settings_file)
|
17
25
|
end
|
18
26
|
end
|
@@ -1,8 +1,23 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
3
|
def update_rules_imported
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'yaml'
|
5
|
+
file_path = "#{config.path}/rules/rules_imported"
|
6
|
+
if File.exist?("#{file_path}.rb") #backwards compatible
|
7
|
+
file_conf = IO.readlines("#{file_path}.rb").join
|
8
|
+
if file_conf.to_s() == ""
|
9
|
+
@rules_imported = {}
|
10
|
+
else
|
11
|
+
@rules_imported = eval(file_conf)
|
12
|
+
end
|
13
|
+
File.open("#{file_path}.yaml", 'w') {|file| file.write(@rules_imported.to_yaml) }
|
14
|
+
File.delete("#{file_path}.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
File.open("#{file_path}.yaml", 'w') {|file|
|
18
|
+
file.flock(File::LOCK_EX)
|
19
|
+
file.write(@rules_imported.to_yaml)
|
20
|
+
file.flock(File::LOCK_UN)
|
21
|
+
}
|
7
22
|
end
|
8
23
|
end
|
@@ -6,11 +6,14 @@ class SlackSmartBot
|
|
6
6
|
@vacations.merge!(vacation)
|
7
7
|
end
|
8
8
|
user = Thread.current[:user]
|
9
|
-
|
9
|
+
team_id_user = Thread.current[:team_id_user]
|
10
|
+
#create folder if doesn't exist
|
11
|
+
FileUtils.mkdir_p(File.join(config.path, "vacations/#{user.team_id}")) unless File.exist?(File.join(config.path, "vacations/#{user.team_id}"))
|
12
|
+
vacations_file = File.join(config.path, "vacations/#{user.team_id}", "v_#{user.name}.yaml")
|
10
13
|
|
11
14
|
File.open(vacations_file, 'w') {|file|
|
12
15
|
file.flock(File::LOCK_EX)
|
13
|
-
file.write(Utils::Encryption.encrypt(@vacations[
|
16
|
+
file.write(Utils::Encryption.encrypt(@vacations[team_id_user].to_yaml, config))
|
14
17
|
file.flock(File::LOCK_UN)
|
15
18
|
}
|
16
19
|
@datetime_vacations_file[vacations_file] = File.mtime(vacations_file)
|
@@ -0,0 +1,276 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def upgrade_to_use_team_ids()
|
3
|
+
team_id = config.team_id
|
4
|
+
|
5
|
+
if Dir.exist?("#{config.path}/rules/") #admins_channels.yaml and access_channels.yaml
|
6
|
+
files_updated = []
|
7
|
+
Dir.glob(config.path + "/rules/**/*").select { |i| i[/admins_channels.yaml$/] }.each do |f|
|
8
|
+
t = YAML.load_file(f)
|
9
|
+
n = {}
|
10
|
+
t.each do |k, v|
|
11
|
+
if v.length > 0
|
12
|
+
# do it only if it is not already a team_id: /^[A-Z0-9]{7,11}_/
|
13
|
+
# if it matches the pattern, it is already with a team_id
|
14
|
+
# if it doesn't match the pattern, it is not with a team_id
|
15
|
+
n[k] = []
|
16
|
+
v.each do |m|
|
17
|
+
if !m.to_s.match?(/^[A-Z0-9]{7,11}_/)
|
18
|
+
n[k] << team_id.to_s + "_" + m
|
19
|
+
files_updated << f unless files_updated.include?(f)
|
20
|
+
else
|
21
|
+
n[k] << m
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
n[k] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
File.open(f, "w") { |f| f.write n.to_yaml } if files_updated.include?(f)
|
29
|
+
end
|
30
|
+
@logger.info "Updated admins_channels.yaml files to use team ids" unless files_updated.empty?
|
31
|
+
|
32
|
+
files_updated = []
|
33
|
+
Dir.glob(config.path + "/rules/**/*").select { |i| i[/access_channels.yaml$/] }.each do |f|
|
34
|
+
t = YAML.load_file(f)
|
35
|
+
n = {}
|
36
|
+
t.each do |k, v|
|
37
|
+
n[k] = {}
|
38
|
+
v.each do |k2, v2|
|
39
|
+
if v2.length > 0
|
40
|
+
# do it only if it is not already a team_id: /^[A-Z0-9]{7,11}_/
|
41
|
+
# if it matches the pattern, it is already with a team_id
|
42
|
+
# if it doesn't match the pattern, it is not with a team_id
|
43
|
+
n[k][k2] = []
|
44
|
+
v2.each do |m|
|
45
|
+
if !m.to_s.match?(/^[A-Z0-9]{7,11}_/)
|
46
|
+
n[k][k2] << team_id.to_s + "_" + m
|
47
|
+
files_updated << f unless files_updated.include?(f)
|
48
|
+
else
|
49
|
+
n[k][k2] << m
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
n[k][k2] = v2
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
File.open(f, "w") { |f| f.write n.to_yaml } if files_updated.include?(f)
|
58
|
+
|
59
|
+
end
|
60
|
+
@logger.info "Updated access_channels.yaml files to use team ids" unless files_updated.empty?
|
61
|
+
|
62
|
+
files_updated = []
|
63
|
+
|
64
|
+
Dir.glob(config.path + "/rules/*").select { |i| i[/rules_imported.yaml$/] }.each do |f|
|
65
|
+
t = YAML.load_file(f)
|
66
|
+
n = {}
|
67
|
+
t.each do |k, v|
|
68
|
+
if !k.to_s.match?(/^[A-Z0-9]{7,11}_/)
|
69
|
+
n["#{team_id.to_s}_#{k}"] = v
|
70
|
+
files_updated << f unless files_updated.include?(f)
|
71
|
+
else
|
72
|
+
n[k] = v
|
73
|
+
end
|
74
|
+
end
|
75
|
+
File.open(f, "w") { |f| f.write n.to_yaml } if files_updated.include?(f)
|
76
|
+
end
|
77
|
+
@logger.info "Updated rules_imported.yaml files to use team ids" unless files_updated.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
if Dir.exist?("#{config.path}/teams/")
|
81
|
+
files_updated = []
|
82
|
+
#todo: do it also for deleted memos files
|
83
|
+
Dir.entries("#{config.path}/teams/").select { |i| i[/\.yaml$/] }.each do |f|
|
84
|
+
t = YAML.load(Utils::Encryption.decrypt(File.read("#{config.path}/teams/#{f}"), config))
|
85
|
+
t[:members].each do |k, v|
|
86
|
+
n = []
|
87
|
+
v.each do |m|
|
88
|
+
if !m.to_s.match?(/^[A-Z0-9]{7,11}_/)
|
89
|
+
n << team_id.to_s + "_" + m
|
90
|
+
files_updated << f unless files_updated.include?(f)
|
91
|
+
else
|
92
|
+
n << m
|
93
|
+
end
|
94
|
+
end
|
95
|
+
t[:members][k] = n
|
96
|
+
end
|
97
|
+
|
98
|
+
# update memos.user and memos.comments.user_name
|
99
|
+
if t.key?(:memos)
|
100
|
+
t[:memos].each do |m|
|
101
|
+
if !m[:user].to_s.match?(/^[A-Z0-9]{7,11}_/)
|
102
|
+
m[:user] = team_id.to_s + "_" + m[:user]
|
103
|
+
files_updated << f unless files_updated.include?(f)
|
104
|
+
end
|
105
|
+
if m.key?(:comments)
|
106
|
+
m[:comments].each do |c|
|
107
|
+
if !c[:user_name].to_s.match?(/^[A-Z0-9]{7,11}_/)
|
108
|
+
c[:user_name] = team_id.to_s + "_" + c[:user_name]
|
109
|
+
files_updated << f unless files_updated.include?(f)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if !t[:user].to_s.match?(/^[A-Z0-9]{7,11}_/)
|
117
|
+
t[:user] = team_id.to_s + "_" + t[:user]
|
118
|
+
files_updated << f unless files_updated.include?(f)
|
119
|
+
end
|
120
|
+
if !t[:creator].to_s.match?(/^[A-Z0-9]{7,11}_/)
|
121
|
+
t[:creator] = team_id.to_s + "_" + t[:creator]
|
122
|
+
files_updated << f unless files_updated.include?(f)
|
123
|
+
end
|
124
|
+
if files_updated.include?(f)
|
125
|
+
File.open("#{config.path}/teams/#{f}", "w") { |file|
|
126
|
+
file.flock(File::LOCK_EX)
|
127
|
+
file.write(Utils::Encryption.encrypt(t.to_yaml, config))
|
128
|
+
file.flock(File::LOCK_UN)
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
@logger.info "Updated teams files to use team ids" unless files_updated.empty?
|
133
|
+
end
|
134
|
+
|
135
|
+
#add team_id to the user_name: team_id_user_name, exclude the key :all
|
136
|
+
if Dir.exist?("#{config.path}/shortcuts/")
|
137
|
+
files_updated = []
|
138
|
+
Dir.entries("#{config.path}/shortcuts/").select { |i| i[/\.yaml$/] }.each do |f|
|
139
|
+
t = YAML.load_file("#{config.path}/shortcuts/#{f}")
|
140
|
+
n = {}
|
141
|
+
t.each do |k, v|
|
142
|
+
if k != :all and !k.to_s.match?(/^[A-Z0-9]{7,11}_/)
|
143
|
+
n[team_id.to_s + "_" + k.to_s] = t[k]
|
144
|
+
files_updated << f unless files_updated.include?(f)
|
145
|
+
else
|
146
|
+
n[k] = t[k]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
File.open("#{config.path}/shortcuts/#{f}", "w") { |f| f.write n.to_yaml } if files_updated.include?(f)
|
150
|
+
end
|
151
|
+
@logger.info "Updated shortcuts files to use team ids" unless files_updated.empty?
|
152
|
+
end
|
153
|
+
|
154
|
+
#repl files are yaml
|
155
|
+
if Dir.exist?("#{config.path}/repl/")
|
156
|
+
files_updated = []
|
157
|
+
Dir.entries("#{config.path}/repl/").select { |i| i[/\.yaml$/] }.each do |f|
|
158
|
+
t = YAML.load_file("#{config.path}/repl/#{f}")
|
159
|
+
t.each do |k, v|
|
160
|
+
if v[:creator_team_id].to_s == ""
|
161
|
+
v[:creator_team_id] = team_id
|
162
|
+
files_updated << f unless files_updated.include?(f)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
File.open("#{config.path}/repl/#{f}", "w") { |f| f.write t.to_yaml } if files_updated.include?(f)
|
166
|
+
end
|
167
|
+
@logger.info "Updated repl files to use team ids" unless files_updated.empty?
|
168
|
+
end
|
169
|
+
|
170
|
+
if Dir.exist?("#{config.path}/routines/")
|
171
|
+
files_updated = []
|
172
|
+
Dir.entries("#{config.path}/routines/").select { |i| i[/\.yaml$/] }.each do |f|
|
173
|
+
t = YAML.load_file("#{config.path}/routines/#{f}")
|
174
|
+
t.each do |k, v|
|
175
|
+
v.each do |k2, v2|
|
176
|
+
if v2[:creator_team_id].to_s == ""
|
177
|
+
v2[:creator_team_id] = team_id
|
178
|
+
files_updated << f unless files_updated.include?(f)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
File.open("#{config.path}/routines/#{f}", "w") { |f| f.write t.to_yaml } if files_updated.include?(f)
|
183
|
+
end
|
184
|
+
@logger.info "Updated routines files to use team ids" unless files_updated.empty?
|
185
|
+
end
|
186
|
+
|
187
|
+
#shares files are csv
|
188
|
+
if Dir.exist?("#{config.path}/shares/")
|
189
|
+
Dir.entries("#{config.path}/shares/").select { |i| i[/\.csv$/] }.each do |f|
|
190
|
+
#verify if the file has the team_id already, in that case the number of columns should be 10
|
191
|
+
t = CSV.table("#{config.path}/shares/#{f}")
|
192
|
+
if t.headers.length == 8
|
193
|
+
t = CSV.table("#{config.path}/shares/#{f}", headers: ["share_id", "user_deleted", "user_created", "date", "time", "type", "to_channel", "condition"])
|
194
|
+
#save it in this order:
|
195
|
+
new_headers = ["share_id", "user_team_id_deleted", "user_deleted", "user_team_id_created", "user_created", "date", "time", "type", "to_channel", "condition"]
|
196
|
+
new_t = []
|
197
|
+
t.each do |m|
|
198
|
+
if m[:user_deleted].to_s == ""
|
199
|
+
user_team_id_deleted = ""
|
200
|
+
else
|
201
|
+
user_team_id_deleted = team_id
|
202
|
+
end
|
203
|
+
new_t << [m[:share_id], user_team_id_deleted, m[:user_deleted], team_id, m[:user_created], m[:date], m[:time], m[:type], m[:to_channel], m[:condition]]
|
204
|
+
end
|
205
|
+
CSV.open("#{config.path}/shares/#{f}", "wb") do |csv|
|
206
|
+
new_t.each do |row|
|
207
|
+
csv << row
|
208
|
+
end
|
209
|
+
end
|
210
|
+
@logger.info "Updated shares to use team ids"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
#announcements
|
216
|
+
if Dir.exist?("#{config.path}/announcements/")
|
217
|
+
Dir.entries("#{config.path}/announcements/").select { |i| i[/\.csv$/] }.each do |f|
|
218
|
+
#verify if the file has the team_id already, in that case the number of columns should be 9
|
219
|
+
t = CSV.table("#{config.path}/announcements/#{f}")
|
220
|
+
if t.headers.length == 7
|
221
|
+
t = CSV.table("#{config.path}/announcements/#{f}", headers: ["message_id", "user_deleted", "user_created", "date", "time", "type", "message"])
|
222
|
+
#save it in this order:
|
223
|
+
new_headers = ["message_id", "user_team_id_deleted", "user_deleted", "user_team_id_created", "user_created", "date", "time", "type", "message"]
|
224
|
+
new_t = []
|
225
|
+
t.each do |m|
|
226
|
+
if m[:user_deleted].to_s == ""
|
227
|
+
user_team_id_deleted = ""
|
228
|
+
else
|
229
|
+
user_team_id_deleted = team_id
|
230
|
+
end
|
231
|
+
new_t << [m[:message_id], user_team_id_deleted, m[:user_deleted], team_id, m[:user_created], m[:date], m[:time], m[:type], m[:message]]
|
232
|
+
end
|
233
|
+
CSV.open("#{config.path}/announcements/#{f}", "wb") do |csv|
|
234
|
+
new_t.each do |row|
|
235
|
+
csv << row
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
@logger.info "Updated announcements to use team ids"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
if Dir.exist?("#{config.path}/vacations/") and !Dir.exist?(config.path + "/vacations/" + team_id.to_s)
|
245
|
+
FileUtils.mkdir_p(config.path + "/vacations/" + team_id.to_s)
|
246
|
+
files_updated = []
|
247
|
+
Dir.glob(config.path + "/vacations/*").select { |i| i[/\.yaml$/] }.each do |f|
|
248
|
+
FileUtils.mv(f, config.path + "/vacations/" + team_id.to_s)
|
249
|
+
files_updated << f
|
250
|
+
end
|
251
|
+
@logger.info "Updated vacations to use team ids. All moved to #{config.path}/vacations/#{team_id}/" unless files_updated.empty?
|
252
|
+
end
|
253
|
+
|
254
|
+
if Dir.exist?("#{config.path}/openai/") and !Dir.exist?(config.path + "/openai/" + team_id.to_s)
|
255
|
+
FileUtils.mkdir_p(config.path + "/openai/" + team_id.to_s)
|
256
|
+
files_updated = []
|
257
|
+
Dir.glob(config.path + "/openai/*").each do |file_or_dir|
|
258
|
+
next if file_or_dir == config.path + "/openai/" + team_id.to_s
|
259
|
+
FileUtils.mv(file_or_dir, config.path + "/openai/" + team_id.to_s)
|
260
|
+
files_updated << file_or_dir
|
261
|
+
end
|
262
|
+
@logger.info "Updated openai to use team ids. All moved to #{config.path}/openai/#{team_id}/" unless files_updated.empty?
|
263
|
+
end
|
264
|
+
|
265
|
+
if Dir.exist?("#{config.path}/personal_settings/") and !Dir.exist?(config.path + "/personal_settings/" + team_id.to_s)
|
266
|
+
FileUtils.mkdir_p(config.path + "/personal_settings/" + team_id.to_s)
|
267
|
+
files_updated = []
|
268
|
+
Dir.glob(config.path + "/personal_settings/*").each do |file_or_dir|
|
269
|
+
next if file_or_dir == config.path + "/personal_settings/" + team_id.to_s
|
270
|
+
FileUtils.mv(file_or_dir, config.path + "/personal_settings/" + team_id.to_s)
|
271
|
+
files_updated << file_or_dir
|
272
|
+
end
|
273
|
+
@logger.info "Updated personal_settings to use team ids. All moved to #{config.path}/personal_settings/#{team_id}/" unless files_updated.empty?
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
@@ -36,4 +36,9 @@ require_relative 'utils/encryption/encryption_get_key_iv'
|
|
36
36
|
require_relative 'utils/encryption/encrypt'
|
37
37
|
require_relative 'utils/encryption/decrypt'
|
38
38
|
require_relative 'utils/get_team_members'
|
39
|
-
|
39
|
+
require_relative 'utils/get_openai_sessions'
|
40
|
+
require_relative 'utils/update_openai_sessions'
|
41
|
+
require_relative 'utils/local_time'
|
42
|
+
require_relative 'utils/get_countries_candelarific'
|
43
|
+
require_relative 'utils/upgrade_to_use_team_ids'
|
44
|
+
require_relative 'utils/find_user'
|