Jump to content
McKay Development

artyak

Member
  • Posts

    8
  • Joined

  • Last visited

artyak's Achievements

  1. hope it helps, i will observe the work of the bot, thank you
  2. 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
  3. Now my server IP was banned, I’m confused, I don’t know what to do
  4. Oh, i understand. I will read about it and make a changes. Maybe you can say something about reload cookies and about ETIMEDOUT error?
  5. Why? What is the problem? I can refuse to use confirmation checker if you recommend an alternative.
  6. I has a bot, running this code: 'use strict'; const fs = require('fs'); const sslOptions = { key: fs.readFileSync('/opt/psa/var/modules/letsencrypt/etc/live/site.com/privkey.pem'), cert: fs.readFileSync('/opt/psa/var/modules/letsencrypt/etc/live/site.com/fullchain.pem'), requestCert: true, rejectUnauthorized: false }; 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(8080); connection.query("SET SESSION wait_timeout = 604800"); 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`", (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']) }; this.client.logOn(this.logOnOptions); this.client.on('loggedOn', () => { this.log('Logged in Steam!'); }); this.client.on('webSession', (sessionid, 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.community.startConfirmationChecker(5000, this.bot['identity']); this.community.on('sessionExpired', () => { this.client.webLogOn(); }); }); 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 offer`, 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 offer`, 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}/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}/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: `Inv 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: 570, 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 send: ${err.toString()}`, status: 'warning' }); return; } this.log(`OFFER FOR ${steamid} #${offer.id} SENT`); io.emit('notify', { steamid: steamid, msg: `Offer send`, 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: 570, 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' }); return; } this.log(`OFFER FOR ${steamid} #${offer.id} SENT`); this.community.checkConfirmations(); this.community.acceptConfirmationForObject(this.bot['identity'], offer.id, function (err) { io.emit('notify', { steamid: steamid, msg: `Send`, trade: offer.id, status: 'success' }); }); }); } } After 24 hours of work i received Error: ETIMEDOUT, or error with old cookies. How i can refresh cookies, for example every 6 hours and how i can fix error ETIMEDOUT? Because if i restart bot, all work fine. Thank for reply!
  7. Here: function sendWithdrawOffer(data) { var sendItems = []; for(var i = 0; i < data.items.length; i++) { sendItems.push({ appid : 570, contextid : 2, assetid : data.items[i] }); } var offer = manager.createOffer(data.url); offer.addMyItems(sendItems); offer.setMessage('CODE: ' + data.code); sentWithdrawOfferNoErr(offer, data.items, data.code, data.user, data.price); }
  8. Hi all. I use TradeOfferManager = require('steam-tradeoffer-manager'), for my Dota 2 project. Now i want use one bot for processing Dota 2 + CS:GO trades. At bot i use appid: 570. How i can use appid: with Dota 2 and CS:GO? I try to use appid: 570 || 730, and appid: 570 && 730, but all time he proceed only request from last number (730). How i can make it?
×
×
  • Create New...