Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.84 KB | None | 0 0
  1. var _ = require('lodash');
  2. var server = require('http').Server();
  3. var io = require('socket.io')(server);
  4. var mysql = require('mysql');
  5. var async = require("async");
  6. var connection = mysql.createConnection({
  7. host: 'localhost',
  8. user: 'adminn',
  9. password: 'C5kgXx((@@',
  10. database: 'jackpot'
  11. });
  12.  
  13. server.listen(8788);
  14.  
  15. var request = require("request");
  16. var admins = ['76561198269216247', '76561198258632124', '76561198023345468'];
  17. var util = require('util');
  18. var TradeOfferManager = require('steam-tradeoffer-manager');
  19. var fs = require('fs');
  20. var Steamcommunity = require('steamcommunity');
  21. var ParentBot = require('steam-parentbot'); //change to 'steam-parentbot' if not running from examples directory
  22. var Steam = ParentBot.Steam; //instance of the Steam object
  23. var PriceApiKey = 'fFlJtSeeJb7wzswQG5FYJyeytkVK6dE8';
  24. var request = require("request");
  25. var community = new Steamcommunity();
  26. var ChildBot = function () {
  27. ChildBot.super_.apply(this, arguments);
  28. }
  29. util.inherits(ChildBot, ParentBot);
  30.  
  31. var Bot = new ChildBot('csboxbot1', 'C5kgXx99', {
  32. apikey: 'AC2CD27C06C67830F32F0B6D661461EE', //steam api key, will be registered automatically if one isn't supplied
  33. sentryfile: 'csboxbot1.sentry', //sentry file that stores steamguard info, defaults to username.sentry
  34. logfile: 'csboxbot1.log', //filename to log stuff to, defaults to username.log
  35. sharedSecret: 'hD41Fnt8Qe8TY3WQTyZhv8ZND8c=', //shared secret, needed to automatically generate twoFactorCode
  36. identitySecret: 'PUH91isKkTB3OJmcxIPdIb9b2ug=', //identity secret, needed to automatically confirm trade offers, must be used with confirmationInterval
  37. confirmationInterval: 10000, //how often we should check for new trades to confirm in miliseconds, must be used with identitySecret
  38. richPresenceID: 730 //game to use rich presence with, don't include for no rich presence
  39. });
  40.  
  41. var SteamTotp = require('steam-totp');
  42. var util = require('util');
  43. var botMain = function () {
  44. botMain.super_.apply(this, arguments);
  45. }
  46. util.inherits(botMain, ParentBot);
  47.  
  48. var TOTP = require('onceler').TOTP;
  49. var totp = new TOTP('D2EUYJ7OKUV6TUKU');
  50. var manager = new TradeOfferManager({
  51. "domain": "http://csgourban.com", // Our domain is example.com
  52. "language": "en", // We want English item descriptions
  53. "pollInterval": 5000 // We want to poll every 5 seconds since we don't have Steam notifying us of offers
  54. });
  55. if (fs.existsSync('polldata.json')) {
  56. manager.pollData = JSON.parse(fs.readFileSync('polldata.json'));
  57. }
  58.  
  59. Bot.steamUser.on('tradeOffers', function (number) {
  60. if (number > 0) {
  61. handleOffers();
  62. bang('Przeglądam oferty :) Jest ich: ' + number + '');
  63. }
  64. });
  65.  
  66. function sendMessage(steamID, message) {
  67. Bot.steamFriends.sendMessage(steamID, message);
  68. }
  69.  
  70. Bot.steamClient.on('logOnResponse', function (logonResp) {
  71. //console.log('Event "logOnResponse": ' + JSON.stringify(logonResp));
  72. if (logonResp.eresult === Steam.EResult.OK) {
  73. console.log('Logged in!');
  74. SteamBot = true;
  75. reWebLogOn();
  76. }
  77. });
  78. Bot.steamClient.on('loggedOff', function () {
  79. SteamBot = false;
  80. });
  81. Bot.steamClient.on('error', function (e) {
  82. console.log('Wystąpił błąd : ' + e + '');
  83. });
  84.  
  85. Bot.connect();
  86.  
  87. io.on('connection', function (socket) {
  88. var withdraws = socket;
  89. withdraws.on('loadInventory', function () {
  90. Bot.offers.loadPartnerInventory({
  91. partnerSteamId: '76561198295495923',
  92. appId: '730',
  93. contextId: '2',
  94. language: 'pl'
  95. }, function (err, items) {
  96. var que = [];
  97. var showeq = [];
  98. connection.query('SELECT * FROM withdraw_que', function (error, results, fields) {
  99. async.each(results, function (value, callback) {
  100. que.push(value['assetID']);
  101. callback();
  102. }, function (err) {
  103. withdraws.emit('inventory', items);
  104. withdraws.emit('que', que);
  105. });
  106. });
  107. });
  108. });
  109. withdraws.on('steamide', function (data) {
  110. var steamID = data;
  111. withdraws.emit('processing', true);
  112. withdraws.on('withdrawItems', function (data) {
  113. var itemCost = 0;
  114. var fruits = data;
  115. async.each(data, function (value, callback) {
  116. var item = encodeURIComponent(value);
  117. request({
  118. url: 'http://csgourban.com/getItemPrice/' + item + '',
  119. json: true
  120. }, function (error, response, body) {
  121. if (body != '') {
  122. var itemPrice = body[0]['avgPrice30Days'];
  123. itemCost = parseInt(itemCost) + parseInt(itemPrice);
  124. callback();
  125. } else {
  126. withdraws.emit('processing', 'error');
  127. return;
  128. }
  129. });
  130. }, function (err) {
  131. // if any of the file processing produced an error, err would equal that error
  132. if (err) {
  133. withdraws.emit('processing', 'error');
  134. } else {
  135. itemCost = itemCost * 10;
  136. connection.query('SELECT * FROM users WHERE steamId64=' + steamID + '', function (error, results, fields) {
  137. var userCoins = results[0]['coins'];
  138. var tradeToken = results[0]['tradeToken'];
  139. connection.query('SELECT sum(itemPrice) as draw FROM wholeItems WHERE ownerSteamId64=' + steamID + '', function (error, results, fields) {
  140. if (error) {
  141. return;
  142. }
  143. var draw = results[0]['draw'];
  144. if (draw < 3000) {
  145. withdraws.emit('processing', 'draw');
  146. return;
  147. } else {
  148. if (userCoins < itemCost) {
  149. withdraws.emit('processing', 'low');
  150. } else {
  151. Bot.offers.loadMyInventory({
  152. appId: 730,
  153. contextId: 2
  154. }, function (err, items) {
  155. if (err) {
  156. withdraws.emit('processing', 'error');
  157. return;
  158. }
  159. var itemo = [], numo = 1;
  160. var itemosID = [];
  161. var itemssToSend = [];
  162. var itemsToSend = fruits;
  163.  
  164. itemsToSend.forEach(function (value, index) {
  165. itemssToSend.push(value);
  166. });
  167. var prevID = 0;
  168. itemssToSend.forEach(function (value, index) {
  169. var finder = _.find(items, function (o) {
  170. var findom = _.find(itemo, {assetid: o.id});
  171. return o.id != prevID && o.market_name == value && findom == undefined;
  172. });
  173. if (finder != undefined) {
  174. var findero = finder['id'];
  175. itemosID.push({"findero": findero, "name": value});
  176. itemo[numo] = {
  177. appid: 730,
  178. contextid: 2,
  179. amount: 1,
  180. assetid: finder['id']
  181. }
  182. prevID = finder['id'];
  183. }
  184. numo++;
  185. });
  186. if (numo > 0) {
  187. async.each(itemosID, function (value, callback) {
  188. var itemname = encodeURIComponent(value['name']);
  189. connection.query('INSERT INTO withdraw_que SET user_id="' + steamID + '",' +
  190. 'assetID="' + value['findero'] + '",' +
  191. 'itemname="' + itemname + '"', function (error, results, fields) {
  192. if (error) {
  193. withdraws.emit('processing', 'error');
  194. console.log(error);
  195. return;
  196. } else {
  197. callback();
  198. }
  199. });
  200. }, function (err) {
  201. if (err) {
  202. withdraws.emit('processing', 'error');
  203. return;
  204. } else {
  205. withdraws.emit('processing', 'success');
  206. }
  207. });
  208. }
  209.  
  210. });
  211. }
  212. }
  213. });
  214.  
  215. });
  216. }
  217. });
  218. });
  219.  
  220. });
  221.  
  222. });
  223.  
  224.  
  225. setInterval(function () {
  226. handleOffers();
  227. }, 30000);
  228.  
  229. setInterval(function () {
  230. handleQue();
  231. }, 10000);
  232.  
  233. Bot.steamUser.on('webSessionID', function (webSessionID) {
  234. console.log('Event "webSessionID" sessionID: ' + webSessionID);
  235. console.log('Event "webSessionID" SteamClient.sessionID: ' + SteamClient.sessionID);
  236. gSessionID = webSessionID;
  237. globalSessionID = webSessionID;
  238. manager.setCookies(cookies, function(err) {
  239. if (err) {
  240. console.log(err);
  241. process.exit(1); // Fatal error since we couldn't get our API key
  242. return;
  243. }
  244.  
  245. console.log("Got API key: " + manager.apiKey);
  246. });
  247. community.setCookies(cookies);
  248. community.startConfirmationChecker(30000, "identitySecret");
  249. });
  250. ChildBot.prototype._onFriendMsg = function (steamID, message, type) { //overwrite default event handlers
  251. if (admins.indexOf(steamID) !== -1) {
  252. if (message == '/token') {
  253. var _2facode = SteamTotp.generateAuthCode(Bot.sharedSecret);
  254. Bot.steamFriends.sendMessage(steamID, 'Proszę : ' + _2facode + '');
  255. } else if (message == '/send') {
  256. Bot.offers.loadMyInventory({
  257. appId: 730,
  258. contextId: 2
  259. }, function (err, items) {
  260.  
  261. console.log(err);
  262. if (err) {
  263. console.log('Problem');
  264. steam.webLogOn(function (newCookie) {
  265. offers.setup({
  266. sessionID: globalSessionID,
  267. webCookie: newCookie
  268. }, function (err) {
  269. if (err) {
  270. }
  271. });
  272. });
  273. return;
  274. }
  275. var item = [], num = 0;
  276. var itemssToSend = [], numero = 0;
  277.  
  278. for (var i = 0; i < items.length; i++) {
  279. if (items[i].tradable) {
  280. item[num] = {
  281. appid: 730,
  282. contextid: 2,
  283. amount: items[i].amount,
  284. assetid: items[i].id
  285. }
  286. num++;
  287. }
  288. }
  289. if (num > 0) {
  290. Bot.offers.makeOffer({
  291. partnerSteamId: steamID,
  292. itemsFromMe: item,
  293. itemsFromThem: [],
  294. message: ''
  295. }, function (err, response) {
  296. if (err) {
  297. throw err;
  298. }
  299. console.log('Wysłałem');
  300. });
  301. }
  302. });
  303. }
  304. } else {
  305. if (type === Steam.EChatEntryType.ChatMsg) {
  306. //Bot.steamFriends.sendMessage(steamID, 'CSBOX.pl'); //use your custom options
  307. //this.logger.info(steamID + ' sent: ' + message);
  308. }
  309. else {
  310. //console.log(type);
  311. }
  312. }
  313.  
  314. }
  315.  
  316. ChildBot.prototype._onFriend = function (steamID, relationship) {
  317. if (relationship === 2) {
  318. if (admins.indexOf(steamID) !== -1) {
  319. Bot.steamFriends.addFriend(steamID);
  320. }
  321. else {
  322. Bot.logger.warn('Someone who isn\'t an admin tried to add me, denying...');
  323. Bot.steamFriends.removeFriend(steamID);
  324. }
  325. }
  326. }
  327.  
  328.  
  329. ////////////// END OF BOT
  330.  
  331. function reWebLogOn(callback) {
  332. Bot.steamUser.on('webSessionID', function (sessionID, newCookie) {
  333. console.log('webLogOn: ' + JSON.stringify({
  334. sessionID: sessionID,
  335. cookie: newCookie
  336. }));
  337.  
  338. getSteamAPIKey({
  339. sessionID: sessionID,
  340. webCookie: newCookie
  341. }, function (err, apiKey) {
  342. if (err) {
  343. console.log('Ошибка в событии logOnResponse ERROR ' + err);
  344. }
  345. else {
  346. console.log('getSteamAPIKey: ' + apiKey);
  347.  
  348. Bot.offers.setup({
  349. sessionID: sessionID,
  350. webCookie: newCookie, //APIKey: config.apiKey
  351. APIKey: apiKey
  352. });
  353.  
  354. if (typeof callback == "function") {
  355. callback();
  356. }
  357. }
  358. });
  359. });
  360. }
  361.  
  362. function handleQue() {
  363. connection.query('SELECT * FROM withdraw_que LEFT JOIN users ON users.steamId64=withdraw_que.user_id WHERE status="awaiting" GROUP BY user_id', function (error, results, fields) {
  364. if(results.length < 1) {
  365. return;
  366. }
  367. var users = [];
  368. async.each(results, function (value, callback) {
  369. users.push({"userid": value['user_id'], "tradeToken": value['tradeToken']});
  370. callback();
  371. }, function (err) {
  372. if (err) {
  373. console.log(err);
  374. } else {
  375. console.log('LIST OF PLAYERS LOADED');
  376. var fruits = [];
  377. async.each(users, function (value, callback) {
  378. var userid = value['userid'];
  379. var tradeToken = value['tradeToken'];
  380. connection.query('SELECT * FROM withdraw_que WHERE user_id=' + userid + ' AND status="awaiting"', function (error, results, fields) {
  381. if (!error) {
  382. fruits.push(results);
  383. callback();
  384. } else {
  385. console.log(error);
  386. }
  387. });
  388. }, function (err) {
  389. if (err) {
  390. console.log(err);
  391. } else {
  392. console.log('LIST OF ITEMS TO SEND LOADED');
  393. Bot.offers.loadMyInventory({
  394. appId: 730,
  395. contextId: 2
  396. }, function (err, items) {
  397. var itemo = [], numo = 1;
  398. var itemssToSend = [];
  399. var itemsToSend = fruits[0];
  400. var userID = itemsToSend[0]['user_id'];
  401. itemsToSend.forEach(function (value, index) {
  402. itemssToSend.push(value);
  403. });
  404. var prevID = 0;
  405. var itemCost = 0;
  406. async.each(itemssToSend, function (value, callback) {
  407. var item = value['itemname'];
  408. request({
  409. url: 'http://csgourban.com/getItemPrice/' + item + '',
  410. json: true
  411. }, function (error, response, body) {
  412. if (body != '') {
  413. var itemPrice = body[0]['avgPrice30Days'];
  414. itemCost = parseInt(itemCost) + parseInt(itemPrice);
  415. callback();
  416. } else {
  417. withdraws.emit('processing', 'error');
  418. return;
  419. }
  420. });
  421. }, function (err) {
  422. if (!err) {
  423. var prowizja = parseInt(itemCost) * 0.05;
  424. itemCost = parseInt(itemCost) * 10;
  425. itemCost = parseInt(itemCost) + parseInt(prowizja);
  426. //console.log(itemCost);
  427. connection.query('SELECT * FROM users WHERE steamId64=' + userID + '', function (error, results, fields) {
  428. //console.log(results);
  429. if (!error) {
  430. var tradeToken = results['tradeToken'];
  431. var userCoins = results['coins'];
  432. if (userCoins < itemCost) {
  433. connection.query('DELETE FROM withdraw_que WHERE user_id=' + userID + ' AND status="awaiting"', function (error, results, fields) {
  434. console.log('Nie stać go, usuwam');
  435. return;
  436. });
  437. }
  438. ;
  439. }
  440. });
  441. async.each(itemssToSend, function (value, callback) {
  442. var itemname = decodeURIComponent(value['itemname']);
  443. // console.log(itemname);
  444. var finder = _.find(items, function (o) {
  445. var findom = _.find(itemo, {assetid: o.id});
  446. return o.id != prevID && o.market_name == itemname && findom == undefined;
  447. });
  448. if (finder != undefined) {
  449. itemo[numo] = {
  450. appid: 730,
  451. contextid: 2,
  452. amount: 1,
  453. assetid: finder['id']
  454. }
  455. prevID = finder['id'];
  456. }
  457. numo++;
  458. callback();
  459. }, function (err) {
  460. if (numo > 0) {
  461. connection.query('SELECT * FROM users WHERE steamId64=' + userID + '', function (error, results, fields) {
  462. if (!error) {
  463. var tradeToken = results[0]['tradeToken'];
  464. //console.log(itemo);
  465. Bot.offers.makeOffer({
  466. partnerSteamId: userID,
  467. itemsFromMe: itemo,
  468. itemsFromThem: [],
  469. accessToken: tradeToken,
  470. message: 'Thanks for playing our site! Have a nice day!'
  471. }, function (err, response) {
  472. if (err) {
  473. console.log(err);
  474. return;
  475. }
  476. console.log(response);
  477. connection.query('UPDATE withdraw_que SET status="sended" WHERE user_id=' + userID + '', function (error, results, fields) {
  478. if (!error) {
  479. console.log('Withdraw offer send.');
  480. }
  481. });
  482. var offerID = response['tradeofferid'];
  483. var cost = itemCost;
  484. connection.query('INSERT INTO ofers SET userID=' + userID + ', value=' + itemCost + ',' +
  485. 'tradeOfferID=' + offerID + ',status="waiting"', function (error, results, fields) {
  486. if (!error) {
  487. console.log('Offer added to history');
  488. }
  489. });
  490. });
  491. }
  492. });
  493. //console.log('Są itemy do wysłania, jedziemy z koksem');
  494. }
  495. })
  496. }
  497. });
  498. });
  499. }
  500. });
  501. }
  502. });
  503. });
  504. }
  505. function handleOffers() {
  506.  
  507. Bot.offers.getOffers({
  508. get_received_offers: 1,
  509. active_only: 1,
  510. time_historical_cutoff: Math.round(Date.now() / 1000),
  511. get_descriptions: 1
  512. }, function (error, body) {
  513. if (error) {
  514. return bang(error);
  515. }
  516. var TradesRecived = body.response.trade_offers_received;
  517. if (TradesRecived == undefined) {
  518. //bang('Brak ofert, papa :)');
  519. return false;
  520. } else {
  521. tradeOffersNumber = Object.keys(TradesRecived).length;
  522. if (tradeOffersNumber < 1) {
  523. } else {
  524. //bang('Ofert do przejrzenia : ' + tradeOffersNumber + '');
  525. }
  526. }
  527. TradesRecived.forEach(function (value, index) {
  528. var tradeOwner = value.steamid_other;
  529. var tradeID = value.tradeofferid;
  530. var tradeItems = value.items_to_receive;
  531. var csgo = true;
  532. var holded = false;
  533. if (value.items_to_receive != undefined) {
  534. value.items_to_receive.forEach(function (value, index) {
  535. if (value.appid != '730') {
  536. csgo = false;
  537. }
  538. });
  539. }
  540. request({
  541. url: 'http://csgourban.com/getUserInfo/' + tradeOwner + '',
  542. json: true
  543. }, function (error, response, body) {
  544. if (body == undefined) {
  545. return;
  546. }
  547. var tradeT = body['tradeToken'];
  548. Bot.offers.getHoldDuration({
  549. partnerSteamId: value.steamid_other,
  550. accessToken: tradeT
  551. }, function (err, response) {
  552. if (err) {
  553. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  554. return;
  555. }
  556. var heis = response['their'];
  557. if (heis != 0) {
  558. //console.log('TradeLock, wyrzuć');
  559. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  560. return;
  561. } else {
  562. Bot.offers.getTradeHoldDuration({
  563. tradeOfferId: tradeID
  564. }, function (err, hold) {
  565. if (err) {
  566. // console.log(heis);
  567. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  568. return;
  569. } else {
  570.  
  571. var HisHold = hold['their'];
  572. if (HisHold != '0') {
  573. holded = true;
  574. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  575. return;
  576. } else {
  577. // console.log('Brak tradelocka, przyjmij.');
  578. }
  579. }
  580. });
  581. // console.log('Owner' + tradeOwner);
  582. request({
  583. url: 'http://csgourban.com/getUserInfo/' + tradeOwner + '',
  584. json: true
  585. }, function (error, response, body) {
  586. if (!error && response.statusCode === 200) {
  587. if (body == undefined) {
  588. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  589. return;
  590. }
  591. var tradeOwnerNick = body.nick;
  592. if (value.items_to_give) {
  593. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  594. return;
  595. }
  596. if (value.items_to_receive == undefined) {
  597. return;
  598. }
  599. if (value.items_to_receive.length == undefined) {
  600. return;
  601. }
  602. if (value.items_to_receive.length > 100 || tradeOwnerNick == undefined || value.items_to_give || csgo == false) {
  603. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  604. } else {
  605. // console.log(holded);
  606. if (holded == true) {
  607. console.log(their);
  608. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  609. return;
  610. } else {
  611. Bot.offers.loadPartnerInventory({
  612. partnerSteamId: tradeOwner,
  613. appId: '730',
  614. contextId: '2',
  615. language: 'pl'
  616. }, function (err, items) {
  617. if (!err) {
  618. if (value.items_to_receive != undefined) {
  619. var updateFor = 0;
  620. value.items_to_receive.forEach(function (value, index) {
  621. var itemDetils = _.find(items, {id: value.assetid});
  622. if (itemDetils != undefined) {
  623. var itemName = itemDetils['market_name'];
  624. var itemColor = itemDetils['name_color'];
  625. var itemType = itemDetils['type'];
  626. var itemIcon = itemDetils['icon_url'];
  627. var classid = itemDetils['classid'];
  628. var instanceid = itemDetils['id'];
  629. var ownerSteamID64 = tradeOwner;
  630.  
  631. // console.log(itemDetils);
  632. secret = totp.now();
  633. apikey = '4ca564b7-ff8d-44d9-908f-c002bd28fd3f';
  634. var item = itemName;
  635. var item = encodeURIComponent(item);
  636. request({
  637. url: 'http://csgourban.com/getItemPrice/' + item + '',
  638. json: true
  639. }, function (error, response, body) {
  640. item = decodeURIComponent(item);
  641. if (body != '') {
  642. //console.log(body);
  643. var itemPrice = body[0]['avgPrice30Days'];
  644. updateFor = parseInt(updateFor) + parseInt(itemPrice);
  645. if (itemPrice < 20) {
  646. Bot.offers.declineOffer({tradeOfferId: tradeID});
  647. return;
  648. }
  649. connection.query('INSERT INTO wholeItems SET ownerSteamId64="' + ownerSteamID64 + '",' +
  650. 'ownerSteamId32="STEAM_0:0:128976850",' +
  651. 'itemName="' + body[0]['marketName'] + '",' +
  652. 'itemPrice="' + body[0]['avgPrice30Days'] + '",' +
  653. 'itemRarityName="' + itemType + '",' +
  654. 'itemRarityColor="' + itemColor + '",' +
  655. 'itemIcon="' + itemIcon + '"', function (error, results, fields) {
  656. if (error) {
  657. console.log(error)
  658. }
  659. });
  660. }
  661. });
  662. }
  663. })
  664. }
  665. Bot.offers.acceptOffer({
  666. tradeOfferId: tradeID
  667. }, function (err) {
  668. if (err) {
  669. Bot.offers.declineOffer({tradeOfferId: value.tradeofferid});
  670. return;
  671. } else {
  672. bang('Akceptuję ofertę od: (' + tradeOwnerNick + ')');
  673. request({
  674. url: 'http://csgourban.com/getUserInfo/' + tradeOwner + '',
  675. json: true
  676. }, function (error, response, body) {
  677. if (error) {
  678. Bot.offers.declineOffer({tradeOfferId: tradeID});
  679. return;
  680. }
  681. updateFor = updateFor * 10;
  682. var updateCoins = parseInt(body.coins) + parseInt(updateFor);
  683. console.log(updateCoins);
  684. connection.query('UPDATE users SET coins="' + updateCoins + '" WHERE steamId64="' + body.steamId64 + '"', function (err, rows) {
  685. if (err) {
  686. Bot.offers.declineOffer({tradeOfferId: tradeID});
  687. return;
  688. }
  689. });
  690. })
  691. }
  692. });
  693. }
  694. });
  695. }
  696. }
  697. }
  698. });
  699. }
  700. });
  701. });
  702.  
  703. });
  704.  
  705. });
  706. };
  707.  
  708. function bang(message) {
  709. console.log(message);
  710. }
  711. manager.on('pollData', function(pollData) {
  712. fs.writeFile('polldata.json', JSON.stringify(pollData));
  713. console.log('Pulled Data');
  714. });
  715. manager.on('sentOfferChanged', function(offer, oldState) {
  716. console.log("Offer #" + offer.id + " changed: " + TradeOfferManager.getStateName(oldState) + " -> " + TradeOfferManager.getStateName(offer.state));
  717. if (offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
  718. offer.getReceivedItems(function(err, items) {
  719. if (err) {
  720. console.log("Couldn't get received items: " + err);
  721. } else {
  722. var names = items.map(function(item) {
  723. return item.name;
  724. });
  725.  
  726. console.log("Received: " + names.join(', '));
  727. }
  728. });
  729. }
  730. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement