Module: Cryptum::BotConf

Defined in:
lib/cryptum/bot_conf.rb

Overview

This plugin is used to read and update bot conf files.

Class Method Summary collapse

Class Method Details

.helpObject

Display Usage for this Module



70
71
72
73
74
# File 'lib/cryptum/bot_conf.rb', line 70

public_class_method def self.help
  puts "USAGE:
    logger = #{self}.create()
  "
end

.read(opts = {}) ⇒ Object

Deserialize Cryptum Bot Conf



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cryptum/bot_conf.rb', line 9

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(opts = {}) ⇒ Object

Update Key/Value Pair in Bot Conf and Serialize to YAML File



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cryptum/bot_conf.rb', line 42

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