Jump to content
McKay Development

Can I instantiate community login just once at startup and use the logged in community object elsewhere?


b_zy

Recommended Posts

I have a web app that processes steam trades. The goal is to log into steamcommunity with user/pass/2fa once on startup, then use the logged in community object to create offers when trades are processed. I have the current code which seems to successfully process trades (I can't know for sure as the bot account had 2FA enabled just a few days ago), the problem is that every time a trade is processed, a community login is required. If I remember correctly, you can only log in with 2FA once every 30 seconds. For my use case, this is a limitation I am hoping to avoid.

 

import two from './twofactor_76561199485326357.json';
import {TItemsAsset} from "@/helpers/steamTypes";
var SteamTotp = require('steam-totp');
var TradeOfferManager = require('steam-tradeoffer-manager');
var SteamCommunity = require('steamcommunity');
var community = new SteamCommunity();
require('dotenv').config();

export default function createOffer(tradeURL: string, items: TItemsAsset[]) {
    var logOnOptions = {
        accountName: process.env.BOT_USER,
        password: process.env.BOT_PASS,
        twoFactorCode: SteamTotp.generateAuthCode(two.shared_secret),
    }

    community.login(logOnOptions, (err: Error) => {
        if (err) {
            console.log('Error logging into community');
            throw Error;
        } else {
            console.log('Successfully logged into community as ' + logOnOptions.accountName);

            var manager = new TradeOfferManager({
                "community": community,
                "pollInterval": 5000,
                "cancelTime": 180000,
                "pendingCancelTime": 180000,
                "domain": (process.env.NODE_ENV !== 'production' ? 'localhost:3000' : 'mywebsite.com'),
                "language": "en",
            })


            let offer = manager.createOffer(tradeURL);
            //offer.addTheirItems(items.map(item => ({ appid: item.assetid, contextid: item.contextid, assetid: item.assetid })));
            offer.addTheirItem({ appid: 730, contextid: 2, assetid: 19506293513 })
            offer.setMessage('Items from bounty creator');
            offer.send(function(err: Error, status: string) {
                if (err) {
                    console.log('send err: ' + err);
                    throw Error;
                } else if (status === 'pending') {
                    community.acceptConfirmationForObject(two.identity_secret, offer.id, (err: Error) => {
                        if (err) {
                            console.log('confirm err: ' + err);
                        } else {
                            console.log('Offer confirmed');
                        }
                    });
                } else {
                    console.log('trade offer sent successfully');
                }
            });
        }
    });
}



I respect your time and am not asking you to teach me basic javascript principles, but if you could point me in the right direction that would be very much appreciated.

 

Thanks for creating these libraries,

- b_zy

Edited by b_zy
removed anyscript
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...