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}]" return true else puts "Command is NOT from an admin! [#{message.from.username}]" return false end end def is_chat_authorized?(message, auth_chat) if auth_chat.include?(message.chat.id) puts "Group [#{message.chat.id}][#{message.chat.title}] is authorized" return true else puts "Group [#{message.chat.id}][#{message.chat.title}] is NOT authorized!" return false end end def process_command_srvstart(message, command, adm) puts "Received command: srvstart" #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" 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'] reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}` else reply = "Refusal: I am not authorized to provide this information here." end return reply end