lib/slack/smart-bot/utils/get_repls.rb in slack-smart-bot-1.10.0 vs lib/slack/smart-bot/utils/get_repls.rb in slack-smart-bot-1.11.0
- old
+ new
@@ -1,11 +1,31 @@
class SlackSmartBot
def get_repls(channel = @channel_id)
- if File.exist?("#{config.path}/repl/repls_#{channel}.rb")
+ require 'yaml'
+ repl_file = "#{config.path}/repl/repls_#{channel}.yaml"
+
+ if File.exist?("#{config.path}/repl/repls_#{channel}.rb") #backwards compatible
file_conf = IO.readlines("#{config.path}/repl/repls_#{channel}.rb").join
- unless file_conf.to_s() == ""
+ if file_conf.to_s() == ""
+ @repls = {}
+ else
@repls = eval(file_conf)
end
+ File.open(repl_file, 'w') {|file| file.write(@repls.to_yaml) }
+ File.delete("#{config.path}/repl/repls_#{channel}.rb")
+ end
+
+ if File.exist?(repl_file)
+ repls = @repls
+ 10.times do
+ repls = YAML.load(File.read(repl_file))
+ if repls.is_a?(Hash)
+ break
+ else
+ sleep (0.1*(rand(2)+1))
+ end
+ end
+ @repls = repls unless repls.is_a?(FalseClass)
end
end
end