slack-smart-bot 1.9.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +184 -16
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  5. data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
  6. data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
  7. data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
  8. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  9. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  10. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  11. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  12. data/lib/slack/smart-bot/comm/react.rb +19 -2
  13. data/lib/slack/smart-bot/comm/respond.rb +224 -53
  14. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  15. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  16. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  17. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  18. data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
  19. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  20. data/lib/slack/smart-bot/comm.rb +4 -0
  21. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  22. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  23. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  24. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  25. data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
  26. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  27. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  28. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  29. data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
  30. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  31. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  32. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  33. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  34. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  35. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  36. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  37. data/lib/slack/smart-bot/commands/general/see_announcements.rb +115 -0
  38. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  39. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
  40. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  41. data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
  42. data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
  43. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  44. data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
  45. data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
  46. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
  47. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
  48. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
  50. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
  52. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
  53. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
  55. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
  56. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
  57. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -1
  58. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  59. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  60. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +34 -0
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
  62. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
  63. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
  64. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
  66. data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
  67. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
  68. data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
  69. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
  70. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  71. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -5
  72. data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
  73. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
  74. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
  75. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
  76. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
  77. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  78. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
  79. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
  80. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
  81. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
  82. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
  83. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
  84. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
  85. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  86. data/lib/slack/smart-bot/commands.rb +36 -5
  87. data/lib/slack/smart-bot/listen.rb +31 -33
  88. data/lib/slack/smart-bot/process.rb +234 -73
  89. data/lib/slack/smart-bot/process_first.rb +119 -38
  90. data/lib/slack/smart-bot/treat_message.rb +310 -237
  91. data/lib/slack/smart-bot/utils/build_help.rb +2 -2
  92. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  93. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  94. data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
  95. data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
  96. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  97. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  98. data/lib/slack/smart-bot/utils/get_help.rb +79 -73
  99. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  100. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  101. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  102. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  103. data/lib/slack/smart-bot/utils/has_access.rb +28 -0
  104. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  105. data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
  106. data/lib/slack/smart-bot/utils/save_status.rb +67 -0
  107. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  108. data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
  109. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  110. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  111. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  112. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  113. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  114. data/lib/slack/smart-bot/utils.rb +11 -0
  115. data/lib/slack-smart-bot.rb +72 -12
  116. data/lib/slack-smart-bot_general_commands.rb +61 -0
  117. data/lib/slack-smart-bot_general_rules.rb +5 -2
  118. data/lib/slack-smart-bot_rules.rb +43 -17
  119. data/whats_new.txt +20 -15
  120. metadata +76 -9
  121. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
@@ -1,11 +1,31 @@
1
1
  class SlackSmartBot
2
2
 
3
3
  def get_routines(channel = @channel_id)
4
- if File.exist?("#{config.path}/routines/routines_#{channel}.rb")
4
+ require 'yaml'
5
+ routines_file = "#{config.path}/routines/routines_#{channel}.yaml"
6
+
7
+ if File.exist?("#{config.path}/routines/routines_#{channel}.rb") #backwards compatible
5
8
  file_conf = IO.readlines("#{config.path}/routines/routines_#{channel}.rb").join
6
- unless file_conf.to_s() == ""
9
+ if file_conf.to_s() == ""
10
+ @routines = {}
11
+ else
7
12
  @routines = eval(file_conf)
8
13
  end
14
+ File.open(routines_file, 'w') {|file| file.write(@routines.to_yaml) }
15
+ File.delete("#{config.path}/routines/routines_#{channel}.rb")
16
+ end
17
+
18
+ if File.exist?(routines_file)
19
+ routines = @routines
20
+ 10.times do
21
+ routines = YAML.load(File.read(routines_file))
22
+ if routines.is_a?(Hash)
23
+ break
24
+ else
25
+ sleep (0.1*(rand(2)+1))
26
+ end
27
+ end
28
+ @routines = routines unless routines.is_a?(FalseClass)
9
29
  end
10
30
  end
11
31
  end
