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_start(message, command, adm) reply = "I am #{@botname}, and I am here to provide temperature information from various sensors. Currently I can retrieve information " + "from temperature sensors. In a future version, I will also report when temperatures are out of a specified range through regular checks.\n\n" + "Commands available:\n/start or /help (Shows this message)\n/check or /c (Show a specific temperature interactively)\n/report or /r (Show all temperatures)\n" + "/simple or /s (Show a simplified report)\n\nExtra functions:\n/whoami or /chatinfo (Provides IDs for internal use)\n/whereareyou or /location (Provides hostname for bot server)\n\n" + "Check again later to see if any new functions have been added, or use /patchnotes to learn about recent updates.\n" + "You can also view the source code at the following location:\nhttps://git.skyfall.tech/skyfall/heatbot" if message_from_admin?(message, adm) msg_from_admin = true end STDOUT.flush if is_chat_authorized?(message, @auth_chat) chat_authorized = true end STDOUT.flush if ! msg_from_admin && ! chat_authorized if message.from.id == message.chat.id 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 elsif msg_from_admin && ! chat_authorized reply = reply + "\n\nWARNING: Although you are an administrator, I have not been authorized to participate in this group. My functionality is limited." end send_message(message.chat.id, reply) end def process_command_patchnotes(message, command, adm) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) reply = File.read("static_text/patchnotes.txt") else reply = "I am not authorized to provide this information here." end send_message(message.chat.id, reply) end def process_command_location(message, command, adm) if message_from_admin?(message, adm) || is_chat_authorized?(message, @auth_chat) reply = "I am currently located at:\n\nHost: #{`head -n1 /etc/hostname`}ExtIP: #{`curl #{@ip_provider} 2>/dev/null`}" else reply = "I am not authorized to provide this information here." end #send_message_markdown(message.chat.id, reply) send_message(message.chat.id, reply) end def process_command_chatinfo(message) reply = "User ID: #{message.from.id}\nChat ID: #{message.chat.id}" send_message(message.chat.id, reply) end def process_command_check(message, command, adm, simple=false) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) #begin interactive code options = [ ] @probes.each do |k,v| puts " Option: #{k} is #{v["loc"].to_s}" button_text = v["loc"].to_s options.insert(-1, Telegram::Bot::Types::InlineKeyboardButton.new(text: button_text, callback_data: "ZONE|#{k}")) STDOUT.flush end message_text = "Which area would you like to check?\n" send_question(message.chat.id, message_text, options) #end interactive code else send_message(message.chat.id,"I am not authorized to provide this information here.") end end def process_command_report(message, command, adm, simple=false) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) if !simple confirmation = send_message(message.chat.id,"Generating full report... Please wait.") report = "Full Report:\n\n" else confirmation = send_message(message.chat.id,"Generating simple report... Please wait.") report = "Simple Report:\n\n" end @probes.each do |k,v| zone = v["loc"].to_s port = v["port"].to_s host = k tdata = process_tdata(host, port, simple) report = report + "#{zone}: #{tdata}\n" STDOUT.flush end send_message(message.chat.id,report) #delete_message(confirmation) #delete_confirmation(confirmation) else send_message(message.chat.id,"I am not authorized to provide this information here.") end end