Added /c alias and sanity check for temperature unit conf

pull/2/head
Aaron Johnson 6 years ago
parent 78bd688a0b
commit e8f44866c3

@ -22,6 +22,7 @@ admin = @conf['admin']
@auth_chat = @conf['authorized_chats'] @auth_chat = @conf['authorized_chats']
@allowed_sources = @conf['allowed_sources'] @allowed_sources = @conf['allowed_sources']
@probes = @conf['probes'] @probes = @conf['probes']
@tunit = @conf['units']
### Begin sanity check ### ### Begin sanity check ###
STDOUT.sync = true STDOUT.sync = true
@ -100,6 +101,14 @@ if @auth_chat.nil?
else else
print "OK\n".green.bold print "OK\n".green.bold
end end
print "Checking temperature units .............. "
if @tunit.nil?
errcount += 1
print "FAIL!\n\n".red.bold
puts "Error(#{errcount.to_s}): No temperature probes configured! Bot will serve no purpose. Continuing anyway....\n\n"
else
print "OK\n".green.bold
end
print "Checking probes list .................... " print "Checking probes list .................... "
if @probes.nil? if @probes.nil?
errcount += 1 errcount += 1
@ -122,6 +131,11 @@ puts "Authorized administrator IDs: #{admin}"
puts "Authorized chat IDs: #{@auth_chat}" puts "Authorized chat IDs: #{@auth_chat}"
puts "Bot token: #{@token}" puts "Bot token: #{@token}"
puts "Temporary direcotry: #{@tmpdir}" puts "Temporary direcotry: #{@tmpdir}"
puts "Temperature unit: #{@tunit}"
puts "Probes loaded:"
@probes.each do |k,v|
puts " [#{k}] #{v["loc"].to_s}"
end
puts "Start time: " + timestamp + "\n\n\n\n" puts "Start time: " + timestamp + "\n\n\n\n"
STDOUT.flush STDOUT.flush
@ -148,7 +162,7 @@ def ack_callback(message, display_message = true)
begin begin
Telegram::Bot::Client.run(@token) do |bot| Telegram::Bot::Client.run(@token) do |bot|
if display_message == true if display_message == true
bot.api.editMessageText(chat_id: message.message.chat.id, message_id: message.message.message_id, text: "#{message.from.username}Request received. Please wait...", reply_markup: "") #Removes buttons. Changes text bot.api.editMessageText(chat_id: message.message.chat.id, message_id: message.message.message_id, text: "Request received. Please wait...", reply_markup: "") #Removes buttons. Changes text
bot.api.answerCallbackQuery(callback_query_id: message.id, show_alert: false, text: "Request received. Please wait...") #Sends a pop-up notification bot.api.answerCallbackQuery(callback_query_id: message.id, show_alert: false, text: "Request received. Please wait...") #Sends a pop-up notification
else else
bot.api.deleteMessage(chat_id: message.message.chat.id, message_id: message.message.message_id) #Deletes message and buttons bot.api.deleteMessage(chat_id: message.message.chat.id, message_id: message.message.message_id) #Deletes message and buttons
@ -245,7 +259,7 @@ def handle_message(message)
process_command_location(message, command, adm) process_command_location(message, command, adm)
when '/whoami', '/chatinfo' when '/whoami', '/chatinfo'
process_command_chatinfo(message) process_command_chatinfo(message)
when '/check' when '/check', '/c'
process_command_check(message, command, adm) process_command_check(message, command, adm)
when '/test' when '/test'
process_command_test(message, command, adm) process_command_test(message, command, adm)

Loading…
Cancel
Save