@@ -0,0 +1,12 @@
1
+ class SlackSmartBot
2
+
3
+ def get_shares()
4
+ channel = @channels_name[@channel_id]
5
+ if File.exist?("#{config.path}/shares/#{channel}.csv")
6
+ "#{config.path}/shares/#{channel}.csv"
7
+ t = CSV.table("#{config.path}/shares/#{channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
8
+ t.delete_if {|row| row[:user_deleted] != ''}
9
+ @shares[channel] = t
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ class SlackSmartBot
2
+ def get_teams
3
+ @teams ||= {}
4
+ teams_file = config.file_path.gsub(".rb", "_teams.yaml")
5
+ if File.exist?(teams_file)
6
+ if !defined?(@datetime_teams_file) or @datetime_teams_file != File.mtime(teams_file)
7
+ require 'yaml'
8
+ teams = @teams
9
+ 10.times do
10
+ teams = YAML.load(File.read(teams_file))
11
+ if teams.is_a?(Hash)
12
+ break
13
+ else
14
+ sleep (0.1*(rand(2)+1))
15
+ end
16
+ end
17
+ @teams = teams unless teams.is_a?(FalseClass)
18
+ @datetime_teams_file = File.mtime(teams_file)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ class SlackSmartBot
2
+ def has_access?(method, user = nil)
3
+ user = Thread.current[:user] if user.nil?
4
+ if config[:allow_access].key?(method) and !config[:allow_access][method].include?(user.name) and !config[:allow_access][method].include?(user.id) and
5
+ (!user.key?(:enterprise_user) or (user.key?(:enterprise_user) and !config[:allow_access][method].include?(user[:enterprise_user].id)))
6
+ respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
7
+ return false
8
+ else
9
+ if Thread.current[:typem] == :on_call
10
+ channel = Thread.current[:dchannel]
11
+ elsif Thread.current[:using_channel].to_s == ""
12
+ channel = Thread.current[:dest]
13
+ else
14
+ channel = Thread.current[:using_channel]
15
+ end
16
+ if !@access_channels.key?(channel) or !@access_channels[channel].key?(method.to_s) or @access_channels[channel][method.to_s].include?(user.name)
17
+ return true
18
+ else
19
+ if @admins_channels.key?(channel) and !@admins_channels[channel].empty?
20
+ respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{@admins_channels[channel].join(">, <@")}>"
21
+ else
22
+ respond "You don't have access to use this command, please contact an Admin to be able to use it."
23
+ end
24
+ return false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ class SlackSmartBot
2
+ def is_admin?(from=nil)
3
+ if from.nil?
4
+ user = Thread.current[:user]
5
+ from = user.name
6
+ end
7
+
8
+ if (Thread.current[:dchannel].to_s!='' and !@channels_creator.key?(Thread.current[:dchannel])) or
9
+ (Thread.current[:dest].to_s!='' and Thread.current[:dest][0]!='D' and !@channels_creator.key?(Thread.current[:dest])) or
10
+ (Thread.current[:using_channel].to_s!='' and !@channels_creator.key?(:using_channel))
11
+ get_channels_name_and_id()
12
+ end
13
+
14
+ if config.masters.include?(from) or
15
+ config.admins.include?(from) or
16
+ (Thread.current[:typem] == :on_call and @admins_channels.key?(Thread.current[:dchannel]) and @admins_channels[Thread.current[:dchannel]].include?(from)) or
17
+ (Thread.current[:using_channel].to_s == '' and @admins_channels.key?(Thread.current[:dest]) and @admins_channels[Thread.current[:dest]].include?(from)) or
18
+ (@admins_channels.key?(Thread.current[:using_channel]) and @admins_channels[Thread.current[:using_channel]].include?(from)) or
19
+ (Thread.current[:using_channel].to_s=='' and @channels_creator.key?(Thread.current[:dest]) and from == @channels_creator[Thread.current[:dest]]) or
20
+ (Thread.current[:typem] == :on_call and @channels_creator.key?(Thread.current[:dchannel]) and from == @channels_creator[Thread.current[:dchannel]]) or
21
+ (@channels_creator.key?(Thread.current[:using_channel]) and from == @channels_creator[Thread.current[:using_channel]])
22
+ return true
23
+ else
24
+ return false
25
+ end
26
+ end
27
+ end
@@ -1,45 +1,50 @@
1
1
  class SlackSmartBot
2
-
3
- def save_stats(method, data: {})
4
- if config.stats
5
- begin
6
- require 'csv'
7
- if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
8
- CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", 'wb') do |csv|
9
- csv << ['date','bot_channel', 'bot_channel_id', 'dest_channel', 'dest_channel_id', 'type_message', 'user_name', 'user_id', 'text', 'command', 'files']
10
- end
11
- end
12
- if data.empty?
13
- data = {
14
- dest: Thread.current[:dest],
15
- typem: Thread.current[:typem],
16
- user: Thread.current[:user],
17
- files: Thread.current[:files?],
18
- command: Thread.current[:command],
19
- routine: Thread.current[:routine]
20
- }
21
- end
22
- if method.to_s == 'ruby_code' and data.files
23
- command_txt = 'ruby'
24
- else
25
- command_txt = data.command
26
- end
27
-
28
- if data.routine
29
- user_name = "routine/#{data.user.name}"
30
- user_id = "routine/#{data.user.id}"
31
- else
32
- user_name = data.user.name
33
- user_id = data.user.id
34
- end
35
- CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", "a+") do |csv|
36
- csv << [Time.now, config.channel, @channel_id, @channels_name[data.dest], data.dest, data.typem, user_name, user_id, command_txt, method, data.files]
37
- end
38
- rescue Exception => exception
39
- @logger.fatal "There was a problem on the stats"
40
- @logger.fatal exception
2
+ def save_stats(method, data: {})
3
+ if has_access?(method, Thread.current[:user])
4
+ if config.stats
5
+ begin
6
+ require "csv"
7
+ if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
8
+ CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", "wb") do |csv|
9
+ csv << ["date", "bot_channel", "bot_channel_id", "dest_channel", "dest_channel_id", "type_message", "user_name", "user_id", "text", "command", "files"]
41
10
  end
11
+ end
12
+ if data.empty?
13
+ data = {
14
+ dest: Thread.current[:dest],
15
+ typem: Thread.current[:typem],
16
+ user: Thread.current[:user],
17
+ files: Thread.current[:files?],
18
+ command: Thread.current[:command],
19
+ routine: Thread.current[:routine],
20
+ }
21
+ end
22
+ if method.to_s == "ruby_code" and data.files
23
+ command_txt = "ruby"
24
+ else
25
+ command_txt = data.command
26
+ end
27
+ command_txt.gsub!(/```.+```/m, "```CODE```")
28
+ command_txt = "#{command_txt[0..99]}..." if command_txt.size > 100
29
+
30
+ if data.routine
31
+ user_name = "routine/#{data.user.name}"
32
+ user_id = "routine/#{data.user.id}"
33
+ else
34
+ user_name = data.user.name
35
+ user_id = data.user.id
36
+ end
37
+ CSV.open("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log", "a+") do |csv|
38
+ csv << [Time.now, config.channel, @channel_id, @channels_name[data.dest], data.dest, data.typem, user_name, user_id, command_txt, method, data.files]
39
+ end
40
+ rescue Exception => exception
41
+ @logger.fatal "There was a problem on the stats"
42
+ @logger.fatal exception
42
43
  end
44
+ end
45
+ else
46
+ sleep 0.2
47
+ Thread.exit
43
48
  end
44
-
45
- end
49
+ end
50
+ end
@@ -0,0 +1,67 @@
1
+ class SlackSmartBot
2
+
3
+ def save_status(status, status_id, message)
4
+ require 'csv'
5
+ Dir.mkdir("#{config.path}/status") unless Dir.exist?("#{config.path}/status")
6
+
7
+ CSV.open("#{config.path}/status/#{config.channel}_status.csv", "a+") do |csv|
8
+ csv << [Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M:%S"), status, status_id, message]
9
+ end
10
+ if defined?(@channels_list) #wait until the 'client' started
11
+ channel_info = @channels_list.select { |c| c.id == @channel_id}[-1]
12
+ if channel_info.nil? or channel_info.is_private
13
+ channel_link = "##{config.channel}"
14
+ else
15
+ channel_link = "<##{@channel_id}|#{config.channel}>"
16
+ end
17
+ else
18
+ channel_link = "##{config.channel}"
19
+ end
20
+
21
+ if status_id == :disconnected
22
+ Thread.new do
23
+ sleep 50
24
+ @logger.info "check disconnection 50 scs later #{@last_notified_status_id}"
25
+ unless @last_notified_status_id == :connected
26
+ respond ":red_circle: The *SmartBot* on *#{channel_link}* is down. An admin will take a look. <@#{config.admins.join(">, <@")}>", config.status_channel
27
+ end
28
+ end
29
+ end
30
+ if @channels_id.is_a?(Hash) and @channels_id.keys.include?(config.status_channel)
31
+ is_back = false
32
+ m = ''
33
+ if (Time.now-@last_status_change) > 20 or !defined?(@last_notified_status_id)
34
+ if status_id == :connected
35
+ if defined?(@last_notified_status_id)
36
+ m = ":exclamation: :large_green_circle: The *SmartBot* on *#{channel_link}* was not available for #{(Time.now-@last_status_change).round(0)} secs. *Now it is up and running again.*"
37
+ else
38
+ m = ":large_green_circle: The *SmartBot* on *#{channel_link}* is up and running again."
39
+ end
40
+ end
41
+ end
42
+ if status_id == :paused
43
+ m = ":red_circle: #{message} *#{channel_link}*"
44
+ elsif status_id == :started
45
+ m = ":large_green_circle: #{message} *#{channel_link}*"
46
+ elsif status_id == :killed or status_id == :exited
47
+ m = ":red_circle: #{message}"
48
+ elsif config.on_master_bot and status_id == :maintenance_on
49
+ if message.to_s == "Sorry I'm on maintenance so I cannot attend your request."
50
+ m = ":red_circle: The *SmartBot* is on maintenance so not possible to attend any request."
51
+ else
52
+ m = ":red_circle: #{message}"
53
+ end
54
+ elsif config.on_master_bot and status_id == :maintenance_off
55
+ m = ":large_green_circle: The *SmartBot* is up and running again."
56
+ end
57
+ @last_status_change = Time.now
58
+ @last_notified_status_id = status_id
59
+ unless m == ''
60
+ respond m, config.status_channel
61
+ end
62
+ end
63
+
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,8 @@
1
+ class SlackSmartBot
2
+
3
+ def update_access_channels()
4
+ file = File.open("#{config.path}/rules/#{@channel_id}/access_channels.rb", "w")
5
+ file.write (@access_channels.inspect)
6
+ file.close
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class SlackSmartBot
2
+
3
+ def update_admins_channels()
4
+ file = File.open("#{config.path}/rules/#{@channel_id}/admins_channels.rb", "w")
5
+ file.write (@admins_channels.inspect)
6
+ file.close
7
+ end
8
+ end
@@ -1,11 +1,32 @@
1
1
  class SlackSmartBot
2
2
  def update_bots_file
3
- file = File.open(config.file_path.gsub(".rb", "_bots.rb"), "w")
4
- bots_created = @bots_created.dup
5
- bots_created.each { |k, v|
6
- v[:thread] = ""
7
- }
8
- file.write bots_created.inspect
9
- file.close
3
+ bots_file = config.file_path.gsub(".rb", "_bots.yaml")
4
+
5
+ if File.exist?(config.file_path.gsub(".rb", "_bots.rb")) #backwards compatible
6
+ file_conf = IO.readlines(config.file_path.gsub(".rb", "_bots.rb")).join
7
+ if file_conf.to_s() == ""
8
+ @bots_created = {}
9
+ else
10
+ @bots_created = eval(file_conf)
11
+ end
12
+ File.open(bots_file, 'w') {|file|
13
+ file.flock(File::LOCK_EX)
14
+ file.write(@bots_created.to_yaml)
15
+ file.flock(File::LOCK_UN)
16
+ }
17
+ File.delete(config.file_path.gsub(".rb", "_bots.rb"))
18
+ else
19
+ #not possible to use @bots_created.deep_copy since one of the fields contains a thread
20
+ bots_created = {}
21
+ @bots_created.each do |k,v|
22
+ bots_created[k] = v.dup
23
+ bots_created[k][:thread] = ''
24
+ end
25
+ File.open(bots_file, 'w') {|file|
26
+ file.flock(File::LOCK_EX)
27
+ file.write(bots_created.to_yaml)
28
+ file.flock(File::LOCK_UN)
29
+ }
30
+ end
10
31
  end
11
32
  end
@@ -1,8 +1,11 @@
1
1
  class SlackSmartBot
2
-
3
2
  def update_repls(channel = @channel_id)
4
- file = File.open("#{config.path}/repl/repls_#{channel}.rb", "w")
5
- file.write (@repls.inspect)
6
- file.close
3
+ require 'yaml'
4
+ repl_file = "#{config.path}/repl/repls_#{channel}.yaml"
5
+ File.open(repl_file, 'w') {|file|
6
+ file.flock(File::LOCK_EX)
7
+ file.write(@repls.to_yaml)
8
+ file.flock(File::LOCK_UN)
9
+ }
7
10
  end
8
11
  end
@@ -1,8 +1,11 @@
1
1
  class SlackSmartBot
2
2
 
3
3
  def update_routines(channel = @channel_id)
4
+
5
+ require 'yaml'
6
+ routines_file = "#{config.path}/routines/routines_#{channel}.yaml"
7
+
4
8
  routines = {}
5
- file = File.open("#{config.path}/routines/routines_#{channel}.rb", "w")
6
9
  @routines.each do |k,v|
7
10
  routines[k]={}
8
11
  v.each do |kk,vv|
@@ -10,7 +13,10 @@ class SlackSmartBot
10
13
  routines[k][kk][:thread]=""
11
14
  end
12
15
  end
13
- file.write (routines.inspect)
14
- file.close
16
+ File.open(routines_file, 'w') {|file|
17
+ file.flock(File::LOCK_EX)
18
+ file.write(routines.to_yaml)
19
+ file.flock(File::LOCK_UN)
20
+ }
15
21
  end
16
22
  end
@@ -1,13 +1,20 @@
1
1
  class SlackSmartBot
2
2
  def update_shortcuts_file
3
- file = File.open("#{config.path}/shortcuts/#{config.shortcuts_file}", "w")
4
- file.write @shortcuts.inspect
5
- file.close
3
+ require 'yaml'
4
+ sc_file = "#{config.path}/shortcuts/#{config.shortcuts_file}"
5
+ File.open(sc_file, 'w') {|file|
6
+ file.flock(File::LOCK_EX)
7
+ file.write(@shortcuts.to_yaml)
8
+ file.flock(File::LOCK_UN)
9
+ }
6
10
 
7
11
  if config.on_master_bot
8
- file = File.open("#{config.path}/shortcuts/shortcuts_global.rb", "w")
9
- file.write @shortcuts_global.inspect
10
- file.close
12
+ sc_file = "#{config.path}/shortcuts/shortcuts_global.yaml"
13
+ File.open(sc_file, 'w') {|file|
14
+ file.flock(File::LOCK_EX)
15
+ file.write(@shortcuts_global.to_yaml)
16
+ file.flock(File::LOCK_UN)
17
+ }
11
18
  end
12
19
  end
13
20
  end
@@ -0,0 +1,16 @@
1
+ class SlackSmartBot
2
+ def update_teams(team=nil)
3
+ require 'yaml'
4
+ unless team.nil?
5
+ get_teams()
6
+ @teams.merge!(team)
7
+ end
8
+ teams_file = config.file_path.gsub(".rb", "_teams.yaml")
9
+ File.open(teams_file, 'w') {|file|
10
+ file.flock(File::LOCK_EX)
11
+ file.write(@teams.to_yaml)
12
+ file.flock(File::LOCK_UN)
13
+ }
14
+ @datetime_teams_file = File.mtime(teams_file)
15
+ end
16
+ end
@@ -4,6 +4,7 @@ require_relative 'utils/get_bots_created'
4
4
  require_relative 'utils/get_channels_name_and_id'
5
5
  require_relative 'utils/get_help'
6
6
  require_relative 'utils/get_routines'
7
+ require_relative 'utils/get_shares'
7
8
  require_relative 'utils/get_rules_imported'
8
9
  require_relative 'utils/remove_hash_keys'
9
10
  require_relative 'utils/update_bots_file'
@@ -15,4 +16,14 @@ require_relative 'utils/get_repls'
15
16
  require_relative 'utils/update_repls'
16
17
  require_relative 'utils/answer'
17
18
  require_relative 'utils/answer_delete'
19
+ require_relative 'utils/has_access'
20
+ require_relative 'utils/save_status'
21
+ require_relative 'utils/get_admins_channels'
22
+ require_relative 'utils/update_admins_channels'
23
+ require_relative 'utils/is_admin'
24
+ require_relative 'utils/get_access_channels'
25
+ require_relative 'utils/update_access_channels'
26
+ require_relative 'utils/get_command_ids'
27
+ require_relative 'utils/get_teams'
28
+ require_relative 'utils/update_teams'
18
29