Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.78 KB | None | 0 0
  1. var Steam = require('steam');
  2. var SteamUser = require('steam-user');
  3. var usd = SteamUser.ECurrencyCode.USD;
  4. var prompt = require('prompt');
  5. var NodeSteamUser = new SteamUser();
  6. var SteamManager = require('steam-tradeoffer-manager');
  7. var username;
  8. var auth = require('steam-totp');
  9. var fs = require('fs');
  10. var httprequest = require('request');
  11. var password;
  12. var manager;
  13. var rate;
  14. var sellrate = 1.80; //Customer sell rate, not bot's.
  15. var buyrate = 1.85; //Cutomer buy rate, not bot's.
  16. var steamc = require('steamcommunity');
  17. var shared_secret;
  18. var identity_secret;
  19. var sbalance;
  20. var cookiesT = [];
  21. var steamcommunity = new steamc();
  22. console.log("Loading BTC Bot v1.0");
  23. fs.readFile('account.txt', function(err,data){
  24. if (err) throw err;
  25. var parsed = JSON.parse(data);
  26. username = parsed.username;
  27. password = parsed.password;
  28. shared_secret = parsed.shared_secret;
  29. identity_secret = parsed.identity_secret;
  30. var currentcode = auth.getAuthCode(shared_secret);
  31. NodeSteamUser.logOn({
  32. accountName: username,
  33. password: password,
  34. twoFactorCode: currentcode
  35. });
  36. });
  37. updateRate();
  38. setInterval(updateRate, 60*1000*10);
  39. function updateRate(){
  40. httprequest('https://blockchain.info/ticker', function(error, response, body){
  41. if (error) console.log(error);
  42. rate = JSON.parse(body).USD.last;
  43. });
  44. }
  45.  
  46.  
  47.  
  48. manager = new SteamManager({
  49. "steam" : NodeSteamUser,
  50. "language" : "en"
  51. });
  52.  
  53.  
  54.  
  55. NodeSteamUser.on('loggedOn', function(){console.log("[INFO]Login Success!");NodeSteamUser.webLogOn();});
  56. NodeSteamUser.on('webSession', function(sessionID, cookies){
  57. console.log('[INFO] Web Login Success!');
  58. sessionIDT = sessionID;
  59. cookiesT = cookies;
  60. console.log("[INFO] Cookie Array was Set!");
  61. manager.setCookies(cookies, function(erghab){
  62. console.log(erghab);
  63. });
  64. steamcommunity.setCookies(cookiesT);
  65. console.log("[INFO] Manager cookies were set.");
  66. steamcommunity.startConfirmationChecker(10000, identity_secret);
  67. NodeSteamUser.setPersona(Steam.EPersonaState.Online);
  68. httprequest('https://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/balance?password=Cabdca1499', function(error, response, bodyir){
  69. if (error) console.log(error);
  70. var balance = JSON.parse(bodyir).balance;
  71. var satoshi = balance / 100000000 * rate;
  72. satoshi = satoshi.toFixed(2);
  73. sbalance = satoshi;
  74. console.log("[INFO] Synced Balance. " + sbalance.toString());
  75. });
  76. });
  77. //Add relationship requests to queue
  78. NodeSteamUser.on('friendRelationship', function(sid, relationship){
  79. if (relationship == Steam.EFriendRelationship.RequestRecipient){
  80. NodeSteamUser.addFriend(sid);
  81. fs.readFile('current.txt', function(nope, body){
  82. if (nope) console.log(nope);
  83. var tmpfile = JSON.parse(body);
  84. tmpfile[tmpfile.length] = {steamid: sid.getSteamID64(),
  85. action: "",
  86. Confirmed: 0,
  87. Done: 0,
  88. Keys: 0,
  89. BTC: ""};
  90. fs.writeFile('current.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  91.  
  92. });
  93. NodeSteamUser.chatMessage(sid.getSteamID64(), "Hello! I am a bot who sells and buy for BTC. Type help if you need help with my commands. Removing me will reset any interaction with you, so only remove me before starting a sell/buy proccess. Doing so may cause it a bug, resulting you in losing money. Removing me while in a proccess is purely your responsability, and the staff will not refund you.");
  94. }
  95. if (relationship == Steam.EFriendRelationship.None){
  96. fs.readFile('current.txt', function(nope, body){
  97. if (nope) console.log(nope);
  98. var tmpfile = JSON.parse(body);
  99. var index;
  100. for(var i = 0;i<tmpfile.length;i++){
  101. if (tmpfile[i].steamid == sid.getSteamID64()){
  102. tmpfile.splice(i, 1);
  103. }
  104. }
  105. fs.writeFile('current.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  106.  
  107. });
  108. }
  109. });
  110.  
  111.  
  112. //Commands Checker
  113. NodeSteamUser.on('friendMessage', function(sender, message){
  114. fs.readFile('current.txt', function(err, body){
  115. if (err) console.log(err);
  116. var fullbdy = JSON.parse(body);
  117. var info;
  118. var rawr = false;
  119. for (var i = 0;i<JSON.parse(body).length;i++){
  120. if (JSON.parse(body)[i].steamid == sender.getSteamID64()){
  121. info = JSON.parse(body)[i];
  122. rawr = true;
  123. }
  124. }
  125. if (rawr){
  126. if (info.action == ""){
  127. if (message == "help"){
  128. NodeSteamUser.chatMessage(info.steamid, "My Commands: \n stock - How many keys I have in stock;\n balance - How many Bitcoins I have in my account;\n buy - Starts the trade where you buy keys;\n sell - Starts the trade where you sell keys;");
  129. }else if (message=="stock"){
  130. var keys = 0;
  131. manager.loadInventory(730, 2, true, function(errorlol, inv, currencies){
  132. if (errorlol) console.log(errorlol);
  133. for (var i = 0;i<inv.length;i++){
  134. if (inv[i].market_hash_name != "Case Key" && inv[i].market_hash_name.indexOf("Case Key") >= 0)
  135. keys++;
  136. }
  137. NodeSteamUser.chatMessage(info.steamid, "I have "+keys.toString()+" keys in stock.");
  138. });
  139. }else if("balance" == message){
  140. NodeSteamUser.chatMessage(info.steamid, "I currently have "+sbalance.toString()+" USD.");
  141.  
  142.  
  143. }else if(message == "sell"){
  144. manager.getEscrowDuration(info.steamid, function(errar, tdays, mdays){
  145.  
  146. if (tdays == 0){
  147. info.action = "sell#1";
  148. var nr2 = JSON.parse(body);
  149. for (var i = 0;i<JSON.parse(body).length;i++){
  150. if (JSON.parse(body)[i].steamid == sender.getSteamID64()){
  151. nr2[i] = info;
  152. }
  153. }
  154. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  155. NodeSteamUser.chatMessage(info.steamid, "Selling proccess started and no escrow detected. How many keys would you like to sell?");
  156. }else{
  157. NodeSteamUser.chatMessage(info.steamid, "Sorry, but I am not buying keys from users that have an Escrow Trade Hold.");
  158. }
  159. });
  160.  
  161. }
  162.  
  163. else if(message=="buy"){
  164. info.action = "buy#1";
  165. var nr2 = JSON.parse(body);
  166. for (var i = 0;i<JSON.parse(body).length;i++){
  167. if (JSON.parse(body)[i].steamid == sender.getSteamID64()){
  168. nr2[i] = info;
  169. }
  170. }
  171. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  172. NodeSteamUser.chatMessage(info.steamid, "Buying proccess started! How many keys would you like to buy?");
  173. }else{
  174. NodeSteamUser.chatMessage(info.steamid, "Invalid Command!");
  175. }
  176. }else{
  177. var args = info.action.split("#");
  178. if (args[0] == "buy"){
  179. if (args[1] == "1"){
  180. var keys = parseInt(message);
  181. if (Number(keys) == keys && keys != 0){
  182.  
  183. manager.loadInventory(730, 2, true, function(nah, inv){
  184. if (nah) NodeSteamUser.chatMessage(info.steamid, "Error loading invetory...if this persists, please report to my owner!");
  185. var stock = 0;
  186. for (var i = 0;i<inv.length;i++){
  187. if (inv[i].market_hash_name != "Case Key" && inv[i].market_hash_name.indexOf("Case Key") >= 0){
  188. stock++;
  189. }
  190. }
  191. if (stock >= keys){
  192. info.action = "buy#2";
  193. info.Keys = keys;
  194. var nr2 = JSON.parse(body);
  195. for (var i = 0;i<JSON.parse(body).length;i++){
  196. if (JSON.parse(body)[i].steamid == sender.getSteamID64())
  197. nr2[i] = info;
  198. }
  199. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  200. NodeSteamUser.chatMessage(info.steamid, "Great! I have enough keys in my account! Please input your Bitcoin address from which you are going to send the money. Make sure you double read it before sending it.");
  201. }else
  202. NodeSteamUser.chatMessage(info.steamid, "It seems like I don't have enough keys in my account :/ . Select another amount.");
  203.  
  204.  
  205.  
  206.  
  207. });
  208. }else{
  209. NodeSteamUser.chatMessage(info.steamid, "Sorry! We couldn't parse your response! Please send the amount again.");
  210. }
  211.  
  212. } else if (args[1] == "2"){
  213. var nr2 = JSON.parse(body);
  214. info.action = "buy#3";
  215. info.BTC = message;
  216. for (var i = 0;i<JSON.parse(body).length;i++){
  217. if (JSON.parse(body)[i].steamid == info.steamid){
  218. nr2[i] = info;
  219. }
  220. }
  221. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  222. NodeSteamUser.chatMessage(info.steamid, "Are you sure you want to buy "+info.Keys.toString()+" keys for "+(info.Keys * buyrate + 0.01).toString()+" USD(0.01 transaction fee)? Your BTC Address: "+info.BTC+" . Type yes to continue and no to cancel");
  223. }else if(args[1] == "3"){
  224. if (message == "no"){
  225. var nr2 = JSON.parse(body);
  226. info.action = "";
  227. info.BTC = "";
  228. info.Keys = 0;
  229. for (var i = 0;i<JSON.parse(body).length;i++){
  230. if (JSON.parse(body)[i].steamid == info.steamid){
  231. nr2[i] = info;
  232. }
  233. }
  234. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  235. NodeSteamUser.chatMessage(info.steamid, "Proccess canceled!");
  236. }else if(message == "yes"){
  237. var nr2 = JSON.parse(body);
  238. info.action = "buy#4";
  239.  
  240. for (var i = 0;i<JSON.parse(body).length;i++){
  241. if (JSON.parse(body)[i].steamid == info.steamid){
  242. nr2[i] = info;
  243. }
  244. }
  245. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  246. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/new_address?password=Cabdca1499&label='+info.steamid, function(nahr, rezponse, baddi){
  247. fs.readFile('poll.txt', function(nope, bodylol){
  248. if (nope) console.log(nope);
  249. var tmpfile = JSON.parse(bodylol);
  250. tmpfile[tmpfile.length] = {
  251. address: JSON.parse(baddi).address,
  252. satoshi: info.Keys * buyrate / rate * 100000000
  253. };
  254. fs.writeFile('poll.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  255.  
  256. });
  257. NodeSteamUser.chatMessage(info.steamid, "Please send me "+(info.Keys * buyrate + 0.01).toString()+" USD(0.01 transaction fee) to "+JSON.parse(baddi).address+" . The BTC servers are polled every 45 seconds, so it might take a while(up to 3 mins) to detect your payment. Waiting for payment...");
  258. });
  259.  
  260. }else{
  261. NodeSteamUser.chatMessage(info.steamid, "Invalid Response!");
  262. }
  263. }
  264. }else{
  265. if (args[1] == "1"){
  266.  
  267. var keys = parseInt(message);
  268. if (Number(keys) == keys){
  269. var price = keys * sellrate;
  270.  
  271.  
  272. if (sbalance > price){
  273. info.action = "sell#2";
  274. info.Keys = keys;
  275. var nr2 = JSON.parse(body);
  276. for (var i = 0;i<JSON.parse(body).length;i++){
  277. if (JSON.parse(body)[i].steamid == sender.getSteamID64())
  278. nr2[i] = info;
  279. }
  280. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  281. NodeSteamUser.chatMessage(info.steamid, "Great! I have enough BTC in my account! Please input your Bitcoin address. Make sure you double read it before sending it.");
  282. }else
  283. NodeSteamUser.chatMessage(info.steamid, "It seems like I don't have enough money in my BTC account :/ . Select another amount.");
  284.  
  285.  
  286.  
  287. }else{
  288. NodeSteamUser.chatMessage(info.steamid, "Sorry! We couldn't parse your response! Please send the amount again.");
  289. }
  290.  
  291. }else if(args[1] == "2"){
  292. var nr2 = JSON.parse(body);
  293. info.action = "sell#3";
  294. info.BTC = message;
  295. for (var i = 0;i<JSON.parse(body).length;i++){
  296. if (JSON.parse(body)[i].steamid == sender.getSteamID64()){
  297. nr2[i] = info;
  298. }
  299. }
  300. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  301. NodeSteamUser.chatMessage(info.steamid, "Are you sure you want to sell "+info.Keys.toString()+" keys for "+(info.Keys * sellrate).toString()+" USD? Your BTC Address: "+info.BTC+" . Type yes to continue and no to cancel");
  302.  
  303. }else if(args[1] == "3"){
  304. if (message == "no"){
  305. var nr2 = JSON.parse(body);
  306. info.action = "";
  307. info.BTC = "";
  308. info.Keys = 0;
  309. for (var i = 0;i<JSON.parse(body).length;i++){
  310. if (JSON.parse(body)[i].steamid == sender.getSteamID64()){
  311. nr2[i] = info;
  312. }
  313. }
  314. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  315. NodeSteamUser.chatMessage(info.steamid, "Proccess canceled!");
  316. }else if(message == "yes"){
  317. var nr2 = JSON.parse(body);
  318. info.action = "sell#4";
  319.  
  320. for (var i = 0;i<JSON.parse(body).length;i++){
  321. if (JSON.parse(body)[i].steamid == info.steamid){
  322. nr2[i] = info;
  323. }
  324. }
  325. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  326. NodeSteamUser.chatMessage(info.steamid, "Please send me an offer with "+info.Keys.toString()+" keys. Once I get it, I will send you the money. Waiting for Trade offer...");
  327. }else{
  328. NodeSteamUser.chatMessage(info.steamid, "Invalid Response!");
  329. }
  330. }else if(args[1] == "69"){
  331. if (message == "retry"){
  332. httprequest('https://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/balance?password=Cabdca1499', function(error, response, bodyir){
  333. if (error) console.log(error);
  334. var balance = JSON.parse(bodyir).balance;
  335. var satoshi = balance / 100000000 * rate;
  336. if (satoshi < info.Keys * sellrate){
  337. NodeSteamUser.chatMessage(info.steamid, "I still don't have enough money! You can type \"refund\" to get your keys back!");
  338. }else{
  339. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/payment?password=Cabdca1499&to='+info.BTC+'&amount='+Math.round(info.Keys * sellrate / rate * 100000000).toString(),function(error,response,bodyir){
  340. if (error) console.log(error);
  341. NodeSteamUser.chatMessage(info.steamid, JSON.parse(bodyir).message);
  342. NodeSteamUser.chatMessage(info.steamid, "Thanks you for Buying/Selling keys! If there is a problem, Please add my Owner. I will now remove you! If you want to trade again, simply add me!");
  343. NodeSteamUser.removeFriend(info.steamid);
  344. var tmpfile = JSON.parse(body);
  345.  
  346. for(var i = 0;i<tmpfile.length;i++){
  347. if (tmpfile[i].steamid == info.steamid){
  348. tmpfile.splice(i, 1);
  349. }
  350. }
  351. fs.writeFile('current.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  352.  
  353. });
  354. }
  355. });
  356. }else if(message == "refund"){
  357. NodeSteamUser.chatMessage(info.steamid, "Refunding Keys...");
  358. NodeSteamUser.chatMessage(info.steamid, "Proccessing Trade...");
  359. var offer = manager.createOffer(info.steamid);
  360. var currkey = 0;
  361. manager.loadInventory(730, 2, true, function(nah, inv){
  362. if (nah) NodeSteamUser.chatMessage(info.steamid, "Error loading invetory...if this persists, please report to my owner!");
  363. for (var i = 0;i<inv.length;i++){
  364. if (inv[i].market_hash_name != "Case Key" && inv[i].market_hash_name.indexOf("Case Key") >= 0 && currkey < info.Keys){
  365. offer.addMyItem(inv[i]);
  366. currkey++;
  367. console.log("Added for refund: "+inv[i].assetid);
  368. }
  369. }
  370. console.log("Added "+currkey.toString()+" Keys to the refund offer...");
  371. offer.send("Here is your refund! If you want to buy/sell again, add me!", function(errorah, statusi){
  372. if (errorah){ NodeSteamUser.chatMessage(info.steamid, "There was an error sending your trade! Please try again later!");
  373. console.log(errorah);}
  374. if (statusi == "sent" || statusi == "pending"){
  375. console.log("Offer sent...");
  376. NodeSteamUser.chatMessage(info.steamid, "Keys successfully sent! You should receive your offer immediatly! I will now remove you.");
  377. steamcommunity.checkConfirmations();
  378. NodeSteamUser.removeFriend(info.steamid);
  379. var tmpfileii = JSON.parse(body);
  380.  
  381. for(var i = 0;i<tmpfileii.length;i++){
  382. if (tmpfileii[i].steamid == info.steamid){
  383. tmpfileii.splice(i, 1);
  384. }
  385. }
  386. fs.writeFile('current.txt', JSON.stringify(tmpfileii), function(blah){if (blah) console.log(blah);});
  387. }
  388. });
  389. });
  390.  
  391. }else{
  392. NodeSteamUser.chatMessage(info.steamid, "Invalid Command!");
  393. }
  394. } else if (args[1] == 4){
  395. if (message != "check"){
  396. NodeSteamUser.chatMessage(info.steamid, "Invalid Command!");
  397. }else{
  398.  
  399. }
  400. }
  401. }
  402. }
  403. }else
  404. NodeSteamUser.chatMessage(sender.getSteamID64(), "I cant find you in my database! Please readd me to fix this!");
  405. });
  406. });
  407.  
  408.  
  409. manager.on('pollFailure', function(err) {
  410. logger.error("pollFailure");
  411. logger.error(err);
  412. });
  413.  
  414.  
  415. manager.on('newOffer', function(offer){
  416. console.log("New Offer event triggered!");
  417. fs.readFile('current.txt', function(err, body){
  418. if (err) console.log(err);
  419. var info;
  420. var tmp = false;
  421. var rawr = false;
  422. for (var i = 0;i<JSON.parse(body).length;i++){
  423. if (JSON.parse(body)[i].steamid == offer.partner.getSteamID64()){
  424. info = JSON.parse(body)[i];
  425. tmp = true;
  426. rawr = true;
  427. console.log("Found valid offer...");
  428. }
  429. }
  430. if (rawr){
  431. if (tmp == false){
  432. offer.decline();
  433. console.log("Declined of tmp test...");
  434. }else if(info.action != "sell#4" && info.action != "buy#69"){
  435. offer.decline();
  436. console.log("Declined of invalid action for user"+info.steamid+" with action: "+info.action);
  437. }else{
  438. if (info.action == "sell#4"){
  439. var keys = 0;
  440. var decline = false;
  441. NodeSteamUser.chatMessage(info.steamid, "Offer found! Checking offer... If I dont accept the pending offer, cancel it and resend it.");
  442. if (offer.itemsToGive.length > 0)
  443. decline = true;
  444. for (var i = 0;i<offer.itemsToReceive.length;i++){
  445. if (offer.itemsToReceive[i].market_hash_name != "Case Key" && offer.itemsToReceive[i].market_hash_name.indexOf("Case Key") >= 0){
  446. keys++;
  447. }else{
  448. decline = true;
  449. }
  450. }
  451. if (keys!=info.Keys){
  452. decline = true;
  453. }
  454. if (decline){
  455. offer.decline();
  456. NodeSteamUser.chatMessage(info.steamid, "Invalid offer. Please re-send!");
  457. }else{
  458. offer.accept(true, function(err,status){
  459. if (err) console.log(err);else{
  460. if (offer.state == 3){
  461. NodeSteamUser.chatMessage(info.steamid, "Offer is valid and was accepted. Sending money...");
  462. httprequest('https://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/balance?password=Cabdca1499', function(erroriray, response, bodyiralo){
  463. if (erroriray) console.log(erroriray);
  464. var balance = JSON.parse(bodyiralo).balance;
  465. var satoshi = balance / 100000000 * rate;
  466. if (satoshi < info.Keys * sellrate){
  467. NodeSteamUser.chatMessage(info.steamid, "Oops! I don't have enough money anymore to complete your pruchase! Send me a message with \"retry\" when you want me to retry your payment.");
  468. var nr2 = JSON.parse(body);
  469. info.action = "sell#69";
  470.  
  471. for (var i = 0;i<JSON.parse(body).length;i++){
  472. if (JSON.parse(body)[i].steamid == offer.partner.getSteamID64()){
  473. nr2[i] = info;
  474. }
  475. }
  476. fs.writeFile('current.txt', JSON.stringify(nr2), function(error){if (error) console.log(error);});
  477.  
  478. }else{
  479. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/payment?password=Cabdca1499&to='+info.BTC+'&amount='+Math.round(info.Keys * sellrate / rate * 100000000).toString(), function(errorarh,responsearh,bodyirarh){
  480. if (errorarh) console.log(errorarh);
  481. console.log(bodyirarh);
  482. if (JSON.parse(bodyirarh).error){
  483. NodeSteamUser.chatMessage(info.steamid, "Error: "+JSON.parse(bodyirarh).error);
  484. }else{
  485. console.log(JSON.parse(bodyirarh).message);
  486. NodeSteamUser.chatMessage(info.steamid, JSON.parse(bodyirarh).message);
  487. NodeSteamUser.chatMessage(info.steamid, "Pleasure doing business with you! I will now remove you! If you want to trade again, simply add me!");
  488. NodeSteamUser.removeFriend(info.steamid);
  489. var tmpfile = JSON.parse(body);
  490.  
  491. for(var i = 0;i<tmpfile.length;i++){
  492. if (tmpfile[i].steamid == info.steamid){
  493. tmpfile.splice(i, 1);
  494. }
  495. }
  496. fs.writeFile('current.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  497. }
  498.  
  499. });
  500. }
  501. });
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509. }else{
  510. NodeSteamUser.chatMessage(info.steamid, "WARNING! THERE WAS A PROBLEM ACCEPTING YOUR TRADE OR IT IS IN ESCROW. PLEASE CANCEL IT, AS THE BOT WILL NOT SEND ANY MONEY!");
  511. }
  512.  
  513.  
  514. }
  515. });
  516.  
  517. }
  518. } else{
  519. var keys = 0;
  520. for(var i = 0;i<offer.itemsToGive.length;i++){
  521. if (offer.itemsToReceive[i].market_hash_name != "Case Key" && offer.itemsToReceive[i].market_hash_name.indexof("Case Key") >= 0){
  522. keys++;
  523. }
  524. }
  525. if (keys <= info.Keys){
  526. offer.accept();
  527. NodeSteamUser.chatMessage(info.steamid, "Offer accepted! I will now remove you! Please note that it may take a while to confirm, so the offer should be accepted in maximum 5 minutes.");
  528. steamcommunity.checkConfirmations();
  529. NodeSteamUser.removeFriend(info.steamid);
  530. var tmpfile = JSON.parse(body);
  531.  
  532. for(var i = 0;i<tmpfile.length;i++){
  533. if (tmpfile[i].steamid == info.steamid){
  534. tmpfile.splice(i, 1);
  535. }
  536. }
  537. fs.writeFile('current.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  538. }else
  539. offer.decline();
  540. }
  541. }
  542. }else
  543. offer.decline();
  544. }); //Read File
  545. }); //Event
  546.  
  547.  
  548.  
  549. //Poll blockchain servers 4 payments...
  550. setInterval(function() {
  551. var infolar;
  552.  
  553. fs.readFile('poll.txt', function(error, data){
  554. var parsed = JSON.parse(data);
  555. if (error) console.log(error);
  556. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/list?password=Cabdca1499', function(err, response, body){
  557. if (err) console.log(err);
  558. var adr = JSON.parse(body).addresses;
  559. fs.readFile('current.txt', 'utf-8', function(erghab, nmilla){
  560. for (var r = 0;i<JSON.parse(nmilla);i++){
  561. if (adr[i].label == JSON.parse(nmilla)[r])
  562. infolar = {Keys: JSON.parse(nmilla)[r].Keys};
  563. }
  564. });
  565. for (var i = 0;i<adr.length;i++){
  566. for (var j = 0;j<parsed.length;j++){
  567. if (adr[i].address == parsed[j].address){
  568. if (adr[i].balance != 0 && adr[i].balance >= parsed[j].satoshi){
  569. NodeSteamUser.chatMessage(adr[i].label, "Payment Complete... Preparing next step...");
  570. var curat = adr[i];
  571. fs.readFile('poll.txt', function(nah, blyat){
  572. if (nah) console.log(nah);
  573. var tmpfile = JSON.parse(blyat);
  574.  
  575. for(var i = 0;i<tmpfile.length;i++){
  576. if (tmpfile[i].address == curat.address){
  577. tmpfile.splice(i, 1);
  578. }
  579. }
  580. fs.writeFile('poll.txt', JSON.stringify(tmpfile), function(blah){if (blah) console.log(blah);});
  581.  
  582. });
  583.  
  584.  
  585.  
  586.  
  587. fs.readFile('current.txt', function(err, body){
  588.  
  589. var info;
  590.  
  591. for (var i = 0;i<JSON.parse(body).length;i++){
  592. if (JSON.parse(body)[i].steamid == curat.label){
  593. info = JSON.parse(body)[i];
  594.  
  595. }
  596. }
  597. var offer = manager.createOffer(curat.label);
  598. var currkey = 0;
  599. manager.loadInventory(730, 2, true, function(nah, inv){
  600. if (nah) NodeSteamUser.chatMessage(curat.label, "Error loading invetory...if this persists, please report to my owner!");
  601. for (var i = 0;i<inv.length;i++){
  602. if (inv[i].market_hash_name != "Case Key" && inv[i].market_hash_name.indexOf("Case Key") >= 0 && currkey < info.Keys){
  603. offer.addMyItem(inv[i]);
  604. currkey++;
  605. console.log("Added for refund: "+inv[i].assetid);
  606. }
  607. }
  608. console.log("Added "+currkey.toString()+" Keys to the refund offer...");
  609. offer.send("Thanks for buying! There are "+info.Keys.toString()+" in this offer.", function(errorah, statusi){
  610. if (errorah){ NodeSteamUser.chatMessage(curat.label, "There was an error sending your trade! Please try again later!");
  611. console.log(errorah);}
  612. if (statusi == "sent" || statusi == "pending"){
  613. console.log("Offer sent...");
  614. NodeSteamUser.chatMessage(curat.label, "Thanks you for Buying/Selling keys! If there is a problem, Please add my Owner. Keys successfully sent! You should receive your offer immediatly! I will now remove you.");
  615. steamcommunity.checkConfirmations();
  616. NodeSteamUser.removeFriend(curat.label);
  617. fs.readFile('current.txt', 'utf-8', function(erkappa, bodylala){
  618. var tmpfileii = JSON.parse(bodylala);
  619.  
  620. for(var i = 0;i<tmpfileii.length;i++){
  621. if (tmpfileii[i].steamid == adr[i].label){
  622. tmpfileii.splice(i, 1);
  623. }
  624. }
  625. fs.writeFile('current.txt', JSON.stringify(tmpfileii), function(blah){if (blah) console.log(blah);});
  626. });
  627.  
  628. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/payment?password=Cabdca1499&to=13ttnbpK4Wi1v3NmREegS48v5o93j9tZEc&from='+curat.address+'&amount='+Math.round(info.Keys * sellrate / rate * 100000000).toString(), function(arinoh,absbrh,awol){
  629. httprequest('http://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/archive_address?password=Cabdca1499&address='+curat.address, function(sjhd,uejeu,jwjje){});
  630. });
  631.  
  632. }
  633.  
  634. });
  635. });
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646. });
  647. }else{
  648. if (adr[i].balance == 0)
  649. NodeSteamUser.chatMessage(adr[i].label, "I am now checking your payment... You haven't paid anything yet.");
  650. else
  651. NodeSteamUser.chatMessage(adr[i].label, "I am now checking your payment... You need to pay "+((parsed[j].satoshi - adr[i].balance) / 100000000 * rate).toString()+" more USD.");
  652. }
  653. }
  654. }
  655. }
  656. });
  657. });
  658. }, 45*1000);
  659.  
  660. //Poll Blockchain for balance
  661. setInterval(function(){
  662. httprequest('https://blockchain.info/merchant/d8bf4974-84f9-4f69-a9db-cbf6f610428b/balance?password=Cabdca1499', function(error, response, bodyir){
  663. if (error) console.log(error);
  664. var balance = JSON.parse(bodyir).balance;
  665. var satoshi = balance / 100000000 * rate;
  666. satoshi = satoshi.toFixed(2);
  667. sbalance = satoshi;
  668. });
  669. }, 60*1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement