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.
empyrion-bot/commands.rb

96 lines
3.8 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 "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']
if `nc -zvw3 #{telnet['host']} #{telnet['port']}`
puts 'Server responded. Fetching details...'
`./scripts/srvstatus.receipt #{@conf['token']} #{message.chat.id}`
STDOUT.flush
end
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
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