You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
heatbot/commands.rb

91 lines
3.1 KiB

def validate_incoming_data(message)
auth_chat = @conf['auth_chat']
message = message.message if message.is_a? Telegram::Bot::Types::CallbackQuery
return "Received message is not from a valid source! Type: \"#{message.chat.type}\". Ignoring." if ! @allowed_sources.include?(message.chat.type)
return true
end
def message_from_admin?(message, adm)
if adm.include?(message.from.id)
puts "Command is from an admin. [" + "#{message.from.username}".green.bold + "]"
return true
else
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}".green.bold + "][" + "#{message.chat.title}".green + "] is authorized"
return true
else
puts "Group [" + "#{message.chat.id}".red.bold + "][" + "#{message.chat.title}".red + "] is NOT authorized!"
return false
end
end
def process_command_patchnotes(message, command, adm)
if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
reply = `cat patchnotes.txt`
else
reply = "I am not authorized to provide this information here."
end
return reply
end
def process_command_check(message, command, adm)
if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
#begin interactive code
options = [ ]
@probes.each do |k,v|
button_text = v
options.insert(-1, Telegram::Bot::Types::InlineKeyboardButton.new(text: button_text, callback_data: "#{k}"))
end
#end interactive code
#probe = @probes[0] #set manually for now
reply = "N/A"
#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
return reply
end
def process_command_test(message, command, adm)
if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
#reply = `scripts/tempf.py`
#some interactive code to select a probe
select_loc = "Server Room: Intake"
#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
return reply
end