Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SteamCommunity = require('steamcommunity');
- var ReadLine = require('readline');
- var fs = require('fs');
- var SteamTotp = require('steam-totp');
- var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
- var botData;
- if(process.argv[2] !== "undefined") {
- var botName = process.argv[2];
- } else {
- console.log("failed to load bot name from arguments. Please try again");
- process.exit();
- }
- var community = new SteamCommunity();
- var rl = ReadLine.createInterface({
- "input": process.stdin,
- "output": process.stdout
- });
- fs.readFile("settings."+botName+".json", (err, data) => {
- if (err)
- {
- console.log("Failed to load settings from file, exiting");
- process.exit();
- }
- else
- {
- try
- {
- botData = JSON.parse(data);
- }
- catch(e)
- {
- console.log("Failed to parse settings to json, exiting. Exception: "+ e);
- process.exit();
- }
- if(typeof botData.username === "undefined" || typeof botData.password === "undefined" || typeof botData.deviceId === "undefined" || typeof botData.identitySecret === "undefined" || typeof botData.sharedSecret === "undefined")
- {
- console.log("Missing variables in json object, check the config for missing settings.");
- process.exit();
- }
- if(typeof botData.cookies === "object")
- {
- doCookieLogin(botData.cookies);
- }
- else
- {
- doLogin(botData.username, botData.password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
- }
- }
- });
- function doLogin(accountName, password, authCode, twoFactorCode, captcha)
- {
- community.login({
- "accountName": accountName,
- "password": password,
- "authCode": authCode,
- "twoFactorCode": twoFactorCode,
- "captcha": captcha
- }, function(err, sessionID, cookies, steamguard)
- {
- if(err)
- {
- if(err.message == 'SteamGuardMobile')
- {
- doLogin(accountName, password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
- return;
- }
- if(err.message == 'SteamGuard')
- {
- console.log("An email has been sent to your address at " + err.emaildomain);
- rl.question("Steam Guard Code: ", function(code)
- {
- doLogin(accountName, password, code);
- });
- return;
- }
- if(err.message == 'CAPTCHA')
- {
- console.log(err.captchaurl);
- rl.question("CAPTCHA: ", function(captchaInput)
- {
- doLogin(accountName, password, authCode, twoFactorCode, captchaInput);
- });
- return;
- }
- console.log(err);
- process.exit();
- return;
- }
- console.log("Logged on!");
- botData.cookies = cookies;
- fs.writeFile("settings."+botName+".json", JSON.stringify(botData), function(err)
- {
- if(err)
- {
- console.log("Failed to save new cookies to the settings file");
- }
- console.log("Saved cookies to the settings file for " + botName);
- });
- startConfirmationPolling(community, cookies);
- });
- }
- function doCookieLogin(cookies) {
- community.setCookies(cookies);
- community.loggedIn(function(err, loggedIn, familyView) {
- if(err) {
- console.log("A error occured while checking login status: Error: " + err);
- }
- if(loggedIn)
- {
- console.log("Logged in with cookies!");
- startConfirmationPolling(community, cookies);
- }
- else
- {
- doLogin(botData.username, botData.password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
- }
- });
- }
- function startConfirmationPolling(community, cookies)
- {
- var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
- {
- steamid: community.steamID,
- identity_secret: botData.identitySecret,
- device_id: botData.deviceId,
- webCookie: cookies,
- });
- var mobileConfirmationsInterval = setInterval(function()
- {
- steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
- {
- if (err)
- {
- console.log("FetchConfirmationsError " +err);
- return;
- }
- console.log('received ' + confirmations.length + ' confirmations');
- if ( ! confirmations.length)
- {
- return;
- }
- for(var x = 0; x < confirmations.length; x++)
- {
- console.log(confirmations[x].id);
- steamcommunityMobileConfirmations.generateConfirmationTradeId(confirmations[x], (function (err, tradeId, confirmationId)
- {
- if (err)
- {
- console.log(err);
- return;
- }
- //
- //DO mysql check for trade id.
- //
- var inDB = true;;
- if(inDB) {
- steamcommunityMobileConfirmations.AcceptConfirmation(confirmationId, (function (err, result)
- {
- if (err)
- {
- console.log("AcceptConfirmationError " + err);
- return;
- }
- console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result);
- }).bind(this));
- }
- }).bind(this));
- }
- }).bind(steamcommunityMobileConfirmations));
- },
- 10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement