Hello. I am quite new to Node.JS so I need a little help sorting some things out.
I am trying to make the bot controlled by POST request by using Express for the URL routing, so the bot only responds to specific requests made from specific domain to specific endpoints. I am able to login to SteamUser, but I am not able to share the cookies to SteamCommunity.
I wasn't able to find a way to keep the bot logged in across different endpoints, I am assuming that it comes from the fact that every request is unique and they are not sharing data between them, so, I have to make the bot log in on each request, and that's fine with me. The problem comes when I try to share the cookies from webSession event, and send a trade on the loggedOn event. It appears that when logged on event fires, cookies are not yet configured. What approach should I use to perform the login on the SteamCommunity module?
Here is my current code, that rejects my trade offer, because cookies are not yet configured.
app.get('/lero', async (req, res) => {
res.send('Loaded');
const SteamUser = require('steam-user');
const SteamCommunity = require('steamcommunity');
const SteamTotp = require('steam-totp');
const TradeOfferManager = require('steam-tradeoffer-manager');
const FS = require('fs');
let client = new SteamUser();
let manager = new TradeOfferManager({
"steam": client,
"domain": "bot.test",
"language": "es"
});
let community = new SteamCommunity();
// Steam logon options
let logOnOptions = {
"accountName": "censored",
"password": "censored",
"twoFactorCode": SteamTotp.getAuthCode("censored"),
};
if (FS.existsSync('polldata.json')) {
manager.pollData = JSON.parse(FS.readFileSync('polldata.json').toString('utf8'));
}
client.logOn(logOnOptions);
const { Sequelize, Op, Model, DataType, DataTypes } = require('sequelize');
const sequelize = new Sequelize('cendsored', 'censored', 'censored', {
host: 'localhost',
dialect: 'mysql',
define: {
underscored: true,
createdAt: 'created_at',
updatedAt: 'updated_at' ,
deletedAt: 'deleted_at',
}
});
const initModels = require('./models/init-models');
const models = initModels(sequelize);
client.on('webSession', (sessionID, cookies) => {
community.setCookies(cookies);
manager.setCookies(cookies);
console.log(cookies); // console logs this after the error, meaning trade is sent before this
});
client.on('loggedOn', async () => {
console.log("Logged into Steam");
const su = await models.steam_users.findOne({
where: {
steam_personaname: 'censored',
},
include: [{
model: models.users,
as: 'user',
}],
}).then((r) => {
client.chat.sendFriendMessage(r.steam_steamidmodern, "Sending trade in a moment");
let offer = manager.createOffer('censored');
console.log(offer);
console.log(community);
let item = {
assetid: 'censored',
appid: '730',
contextid: '2',
amount: 1,
};
if (offer.addTheirItem(item)) {
offer.send((err, status) => {
if (err) {
console.log(err);
} else {
console.log(status);
}
});
}
});
});
});
I am familiar with events, since in PHP I have worked with OpenCart, Wordpress and Laravel, but I cannot find the right order of events here, to correctly log in both modules.
Any help will be very much appreciated.