system("rm #{@tmpdir}/test.file >/dev/null 2>&1")#Attempt to clean up anyway
returnfalse
end
end
if@tmpdir.nil?
errcount+=1
print"FAIL!\n\n".red.bold
puts"Error(#{errcount.to_s}): No temporary directory defined. Using '/tmp/.skyfall/egs-bot'.\n"
@tmpdir="/tmp/.skyfall/egs-bot"
ifis_tmp_writable?
puts"Default temporary directory is writable. Continuing...\n\n"
else
errcount+=1
puts"Error(#{errcount.to_s}): Temporary directory ["+@tmpdir.red.bold+"] is not writable!\n"+"THIS IS REQUIRED!".red.bold+" Bot initialization failed; exiting..."
exit(1)
end
else
ifis_tmp_writable?
print"OK\n".green.bold
else
errcount+=1
print"FAIL!\n\n".red.bold
puts"Error(#{errcount.to_s}): Temporary directory ["+@tmpdir.red.bold+"] is not writable!\n"+"THIS IS REQUIRED!".red.bold+" Bot initialization failed; exiting..."
exit(1)
end
end
### End tmpdir check
print"Checking telnet configuration ........... "
iftelnet.nil?
iftelnet.nil?
errcount+=1
errcount+=1
print"FAIL!\n\n".red.bold
puts"Error(#{errcount.to_s}): No telnet information provided in bot_config.yaml.\nThis is required for nearly all Empyrion-related "+
puts"Error(#{errcount.to_s}): No telnet information provided in bot_config.yaml.\nThis is required for nearly all Empyrion-related "+
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will return broken messages)\n\n"
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will return broken messages)\n\n"
else
print"OK\n".green.bold
end
end
print"Checking administrators ................. "
ifadmin.nil?
ifadmin.nil?
errcount+=1
errcount+=1
print"FAIL!\n\n".red.bold
puts"Error(#{errcount.to_s}): No admin Telegram IDs provided in bot_config.yaml.\nThis is required for many functions.\n"+
puts"Error(#{errcount.to_s}): No admin Telegram IDs provided in bot_config.yaml.\nThis is required for many functions.\n"+
"THIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
"THIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
admin=["0"]
admin=["0"]
else
print"OK\n".green.bold
end
end
print"Checking authorized chats ............... "
if@auth_chat.nil?
if@auth_chat.nil?
errcount+=1
errcount+=1
print"FAIL!\n\n".red.bold
puts"Error(#{errcount.to_s}): No authorized Telegram group IDs provided in bot_config.yaml.\nThis is required for most Empyrion-related "+
puts"Error(#{errcount.to_s}): No authorized Telegram group IDs provided in bot_config.yaml.\nThis is required for most Empyrion-related "+
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
"functions.\nTHIS SHOULD BE ADDRESSED. Continuing. (some commands will not be available)\n\n"
@auth_chat=["0"]
@auth_chat=["0"]
else
print"OK\n".green.bold
end
end
puts"Errors found: #{errcount.to_s}\n\n"
puts"Errors found: #{errcount.to_s}\n\n"
iferrcount>0
print"Environment is grinning and holding a spatula. Please review your configuration.\n\n".red.bold
else
print"Environment appears sane.\n\n".green.bold
end
STDOUT.sync=false
### End sanity check ###
puts"Starting [#{@botname}]...\n\n"
puts"Starting [#{@botname}]...\n\n"
puts"Empyrion Host: #{telnet['host']}"
puts"Empyrion Host: #{telnet['host']}"
puts"Empyrion Telnet Port: #{telnet['port']}"
puts"Empyrion Telnet Port: #{telnet['port']}"
puts"Authorized administrator IDs: #{admin}"
puts"Authorized administrator IDs: #{admin}"
puts"Authorized chat IDs: #{@auth_chat}"
puts"Authorized chat IDs: #{@auth_chat}"
puts"Bot token: #{token}\n\n\n\n"
puts"Bot token: #{token}"
puts"Temporary direcotry: #{@tmpdir}"
puts"Start time: "+timestamp+"\n\n\n\n"
STDOUT.flush
#def process_command_srvstart(message)
#def process_command_srvstart(message)
# puts "Received command: srvstart"
# puts "Received command: srvstart"
@ -96,20 +169,27 @@ def handle_message(message)
#conf = YAML.load_file("bot_config.yaml")
#conf = YAML.load_file("bot_config.yaml")
telnet=@conf['telnet']
telnet=@conf['telnet']
adm=@conf['admin']
adm=@conf['admin']
puts"Received command from #{message.from.username}: #{command}"
putsTime.now.strftime("%F %H:%M:%S").yellow+": Received command from "+"#{message.from.username}".cyan.bold+" ["+"#{message.from.id}".cyan+"]: "+"#{command}".magenta.bold
casecommand
casecommand
when'/start'
when'/start'
reply="Introduction: I am #{@botname}, and I am here to make life easier for meatbag admins like you. Currently I can retrieve information "+
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"+
"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 (Shows this message)\n/srvstart (Currently non-functional)\n/srvstop\n/status\n/whoami or /chatinfo\n/whereareyou or /location\n\n"+
"Commands available:\n/start (Shows this message)\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."
"Check again later to see if any new functions have been added, or use /patchnotes to learn about recent updates.\n"+