work in progress

pull/1/head
Aaron Johnson 6 years ago
parent bae69e99ca
commit 7a5afa2f9c

@ -9,4 +9,10 @@ allowed_sources:
- 'private'
- 'group'
- 'supergroup'
probes:
srv1:
loc: 'Office'
srv2:
loc: 'Area 50.1'
srv3:
loc: 'Dungeon'

@ -36,7 +36,24 @@ end
def process_command_check(message, command, adm)
if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
reply = `cat fakeoutput.txt`
#reply = `scripts/tempf.py`
#some interactive code to select a probe
select_loc = "Aisle 12-3"
#end interactive code
#probe = @probes[0] #set manually for now
reply = ""
hostdata = host_lookup(select_loc)
puts "var:".blue+" hostdata".blue.bold+"::".bold + hostdata.to_s
if ! hostdata.empty?
hostdata.each do |k,v|
puts "match:".blue+" host".blue.bold+"::".bold + k.to_s
reply += k.to_s+"\n"
end
else
reply = "No matching locations!"
puts "hostdata is empty!"
end
puts reply
else
reply = "I am not authorized to provide this information here."
end

@ -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

Loading…
Cancel
Save