Jump to content
McKay Development

Recommended Posts

Posted

Hi , 

Sometime Bot does not accept incoming offers. it gets stuck at offer.accept in newOffer. (Most of the time. it works, around 10% offers get stuck in my testing) 

So what's the best way to accept newOffer in bot? 

Also if bot get stuck and I restart, how to force bot to accept that old offer.

Bot Stuck Example: (nothing happens after Receiving new offer  from me)

 

 

04-02-2017 06:45:21 PM - info: Offer #1833690130 | Received new offer from 76561198046xxxxxx

My code:

 

'use strict'

// all packages
var SteamUser = require('steam-user')
var SteamTotp = require('steam-totp')
var SteamCommunity = require('steamcommunity')
var TradeOfferManager = require('steam-tradeoffer-manager')
var express = require('express')
var bodyParser = require('body-parser')
var fs = require('fs')
var log = require('./log')
var config = require('config.json')('./config.json')
var request = require('request')

// Now steam

var community = new SteamCommunity()
var SteamID = SteamCommunity.SteamID

var client = new SteamUser()

// varable
var admin1 = '76561198046099284'  // Me
// var admin2 = '76561198061798481'  // Bhanu
var port = 3000

// Steam LoginLogin Details

var logOnOptions = {
  'accountName': config.username, // Bot username
  'password': config.password, // Bot password
  'twoFactorCode': SteamTotp.generateAuthCode(config.shared_secret)
}

var manager = new TradeOfferManager({
  'steam': client, // Polling every 30 seconds is fine since we get notifications from Steam
  'domain': 'rs.dev', // Our domain is example.com
  'language': 'en' // We want English item descriptions
})

if (fs.existsSync('polldata.json')) {
  manager.pollData = JSON.parse(fs.readFileSync('polldata.json'))
}

client.logOn(logOnOptions)

client.on('loggedOn', function () {
  console.log('Logged into Steam')
})

client.on('webSession', function (sessionID, cookies) {
  manager.setCookies(cookies, function (err) {
    if (err) {
      log.debug(err)
      process.exit(1) // Fatal error since we couldn't get our API key
      return
    }
    console.log('[BOT] The Bot has logged in!')
    // client.chatMessage(admin1, '[BOT] Successfully logged in!')
    client.setPersona(5)
  })

  community.setCookies(cookies)
  community.startConfirmationChecker(30000, config.identity_secret)
})

client.on('friendMessage#' + admin1, function (steamID, message) {
  console.log('[SERVER] admin1 to Bot: ' + message)

  if (message.indexOf('/code') === 0) {
    client.chatMessage(admin1, 'Code :' + SteamTotp.generateAuthCode(config.shared_secret))
  }
})

manager.on('newOffer', function (offer) {
  var steamID64 = offer.partner.getSteamID64()

  log.info(`Offer #${offer.id} | Received new offer from ${steamID64}`)

  if (steamID64 === admin1) {
    offer.accept(function (err) {
      if (err) {
        log.debug(err)
      } else {
        community.checkConfirmations()
        log.info(`Offer #${offer.id} | Offer Accepted From Admin: ${steamID64}`)
      }
    })
  } else {
    offer.decline()
    log.info(`Offer #${offer.id} | Declined offer from ${steamID64}`)
  }
})

manager.on('receivedOfferChanged', function (offer, oldState) {
  console.log(`Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`)
})

manager.on('sentOfferChanged', function (offer, oldState) {
  var itemId = offer.itemsToGive[0].assetid

  log.info(`Offer #${offer.id} | changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`)

  if (offer.state === TradeOfferManager.ETradeOfferState.Accepted) {
    request({
      'url': `${config.site_url}/my-account/change-status?id=${itemId}&offerid=${offer.id}&status=${TradeOfferManager.ETradeOfferState[offer.state]}`
    }, function (error, response, body) {
      if (error) {
        log.debug(`Offer #${offer.id} | Error: ${error}`)
      } else {
        log.info(`Offer #${offer.id} | Response : ${body}`)
      }
    })
  }
})

community.on('confKeyNeeded', function (tag, callback) {
  var time = Math.floor(Date.now() / 1000)
  callback(null, time, SteamTotp.getConfirmationKey(config.identity_secret, time, tag))
})

manager.on('pollData', function (pollData) {
  fs.writeFileSync('polldata.json', JSON.stringify(pollData))
})

community.on('debug', console.log)

// make web server here

var app = express()
app.use(bodyParser.json())

app.get('/', function (req, res) {
  res.send('FucK bhanu')
})

// escrowhold function

app.get('/ping', function (req, res) {
  res.status(200).send('pong')
})

app.post('/escrowhold', function (req, res) {
  var tradelink = req.body.tradelink
  var offer = manager.createOffer(tradelink)
  offer.getUserDetails(function (err, me, them) {
    if (!err) {
      res.status(200).json({
        'escrowDays': them.escrowDays
      })
      return
    } else {
      log.debug(err)
      res.status(400).json({ 'error': err })
      return
    }
  })
})

// send offer

app.post('/send-offer', function (req, res) {
  var tradeToken = req.body.trade
  var sid = new SteamID(req.body.steamid)
  var itemID = req.body.item_id
  var Message = 'Bhanu is fag'

  var offer = manager.createOffer(sid, tradeToken)

  var item = {'assetid': itemID, 'appid': 730, 'contextid': 2}

  offer.addMyItem(item)
  offer.setMessage(Message)
  offer.send(function (err, status) {
    if (err) {
      res.status(400).json({ 'error': err })
      return
    }

    if (status === 'pending') {
      // We need to confirm it
      log.info(`Offer #${offer.id} | sent, but requires confirmation`)
      community.acceptConfirmationForObject(config.identity_secret, offer.id, function (err) {
        if (err) {
          res.status(400).json({ 'error': err })
        } else {
          log.info(`Offer #${offer.id} | confirmed`)
          res.status(200).json({ 'offerid': offer.id })
        }
      })
    } else {
      log.info(`Offer #${offer.id} | sent successfully`)
      res.status(400).json({ 'offerid': offer.id })
    }
  })
})

app.listen(port)
console.log('Listening at http://localhost:' + port)

Posted

Nothing . I just stuck at accepting it. Nothing happens. No error nothing

 

I waited around 15 min. After restarting bot, it ignores that offer due to polling. So I deleted poll data.JSON file and bot try to accept it again.

There is any other way to re-poll that offer again without deleting JSON file. 

PS: Yesterday player inventories delayed according to steam stats.us. Maybe that was reason for this behavior 

Posted

It doesn't look like you're renewing your web session. You need to call client.webLogOn() when it expires (listen for sessionExpired on your SteamCommunity). It also doesn't hurt to call it periodically, say every hour.

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...