const fs = require('fs');
(async ()=>{try{
	var list_files=fs.readdirSync('./');
	var file_steamguard='D:\\1\\utils\\sda\\maFiles\\76561198339583882.maFile';
	if(!file_steamguard){
		console.error('Нету файла с steamguad\nОканчиваю работу');
		return process.exit();
	}
	var data_steamguard;
	try{
		data_steamguard=JSON.parse(fs.readFileSync(file_steamguard));
	}catch (e){
		console.error('Нету файла или ошибка чтения steamguad\nОканчиваю работу\n'+e);
		return process.exit();
	};
	if(process.argv[2]=='guard'||process.argv[3]=='guard'){
		var SteamUser=null;
		try{
			SteamUser=require('steam-user');
		}catch (e){
			console.error('Нету модуля steam-user\n'+
				'Перед запуском этого скрипта выполните и дождитесь окончания:\n'+
				'npm i steam-user\n'+
				'Оканчиваю работу');
			return process.exit();
		};
		console.log('Ваш 2FA(SteamGuard) код атворизации: '+SteamUser.generateAuthCode(data_steamguard.shared_secret));
		return process.exit();
	}
	var SteamCommunity=null;
	try{
		SteamCommunity=require('steamcommunity');
	}catch (e){
		console.error('Нету модуля steamcommunity\n'+
			'Перед запуском этого скрипта выполните и дождитесь окончания:\n'+
			'npm i steamcommunity\n'+
			'После этого откройте файл по пути\n'+
			'node_modules/@doctormckay/stats-reporter/index.js\n'+
			'И замените все что там есть на\n'+
			'exports.setup=()=>1;\n'+
			'Оканчиваю работу');
		return process.exit();
	};
	var steamcommunity=new SteamCommunity();
	var info=await new Promise(async call=>steamcommunity.login({
		"accountName": data_steamguard.account_name,
		"password": 'Тут пароль',
		"steamguard": "your Steam Guard value", // only required if logging in with a Steam Guard authorization
		//"authCode": "your Steam Guard email code", // only required if logging in with a new email auth code
		"twoFactorCode": require('steam-totp').generateAuthCode(data_steamguard.shared_secret), // only required if logging in with a Steam Guard app code
		//"captcha": "value of prompted captcha" // only required if you have been prompted with a CAPTCHA
	},(err,sessionID,cookies,steamguard,oAuthToken)=>{
		call({err,sessionID,cookies,steamguard,oAuthToken})
	}));
	if(info.err){
		console.error('Ошибка входа\n'+info.err+'\nОканчиваю работу');
		console.error(info);
		return process.exit();
	};
	console.log('Готово, теперь все с телефона будет подтверждатся само');
	steamcommunity.startConfirmationChecker(10000, data_steamguard.identity_secret);
}catch (e){console.error(e);}})()