# frozen_string_literal: true require 'logger' module Cryptum # This plugin is used to read and update bot conf files. module BotConf # Deserialize Cryptum Bot Conf public_class_method def self.read(opts = {}) option_choice = opts[:option_choice] bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml" unless File.exist?(bot_conf_file) FileUtils.cp( "#{option_choice.repo_root}/etc/bot_confs/BOT_CONF.TEMPLATE", bot_conf_file ) end YAML.load_file( bot_conf_file, symbolize_names: true ) rescue Errno::ENOENT, NoMethodError => e File.open('/tmp/cryptum-errors.txt', 'a') do |f| f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z') f.puts "Module: #{self}" f.puts "#{e}\n\n\n" end retry rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end # Update Key/Value Pair in Bot Conf and Serialize to YAML File public_class_method def self.update(opts = {}) option_choice = opts[:option_choice] bot_conf = opts[:bot_conf] key = opts[:key].to_s.to_sym value = opts[:value] bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml" bot_conf[key] = value File.write(bot_conf_file, bot_conf.to_yaml) rescue Errno::ENOENT, NoMethodError => e File.open('/tmp/cryptum-errors.txt', 'a') do |f| f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z') f.puts "Module: #{self}" f.puts "#{e}\n\n\n" end retry rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end # Display Usage for this Module public_class_method def self.help puts "USAGE: logger = #{self}.create() " end end end