|
|
|
@ -20,6 +20,7 @@ token = @conf['token']
|
|
|
|
|
admin = @conf['admin']
|
|
|
|
|
@auth_chat = @conf['authorized_chats']
|
|
|
|
|
@allowed_sources = @conf['allowed_sources']
|
|
|
|
|
@probes = @conf['probes']
|
|
|
|
|
|
|
|
|
|
### Begin sanity check ###
|
|
|
|
|
STDOUT.sync = true
|
|
|
|
@ -104,6 +105,14 @@ if errcount > 0
|
|
|
|
|
else
|
|
|
|
|
print "Environment appears sane.\n\n".green.bold
|
|
|
|
|
end
|
|
|
|
|
if @probes.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
|
|
|
|
|
|
|
|
|
|
STDOUT.sync = false
|
|
|
|
|
### End sanity check ###
|
|
|
|
|
puts "Starting [#{@botname}]...\n\n"
|
|
|
|
@ -114,6 +123,13 @@ puts "Temporary direcotry: #{@tmpdir}"
|
|
|
|
|
puts "Start time: " + timestamp + "\n\n\n\n"
|
|
|
|
|
STDOUT.flush
|
|
|
|
|
|
|
|
|
|
def host_lookup(select_loc)
|
|
|
|
|
#@probes.select { |k,v| v['loc'] == select_loc }.each do |host,loc|
|
|
|
|
|
# return host
|
|
|
|
|
#end
|
|
|
|
|
return @probes.select { |k,v| v['loc'] == select_loc }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_message(message)
|
|
|
|
|
if ! message.reply_to_message.nil? then
|
|
|
|
|
#drop message. Someone's replying to a message
|
|
|
|
@ -186,7 +202,7 @@ def handle_message(message)
|
|
|
|
|
reply = "Sorry, #{command} is not a valid command."
|
|
|
|
|
end
|
|
|
|
|
# Verbose output:
|
|
|
|
|
puts timestamp + ": Sending #{reply.inspect}\n\n"
|
|
|
|
|
#print timestamp + ": Sending #{reply.inspect} ..... "
|
|
|
|
|
STDOUT.flush
|
|
|
|
|
return reply
|
|
|
|
|
end
|
|
|
|
@ -198,8 +214,14 @@ Telegram::Bot::Client.run(token) do |bot|
|
|
|
|
|
#puts "DEBUG: #{validation}"
|
|
|
|
|
if validation
|
|
|
|
|
reply = handle_message(message)
|
|
|
|
|
print timestamp + ": Sending ..... "
|
|
|
|
|
if ! message.text.nil?
|
|
|
|
|
bot.api.send_message(chat_id: message.chat.id, text: "#{reply}")
|
|
|
|
|
print "OK\n".green.bold
|
|
|
|
|
puts "Sent: #{reply.inspect}\n\n"
|
|
|
|
|
else
|
|
|
|
|
print 'FAIL'.red.bold
|
|
|
|
|
print " (Message is NULL)\n\n"
|
|
|
|
|
end
|
|
|
|
|
STDOUT.flush
|
|
|
|
|
else
|
|
|
|
|