Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- En este código esta implementada la nueva librería donde pide los valores de los items directamente usando nodejs.
- Como siempre y se que vos queres todo nuevo, no es para utilizarla en si pero es un código limpio, ordenado y por sobre todas las cosas es un código que funciona. O por lo menos eso aparenta.
- Lo bueno es que podemos sacar muy buenas idea de acá.
- var site = '';
- var apiKey = '';
- var shared_secret = '';
- var botID = '';
- var identity_secret = '';
- var accountName = '';
- var accountPassword = '';
- var sitePassword = 'Amina1808';
- var crypto = require('crypto');
- var market = require('steam-market-pricing');
- var hash = crypto.createHash('sha1');
- hash.update(Math.random().toString());
- hash = hash.digest('hex');
- var device_id = 'android:' + hash;
- var SteamUser = require('steam-user');
- var TradeOfferManager = require('steam-tradeoffer-manager');
- var SteamTradeOffers = require('steam-tradeoffers');
- var fs = require('fs');
- var request = require('request');
- var SteamTotp = require('steam-totp');
- var code = SteamTotp.generateAuthCode(shared_secret);
- var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
- var steamcommunityMobileConfirmations = null;
- var client = new SteamUser();
- var offers = new SteamTradeOffers();
- var manager = new TradeOfferManager({
- "steam": client,
- "domain": "example.com",
- "language": "ru"
- });
- manager.apiKey = apiKey;
- var logOnOptions = {
- "accountName": accountName,
- "password": accountPassword,
- "twoFactorCode": code
- };
- client.setSentry(fs.readFileSync('sentry'));
- client.logOn(logOnOptions);
- client.on('loggedOn', function() {
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- });
- client.on('webSession', function(sessionID, cookies) {
- steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
- {
- steamid: botID,
- identity_secret: identity_secret,
- device_id: device_id.toString(),
- webCookie: cookies
- });
- mobileConfirm();
- offers.setup({
- sessionID: sessionID,
- webCookie: cookies
- });
- manager.setCookies(cookies, function(err) {
- if(err) {
- console.log(err);
- process.exit(1);
- return;
- }
- console.log("Logged in");
- });
- });
- client.on("tradeOffers", function(count){
- if(count > 0){
- handleOffer();
- }
- });
- /*--------------------------
- * MY FUNCTIONS START
- --------------------------*/
- function getSHA1(bytes) {
- var shasum = crypto.createHash('sha1');
- shasum.end(bytes);
- return shasum.read();
- }
- function reAuth(){
- client.logOff();
- var code = SteamTotp.generateAuthCode(shared_secret);
- var logOnOptions = {
- "accountName": accountName,
- "password": accountPassword,
- "twoFactorCode": code
- };
- client.logOn(logOnOptions);
- client.webLogOn();
- }
- function mobileConfirm(){
- steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
- {
- if (err)
- {
- console.log(err);
- return;
- }
- if (!confirmations.length)
- {
- return;
- }
- confirmations.forEach(function(confirmation) {
- steamcommunityMobileConfirmations.AcceptConfirmation(confirmation, (function (err, result)
- {
- if (err)
- {
- console.log(err);
- return;
- }
- console.log('Mobile Confirmation: ' + result);
- }));
- });
- }));
- }
- /// --- Aca esta el codigo de la consulta a la base de datos de Steam, por los precios. --- ///
- function price(classid,steamid){
- steamid = steamid.toString();
- classid = classid.toString();
- var countIteration = 0;
- var nameUrl = "http://api.steampowered.com/ISteamEconomy/GetAssetClassInfo/v0001?key="+apiKey+"&format=json&language=ru&appid=730&class_count=2&classid0=0&classid1="+classid;
- request(nameUrl, function (error, response, body)
- {
- if(countIteration != 0){
- return;
- }
- countIteration++;
- var countIteration2 = 0;
- if (!error && response.statusCode == 200) {
- var json = JSON.parse(body);
- if(json['result'][classid]['tradable'] != "")
- {
- var market_hash_name = json['result'][classid]['market_hash_name'].toString();
- market.getItemPrice(730, market_hash_name, function(err, data)
- {
- if(!err)
- {
- if(countIteration2 != 0)
- {
- return;
- }
- countIteration2++;
- var cost = data;
- cost = cost['lowest_price'].replace(',','.');
- cost = cost.replace('$','');
- cost = parseFloat(cost);
- cost = (cost*100);
- var postData=
- {
- steamid: steamid,
- sum: cost,
- password: sitePassword
- };
- request.post(
- {
- headers: {'content-type' : 'application/x-www-form-urlencoded'},
- url: site+'balance',
- body: require('querystring').stringify(postData)
- }, function(error, response, body)
- {
- if (!error && response.statusCode == 200) {
- console.log("Sent money to "+ steamid);
- }
- });
- }
- });
- };
- }
- });
- }
- /// --- Aca termina. --- ///
- function handleOffer(){
- manager.getOffers(1, function(err, sent, received){
- if(err){
- reAuth();
- }
- received.forEach(function(offer) {
- var itemToRecieve = offer.itemsToReceive;
- if(itemToRecieve === undefined || itemToRecieve === null){
- offer.decline();
- return;
- }
- for(var i = 0; i < itemToRecieve.length; i++)
- {
- if(itemToRecieve[i].appid != "730")
- {
- offer.decline();
- return;
- }
- }
- if (offer.itemsToGive.length == 0) {
- offer.getEscrowDuration(function(err, daysTheirEscrow, daysMyEscrow){
- if(daysTheirEscrow == 0 || daysTheirEscrow == undefined){
- if(offer.state == 11){
- return;
- }
- console.log("New offer #" + offer.id + " from " + offer.partner);
- offer.accept(function(err) {
- if(err) {
- console.log("Unable to accept offer: " + err.message);
- reAuth();
- return;
- } else {
- console.log("Offer accepted");
- var items = offer.itemsToReceive;
- var steamid = offer.partner;
- for(var x = 0; x < items.length; x++) {
- price(items[x].classid, steamid);
- }
- request(site+'updateItems', function (error, response, body){
- if(!error && response.statusCode == 200) {
- }
- });
- }
- });
- }else{
- if(offer.state == 11){
- return;
- }else{
- console.log("New offer #" + offer.id + " from " + offer.partner);
- offer.decline();
- console.log("Escrow");
- }
- }
- });
- }else {
- offer.decline();
- console.log("I don't accept this shit!");
- }
- });
- });
- };
- function sendoffers(){
- request(site+"winner", function (error, response, body) {
- if(!error && response.statusCode == 200) {
- var str = body.toString();
- var winner = JSON.parse(str);
- if(winner === null || winner === undefined){
- return;
- }
- var gameid = winner['id'];
- var sendItem = winner['items'];
- var item=[], num = 0;
- var detected2 = false;
- manager.loadInventory(730, 2, false, function(err, items, currencies) {
- if(err){
- reAuth();
- }
- itemscopy = items;
- for (var x = 0; x < itemscopy.length; x++) {
- if (itemscopy[x].tradable && itemscopy[x].classid == sendItem) {
- itemscopy[x].market_name = "fgdfgdfgdfgdfgfswfewefewrfewrewrewr";
- item[0] = {
- appid: 730,
- contextid: 2,
- amount: 1,
- assetid: itemscopy[x].id
- }
- num++;
- }
- }
- if (num > 0) {
- var gamenum = winner['id'];
- offers.makeOffer({
- partnerSteamId: winner['usersteamid'].toString(),
- itemsFromMe: item,
- accessToken: winner['token'].toString(),
- itemsFromThem: []
- }, function(err, response){
- if (err){
- console.log(err);
- reAuth();
- return;
- }
- var postData={
- id: gamenum,
- password: sitePassword
- };
- request.post({
- headers: {'content-type' : 'application/x-www-form-urlencoded'},
- url: site+'delivery',
- body: require('querystring').stringify(postData)
- });
- console.log('Trade offer for queue '+gamenum+' sent!');
- mobileConfirm();
- });
- }
- });
- }
- });
- }
- setInterval(function(){sendoffers()}, 13000);
- /*--------------------------
- * MY FUNCTIONS END
- --------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement