From 56630ad5b0de999e86615ce752ee7dbd2a003c87 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Tue, 7 May 2019 14:35:32 -0500 Subject: [PATCH] Improved and colorized logging --- commands.rb | 16 ++++++++-------- run.rb | 11 +++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/commands.rb b/commands.rb index a2f54a9..69479b0 100644 --- a/commands.rb +++ b/commands.rb @@ -13,26 +13,26 @@ def message_from_admin?(message, adm) #puts message.from.id #puts adm if adm.include?(message.from.id) - puts "Command is from an admin. [#{message.from.username}]" + puts "Command is from an admin. [" + "#{message.from.username}".cyan.bold + "]" return true else - puts "Command is NOT from an admin! [#{message.from.username}]" + puts "Command is NOT from an admin! [" + "#{message.from.username}".yellow.bold + "]" return false end end def is_chat_authorized?(message, auth_chat) if auth_chat.include?(message.chat.id) - puts "Group [#{message.chat.id}][#{message.chat.title}] is authorized" + puts "Group [" + "#{message.chat.id}".green.bold + "][" + "#{message.chat.title}".green + "] is authorized" return true else - puts "Group [#{message.chat.id}][#{message.chat.title}] is NOT authorized!" + puts "Group [" + "#{message.chat.id}".red.bold + "][" + "#{message.chat.title}".red + "] is NOT authorized!" return false end end def process_command_srvstart(message, command, adm) - puts "Received command: srvstart" + puts "Received command: " + "srvstart".green #pp message from_admin = message_from_admin?(message, adm) auth_grp = is_chat_authorized?(message, @auth_chat) @@ -52,7 +52,7 @@ def process_command_srvstart(message, command, adm) end def process_command_srvstop(message, command, adm) - puts "Received command: srvstop" + puts "Received command: " + "srvstop".red from_admin = message_from_admin?(message, adm) auth_grp = is_chat_authorized?(message, @auth_chat) if ! auth_grp && ! from_admin @@ -79,11 +79,11 @@ def process_command_srvstatus(message, command, adm) if `./scripts/srvstatus.receipt #{@conf['token']} #{message.chat.id}` print "Receipt sent!\nFetching details...\n" else - print "Receipt FAILED to send (non-zero exit code on scripts/srvstatus.receipt) !!!\nContinuing to fetch details anyway...\n" + print "Receipt FAILED to send (non-zero exit code on scripts/srvstatus.receipt) !!!\nContinuing to fetch details anyway...\n".red.bold end reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}` else - print "Server did not respond!\nSending failure message...\n" + print "Server did not respond!\nSending failure message...\n".red.bold reply = "Server is not responding!" end STDOUT.flush diff --git a/run.rb b/run.rb index 6f89176..ffb7284 100755 --- a/run.rb +++ b/run.rb @@ -69,7 +69,7 @@ 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".red.bold else - print "Environment appears sane.\n\n".cyan.bold + print "Environment appears sane.\n\n".green.bold end ### End sanity check ### @@ -123,7 +123,7 @@ def handle_message(message) #conf = YAML.load_file("bot_config.yaml") telnet = @conf['telnet'] adm = @conf['admin'] - puts "Received command from #{message.from.username}: #{command}" + puts "Received command from " + "#{message.from.username}".cyan.bold + ": #{command}" case command when '/start' reply = "Introduction: I am #{@botname}, and I am here to make life easier for meatbag admins like you. Currently I can retrieve information " + @@ -133,7 +133,7 @@ def handle_message(message) "You can also view the source code at the following location:\nhttps://git.skyfall.tech/skyfall/empyrion-bot" if ! message_from_admin?(message, adm) && ! is_chat_authorized?(message, @auth_chat) if message.from.id == message.chat.id - reply = reply + "\n\nWARNING: I am not authorized to work you directly. My functionality is limited." + reply = reply + "\n\nWARNING: I am not authorized to work with you directly. My functionality is limited." else reply = reply + "\n\nWARNING: I am not authorized to participate with this group. My functionality is limited." end @@ -146,11 +146,6 @@ def handle_message(message) reply = process_command_srvstop(message, command, adm) when '/status' reply = process_command_srvstatus(message, command, adm) - #if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) - # reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}` - #else - # reply = "Refusal: I am not authorized to provide this information here." - #end when '/patch', '/patchnotes' reply = process_command_patchnotes(message, command, adm) when '/location', '/whereareyou'