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 send_gif(chat, cmd) # bot.api.sendVideo(chat_id: chat, video: "#{@gif_url_prefix}#{cmd}.gif") #end def process_command_start(message, command, adm) reply = "Introduction: I am #{@botname}, and I am here to make life easier for meatbag admins like you. Currently I can retrieve information " + "from an Empyrion server as well as kill the server process. I also have some pretty sweet dance moves.\n\n" + "Commands available:\n/start or /help (Shows this message)\n/voice or /chat (Shows voice chat info)\n/srvstart (Currently non-functional)\n/srvstop\n/status\n/whoami or /chatinfo\n/whereareyou or /location\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/empyrion-bot" if message_from_admin?(message, adm) msg_from_admin = true end if is_chat_authorized?(message, @auth_chat) chat_authorized = true end 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 my master, 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_voicechat(message, command, adm, vchat_info = @vchat_info) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) print "Checking connectivity to #{vchat_info['type']} service... " STDOUT.flush if vchat_info['type'].downcase != 'discord' if system("nc -zvw3 #{vchat_info['address']} #{vchat_info['port']} >/dev/null 2>&1") print "OK\n".green.bold STDOUT.flush reply = "#{vchat_info['type']} service is online.\n\n" else print "FAIL\n".red.bold STDOUT.flush reply = "#{vchat_info['type']} service is not responding!\n\n" end else reply = "" end reply = reply + "Voice Chat Connection Information\n" + "-------------------------------------------------\n" + "Application: #{vchat_info['type']}\n" + "Address: #{vchat_info['address']}\n" + "Port: #{vchat_info['port']}\n" + "Password: #{vchat_info['password']}\n" if system("test -f static_text/custom/voicechat.txt") reply = reply + File.read("static_text/custom/voicechat.txt") #Add custom info end STDOUT.flush else reply = "Refusal: I am not authorized to provide this information here." end send_message(message.chat.id, reply) 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 "OK\n".green.bold + "Sending message receipt... " STDOUT.flush if `./scripts/srvstatus.receipt #{@conf['token']} #{message.chat.id}` print "OK\n".green.bold + "Fetching 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 = "Exclamation: 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 = File.read("static_text/patchnotes.txt") else reply = "Refusal: I am not authorized to provide this information here." end return reply end