Improved sanity check; addition of colors.rb

pull/11/head
Aaron Johnson 6 years ago
parent e8873c0808
commit 36ffd9e4e5

@ -0,0 +1,26 @@
class String
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def brown; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def magenta; "\e[35m#{self}\e[0m" end
def cyan; "\e[36m#{self}\e[0m" end
def gray; "\e[37m#{self}\e[0m" end
def bg_black; "\e[40m#{self}\e[0m" end
def bg_red; "\e[41m#{self}\e[0m" end
def bg_green; "\e[42m#{self}\e[0m" end
def bg_brown; "\e[43m#{self}\e[0m" end
def bg_blue; "\e[44m#{self}\e[0m" end
def bg_magenta; "\e[45m#{self}\e[0m" end
def bg_cyan; "\e[46m#{self}\e[0m" end
def bg_gray; "\e[47m#{self}\e[0m" end
def bold; "\e[1m#{self}\e[22m" end
def italic; "\e[3m#{self}\e[23m" end
def underline; "\e[4m#{self}\e[24m" end
def blink; "\e[5m#{self}\e[25m" end
def reverse_color; "\e[7m#{self}\e[27m" end
end

@ -5,6 +5,7 @@ require 'yaml'
require 'telegram/bot'
require 'pp'
require_relative 'commands.rb'
require_relative 'colors.rb'
#conf = YAML.load(File.read("bot_config.yaml"))
@conf = YAML.load_file("bot_config.yaml")
@ -18,56 +19,57 @@ admin = @conf['admin']
### Begin sanity check ###
errcount = 0
puts "Checking if environment is sane...\n\n"
print "Checking for presence of a bot token .... "
print "Checking bot token ...................... "
if token.nil?
print "FAIL!\n\n"
print "FAIL!\n\n".red.bold
puts "No bot token defined in bot_config.yaml!\nTHIS IS REQUIRED! Bot initialization failed; exiting..."
exit(1)
else
print "OK!\n"
print "OK\n".green.bold
end
print "Checking for defined bot name ........... "
print "Checking configured bot name ............ "
if @botname.nil?
errcount += 1
print "FAIL!\n\n"
print "FAIL!\n\n".red.bold
puts "Error(#{errcount.to_s}): No bot name defined. This is superficial. We'll call him Bob.\n\n"
@botname = "Bob"
else
print "OK!\n"
print "OK\n".green.bold
end
print "Checking for telnet configuration ....... "
print "Checking telnet configuration ........... "
if telnet.nil?
errcount += 1
print "FAIL!\n\n"
print "FAIL!\n\n".red.bold
puts "Error(#{errcount.to_s}): No telnet information provided in bot_config.yaml.\nThis is required for nearly all Empyrion-related " +
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will return broken messages)\n\n"
else
print "OK!\n"
print "OK\n".green.bold
end
print "Checking for administrators ............. "
print "Checking administrators ................. "
if admin.nil?
errcount += 1
print "FAIL!\n\n"
print "FAIL!\n\n".red.bold
puts "Error(#{errcount.to_s}): No admin Telegram IDs provided in bot_config.yaml.\nThis is required for many functions.\n" +
"THIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
admin = ["0"]
else
print "OK!\n"
print "OK\n".green.bold
end
print "Checking for authorised chats ........... "
print "Checking authorised chats ............... "
if @auth_chat.nil?
errcount += 1
print "FAIL!\n\n".red.bold
puts "Error(#{errcount.to_s}): No authorized Telegram group IDs provided in bot_config.yaml.\nThis is required for most Empyrion-related " +
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
@auth_chat = ["0"]
else
print "OK!\n"
print "OK\n".green.bold
end
puts "Errors found: #{errcount.to_s}\n\n"
if errcount > 0
print "Environment is grinning and holding a spatula. Please review your configuration.\n\n"
print "Environment is grinning and holding a spatula. Please review your configuration.\n\n".red.bold
else
print "Environment appears sane.\n\n"
print "Environment appears sane.\n\n".cyan.bold
end
### End sanity check ###

Loading…
Cancel
Save