I suppose if I can send a tradeoffer (with status pending) then I'm logged in. Also I have some log statements for login errors and I have nothing related to login errors in my console. Here is a complete .js file I'm using for managing bot, if it will help.
import SteamUser from 'steam-user'
import SteamTotp from 'steam-totp'
import TradeOfferManager from 'steam-tradeoffer-manager'
import SteamCommunity from 'steamcommunity'
import { log, sleep } from './utils'
function getRandomInt(min, max) {
return Math.floor(Math.random() * ((max - min) + 1)) + min
}
class SteamBot {
loginBot() {
log(`[bot] Logging in, login [${this.login}] \
password [${this.password}] shared [${this.shared}] \
identity [${this.identity}]`)
this.status = { name: this.login, loggedIn: false, gotApiKey: false, error: null }
this.client = new SteamUser()
this.client.setOption('promptSteamGuardCode', false)
this.community = new SteamCommunity()
const authCode = SteamTotp.getAuthCode(this.shared)
const logOnOptions = {
accountName: this.login,
password: this.password,
twoFactorCode: authCode,
}
this.client.on('loggedOn', () => {
this.status.loggedIn = true
log(`[bot] Logged into Steam as ${this.client.steamID.getSteam3RenderedID()}`)
this.client.setPersona(SteamUser.EPersonaState.Online)
})
this.client.on('steamGuard', (domain, callback) => {
log('[bot] Requiring Steam Guard, waiting 30 sec...', true, true)
setTimeout(() => {
const code = SteamTotp.getAuthCode(this.shared)
callback(code)
}, 30000) // 30 sec sleeping
})
this.client.on('error', error => this.onBotLoginError(error))
this.manager = new TradeOfferManager({
steam: this.client,
community: this.community,
domain: "localhost",
language: 'en',
pollInterval: 5000
})
this.client.on('webSession', (sessionID, cookies) =>
this.onBotWebSession(sessionID, cookies))
this.client.logOn(logOnOptions)
}
onBotWebSession(sessionID, cookies) {
this.manager.setCookies(cookies, err =>
this.onManagerSetCookies(err))
this.community.setCookies(cookies)
this.community.startConfirmationChecker(10000, this.identity);
}
onManagerSendOfferChanged(offer, old) {
log(`[bot] Offer #${offer.id} status: ${TradeOfferManager.ETradeOfferState[offer.state]}`, true, true)
}
makeOffer(id, itemsToGive, itemsToReceive, token) {
return new Promise((res, rej) => {
const offer = this.manager.createOffer(id)
offer.itemsToGive = itemsToGive.map(i => ({
appid: 730,
contextid: 2,
amount: 1,
assetid: i
}))
offer.itemsToReceive = itemsToReceive.map(i => ({
appid: 730,
contextid: 2,
amount: 1,
assetid: i
}))
offer.setToken(token)
offer.send((err, status) => {
if (err)
return rej(err)
this.community.checkConfirmations()
res(`Sent offer ${offer.id}, status: ${status}`)
})
})
}
onManagerSetCookies(err) {
if (err) {
this.status.error = err.message
log(`[bot] Error getting API key: ${err.message}`)
if (err.message === 'HTTP error 429') { // too many requests
const interval = getRandomInt(60, 300)
log(`[bot] Too many requests, relogin in ${interval} seconds`, true, true)
this.client.logOff()
setTimeout(() => {
this.loginBot()
}, interval * 1000) // 60-300 sec sleeping
} else
log(`[bot] Unrecoverable error, not retrying. Error: ${err.message}`, true)
return
}
this.status.gotApiKey = true
log(`[bot] Got API key: ${this.manager.apiKey}`)
this.manager.on('newOffer', (offer, old) =>
this.onManagerNewOffer(offer, old))
this.manager.on('sentOfferChanged', (offer, old) =>
this.onManagerSendOfferChanged(offer, old))
this.community.on('newConfirmation', (confirmation) =>
this.onCommunityNewConfirmation(confirmation));
this.community.on('confirmationAccepted', (confirmation) =>
this.onCommunityConfirmationAccepted(confirmation));
this.community.on('confKeyNeeded', (tag, callback) => {
const time = Math.floor(Date.now() / 1000)
log(`Conf Key Needed ${JSON.stringify(tag)}`, true, true)
callback(null, time, SteamTotp.generateAuthCode(this.identity, time, tag))
})
}
onCommunityNewConfirmation(confirmation) {
log(`Confirmation needed: ${JSON.stringify(confirmation)}`, true, true)
}
onCommunityConfirmationAccepted(confirmation) {
log(`Confirmation accepted: ${JSON.stringify(confirmation)}`, true, true)
}
confirmAll() {
return new Promise((res, rej) => {
const time = Math.floor(Date.now() / 1000)
const confKey = SteamTotp.getConfirmationKey(this.identity + 'aaa', time, 'conf')
const allowKey = SteamTotp.getConfirmationKey(this.identity + 'aaa', time, 'allow')
this.community.acceptAllConfirmations(time, confKey, allowKey, (err, confirmations) => {
if (err)
return rej(err)
return res(confirmations)
})
})
}
onManagerNewOffer(offer) {
const steamId = offer.partner.getSteamID64()
log(`[bot] New offer #${offer.id}: ${TradeOfferManager.ETradeOfferState[offer.state]} from ${steamId}`, true, true)
offer.accept(err => {
if (err) {
log(`[bot] Offer ${offer.id} error: ${err}`, true, true)
} else {
log(`[bot] Offer from ${steamId} accepted: ${offer.id}`, true, true);
}
})
}
onBotLoginError(error) {
this.status.loggedIn = false
this.status.error = error.message
const interval = getRandomInt(5, 15)
log(`[bot] Error logging in: ${error.message}, sleeping for ${interval} min...`, true, true)
setTimeout(() => {
this.loginBot()
}, interval * 1000 * 60) // 5-15 min sleeping
}
constructor(login, password, shared, identity) {
this.login = login
this.password = password
this.shared = shared
this.identity = identity
this.loginBot()
}
}
export default SteamBot