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 "Unauthorized user sent message. User ID: #{message.from.id} Source ID: #{message.chat.id}." if ! auth_chat.include?(message.chat.id.to_s) #puts message.chat.type return true end def message_from_admin?(message, adm) #return @admin_userids.include? message.from.id.to_s #puts adm.class #puts message.from.id #puts 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_srvstart(message, command, adm) #puts "Received command: " + "srvstart".green #pp message from_admin = message_from_admin?(message, adm) auth_grp = is_chat_authorized?(message, @auth_chat) if ! auth_grp && ! from_admin return "Refusal: I am not authorized to perform this function for this group, meatbag." elsif ! from_admin return "Refusal: The meatbag #{message.from.username} is not my master." elsif ! auth_grp return "Refusal: Although I respect your wishes, master, I am not authorized to perform this function for this group." else telnet = @conf['telnet'] puts `./scripts/srvstart #{telnet['host']}` #return "Starting up the Empyrion service." return "This function is currently broken. An attempt was made, but odds are against the server having actually started.\n\n" + "Use /status for more info." end end def process_command_srvstop(message, command, adm) #puts "Received command: " + "srvstop".red from_admin = message_from_admin?(message, adm) auth_grp = is_chat_authorized?(message, @auth_chat) if ! auth_grp && ! from_admin return "Refusal: I am not authorized to perform this function for this group, meatbag." elsif ! from_admin return "Refusal: The meatbag #{message.from.username} is not my master." elsif ! auth_grp return "Refusal: Although I respect your wishes, master, I am not authorized to perform this function for this group." else telnet = @conf['telnet'] `./scripts/srvstop #{telnet['host']} #{telnet['port']} #{telnet['pass']}` return "Affirmation: I am shutting down the Empyrion service." end end def process_command_srvstatus(message, command, adm) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) telnet = @conf['telnet'] print 'Checking connectivity to Empyrion service... ' STDOUT.flush if system("nc -zvw3 #{telnet['host']} #{telnet['port']} >/dev/null 2>&1") print "Server responded!\nSending message receipt... " STDOUT.flush if `./scripts/srvstatus.receipt #{@conf['token']} #{message.chat.id}` print "Receipt sent!\nFetching details...\n" else print "Receipt FAILED to send (non-zero exit code on scripts/srvstatus.receipt) !!!\nContinuing to fetch details anyway...\n".red.bold end reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']} #{@tmpdir}` else print "Server did not respond!\nSending failure message...\n".red.bold reply = "Server is not responding!" end STDOUT.flush else reply = "Refusal: I am not authorized to provide this information here." end return reply end def process_command_patchnotes(message, command, adm) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) telnet = @conf['telnet'] reply = `cat patchnotes.txt` else reply = "Refusal: I am not authorized to provide this information here." end return reply end