artyak Posted April 6, 2020 Report Posted April 6, 2020 (edited) Very often I get an Error: Not Logged , I can get this error after one day the bot starts, sometimes I get it after 5 minutes the bot starts, as I understand the problem is that the bot cannot receive new cookies, but in the bot getting worth it. Can someone tell me where the error is? My code is: 'use strict'; const fs = require('fs'); const app = require('express')(), https = require('https'), server = https.createServer(sslOptions, app), io = require('socket.io')(server), redis = require('redis'), mysql = require('mysql'), config = require('./config.js'), SteamUser = require('steam-user'), SteamTotp = require('steam-totp'), SteamCommunity = require('steamcommunity'), TradeOfferManager = require('steam-tradeoffer-manager'), log4js = require('log4js'), requestify = require('requestify'), client = redis.createClient(), redisClient = redis.createClient(); const connection = mysql.createConnection({ host: 'localhost', user: config.db.user, password: config.db.password, database: config.db.database }); let bots = []; connection.connect(); server.listen(8081); log4js.configure({ appenders: { multi: {type: 'multiFile', base: 'logs/', property: 'categoryName', extension: '.log'}, console: {type: 'console'} }, categories: { default: {appenders: ['multi', 'console'], level: 'debug'} } }); /** * Redis function */ redisClient.subscribe('deposit'); redisClient.subscribe('withdraw'); redisClient.subscribe('sendItem'); redisClient.on('message', (channel, message) => { if (channel == `deposit`) { const data = JSON.parse(message); bots[data.bot].deposit(data); } if (channel == `withdraw`) { const data = JSON.parse(message); bots[data.bot].withdraw(data); } if (channel == `sendItem`) { const data = JSON.parse(message); io.emit('notify', data); } }); /** * Bot Function */ connection.query("SELECT * FROM `bots_cs`", (err, row) => { if ((err) || (!row.length)) { console.log('Bots not found. Stop App.'); console.log(err); return process.exit(0); } for (let i = 0; i < row.length; i++) { const bot = new Bot(row[i]); bots.push(bot); bot.log(`Launch BOT [${row[i].username}]`); } }); class Bot { constructor(row) { this.bot = row; this.client = new SteamUser(); this.community = new SteamCommunity(); this.manager = new TradeOfferManager({ steam: this.client, community: this.community, language: 'en', cancelTime: 300000, pollInterval: 5000 }); this.logger = log4js.getLogger(`bot_${this.bot['id']}`); this.logOnOptions = { 'accountName': this.bot['username'], 'password': this.bot['password'], 'twoFactorCode': SteamTotp.generateAuthCode(this.bot['shared']), 'logonID': 1 }; this.client.logOn(this.logOnOptions); this.client.on('loggedOn', () => { this.log('Logged in Steam!'); }); this.community.on('sessionExpired', () => { this.client.webLogOn(); }); this.client.on('webSession', (sessionid, cookies) => { console.log(cookies); this.manager.setCookies(cookies, function(err) { if (err) { console.log(err); process.exit(1); // Fatal error since we couldn't get our API key return; } }); this.community.setCookies(cookies); }); this.manager.on('newOffer', (offer) => { this.log(`NEW OFFER FROM ${offer.partner.getSteamID64()} #${offer.id}`); if (offer.itemsToGive.length !== 0 && offer.itemsToReceive.length === 0 &&this.client.myFriends[offer.partner.getSteamID64()]) { offer.accept((err, status) => { if (err) { this.log(err); } else { this.log(`OFFER #${offer.id} ACCEPTED`); } }); } else if (offer.itemsToReceive.length !== 0 && offer.itemsToGive.length === 0 && this.client.myFriends[offer.partner.getSteamID64()]) { offer.accept((err, status) => { if (err) { this.log(err); } else { this.newShopItems(offer); this.log(`OFFER #${offer.id} ACCEPTED. NEW ITEMS TO SHOP ADDED`); } }); } else { offer.decline((err) => { }); } }); this.manager.on('sentOfferChanged', (offer, oldState) => { if (offer.state == 7 && offer.confirmationMethod == 0) { this.log(`Offer #${offer.id} DEPOSIT declined!`); io.emit('notify', { steamid: offer.partner.getSteamID64(), msg: `You decline`, status: 'warning' }); } if (offer.state == 7 && offer.confirmationMethod == 2) { this.log(`Offer #${offer.id} WITHDRAW declined!`); this.declinedItems(offer); io.emit('notify', { steamid: offer.partner.getSteamID64(), msg: `You decline`, status: 'warning' }); } if (offer.state == 3 && offer.confirmationMethod == 0) { this.log(`Offer #${offer.id} DEPOSIT accepted!`); io.emit('notify', { steamid: offer.partner.getSteamID64(), msg: `Trade accept`, status: 'success' }); this.getItems(offer); } if (offer.state == 3 && offer.confirmationMethod == 2) { this.log(`Offer #${offer.id} WITHDRAW accepted!`); this.updateItems(offer); } }); } log(msg) { this.logger.debug(`[${this.bot['username']}]: ${msg}`); } newShopItems(offer) { offer.getExchangeDetails((err, status, tradeInitTime, receivedItems, sentItems) => { if (!err) { requestify.post(`https://${config.namesite_cs}/api/newItemsShop`, { items: receivedItems, bot: this.bot['id'] }) .then((response) => { const data = JSON.parse(response.body); }, (error) => { console.log(error); }); } }); } getItems(offer) { offer.getExchangeDetails((err, status, tradeInitTime, receivedItems, sentItems) => { if (!err) { const newReceivedItems = receivedItems.map(item => item.name); const items = receivedItems; const newItems = []; this.log(`OFFER #${offer.id} FROM ${offer.partner.getSteamID64()} ITEMS: ${newReceivedItems.join(',')}`); items.forEach( (item) => { newItems.push({ market_hash_name: item.market_hash_name, type: item.type, new_assetid: item.new_assetid, classid: item.icon_url }); }); client.set(`items_bot_${this.bot['id']}`, `${JSON.stringify(newItems)}`, redis.print); requestify.post(`https://${config.namesite_cs}/api/newItems`, { steamid: offer.partner.getSteamID64(), bot: this.bot['id'] }) .then((response) => { const data = JSON.parse(response.body); if (data.success) { this.log(`OFFER #${offer.id} FROM ${offer.partner.getSteamID64()} ACCEPTED`); io.emit('notify', { msg: `Inventory was update`, status: 'success', steamid: offer.partner.getSteamID64() }); io.emit('updateInventory', { steamid: offer.partner.getSteamID64(), }); } if (!data.success) this.log(`OFFER #${offer.id} FROM ${offer.partner.getSteamID64()} NOT ACCEPTED`); }, (error) => { console.log(error); }); } else { console.log(err); } }); } declinedItems(offer) { const items = offer.itemsToGive; items.forEach( (item) => { connection.query(`UPDATE items SET status = 0 WHERE assetid = ${item['id']}`, (err, row) => { if (err) { this.log(`BD Error: ${err.toString()}`); } }); }); io.emit('updateInventory', { steamid: offer.partner.getSteamID64(), }); } updateItems(offer) { const items = offer.itemsToGive; items.forEach( (item) => { connection.query(`UPDATE bots SET items = items - 1 WHERE id = ${parseInt(this.bot['id'])}`, (err, row) => { if (err) { this.log(`BD Error: ${err.toString()}`); } else { connection.query(`DELETE FROM items WHERE assetid = ${item['id']}`, (err1, row) => { if (err1) { this.log(`BD Error: ${err1.toString()}`); } }); } }); }); io.emit('updateInventory', { steamid: offer.partner.getSteamID64(), }); } deposit(data) { const items = data.items; const trade_link = data.trade_link; const steamid = data.steamid; this.log(`NEW REQUEST TO DEPOSIT FROM ${steamid}`); let sendItems = []; items.forEach((item) => { sendItems.push({ appid: 730, contextid: 2, amount: 1, assetid: item }); }); const offer = this.manager.createOffer(trade_link); offer.addTheirItems(sendItems); offer.setMessage(``); offer.send((err, status) => { if (err) { this.log(`ERROR ON SENDING USER ${steamid} OFFER: ${err.toString()}`); io.emit('notify', { steamid: steamid, msg: `Error with send: ${err.toString()}`, status: 'warning' }); return; } this.log(`OFFER FOR ${steamid} #${offer.id} SENT`); io.emit('notify', { steamid: steamid, msg: `Trade was sent`, trade: offer.id, status: 'success' }); }); } withdraw(data) { const items = data.items; const trade_link = data.trade_link; const steamid = data.steamid; this.log(`NEW REQUEST TO WITHDRAW FROM ${steamid}`); let sendItems = []; items.forEach((item) => { sendItems.push({ appid: 730, contextid: 2, amount: 1, assetid: item }); }); const offer = this.manager.createOffer(trade_link); offer.addMyItems(sendItems); offer.setMessage(``); offer.send((err, status) => { if (err) { this.log(`ERROR ON SENDING USER ${steamid} OFFER: ${err.toString()}`); this.declinedItems(offer); io.emit('notify', { steamid: steamid, msg: `Error with send: ${err.toString()}`, status: 'warning' }); this.client.webLogOn(); return; } this.log(`OFFER FOR ${steamid} #${offer.id} SENT`); this.community.acceptConfirmationForObject(this.bot['identity'], offer.id, function (err) { if (err) { console.log(err); } io.emit('notify', { steamid: steamid, msg: `Trade send`, trade: offer.id, status: 'success' }); }); }); } } Please, help with this error I'll be grateful Edited April 6, 2020 by artyak Quote
sNIP Posted April 6, 2020 Report Posted April 6, 2020 Iam not sure if this is relevant but here is my take: community.on("sessionExpired", function(err) { if (err) { console.log("Session Expired: " + err); } if (client.steamID) { client.webLogOn(); console.log("called weblogon: " + thisId); } else { client.logOn(logOnOptions); console.log("called logon"); } }); Quote
artyak Posted April 7, 2020 Author Report Posted April 7, 2020 On 4/6/2020 at 2:35 PM, sNIP said: Iam not sure if this is relevant but here is my take: community.on("sessionExpired", function(err) { if (err) { console.log("Session Expired: " + err); } if (client.steamID) { client.webLogOn(); console.log("called weblogon: " + thisId); } else { client.logOn(logOnOptions); console.log("called logon"); } }); hope it helps, i will observe the work of the bot, thank you Quote
Recommended Posts
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.