Advertisement
Guest User

Untitled

a guest
Apr 7th, 2018
1,994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.75 KB | None | 0 0
  1. const
  2. SteamUser = require('steam-user'),
  3. Helper = require('./helpers.js'),
  4. SteamCommunity = require('steamcommunity'),
  5. Inventory = require('./components/inventory.js'),
  6. CustomerHandler = require('./components/userhandler.js'),
  7. TradeOfferManager = require('steam-tradeoffer-manager'),
  8. config=Helper.getConfig(),
  9. rates=require('./data/rates.json'),
  10. msg=require('./data/messages.json'),
  11. helper = new Helper(),
  12. B = helper.breakline;
  13.  
  14. require('events').EventEmitter.defaultMaxListeners = 20;
  15.  
  16. let client = new SteamUser( { 'promptSteamGuardCode':false } ),
  17. profit,
  18. didLogin,
  19. LastLogin = {"client":0, "web":0},
  20. LastLoginTry = {"client":0, "web":0},
  21. community = new SteamCommunity(),
  22. manager = new TradeOfferManager({ "steam": client, "language": "en", "community":community, "pollInterval": "10000", "cancelTime": "7200000" }),
  23. inventory = new Inventory(community, client, config.enableTF, config.maxStock, helper),
  24. customer = new CustomerHandler(client, config.admin, config.maxDays, helper),
  25. timeouts = {},
  26. keyPrice = parseInt(rates.SetsPrice.split(':')[1]),
  27. keySets = parseInt(rates.SetsPrice.split(':')[0]),
  28. keyBuyPrice = parseInt(rates.BuyPrice.split(':')[1]),
  29. keyBuySets = parseInt(rates.BuyPrice.split(':')[0]),
  30. tfkeyPrice = parseInt(rates.TF2Price.split(':')[1]),
  31. tfkeySets = parseInt(rates.TF2Price.split(':')[0]),
  32. tfkeyBuyPrice = parseInt(rates.TF2BuyPrice.split(':')[1]),
  33. tfkeyBuySets = parseInt(rates.TF2BuyPrice.split(':')[0]),
  34. GemPrice = parseInt(rates.GemsPrice.split(':')[1]),
  35. GemSet = parseInt(rates.GemsPrice.split(':')[0]),
  36. GemBuyPrice = parseInt(rates.GemsBuyPrice.split(':')[1]),
  37. GemBuySet = parseInt(rates.GemsBuyPrice.split(':')[0]);
  38.  
  39. helper.getJSON('poll.json', data => { if(Object.keys(data).length){ manager.pollData=data; } } );
  40.  
  41. helper.getJSON('profit.json', data => { profit=data; } );
  42.  
  43. tryLogin();
  44.  
  45. function tryLogin(){
  46.  
  47. let type = client.client.loggedOn,
  48. lastl = !type ? LastLogin.client : LastLogin.web,
  49. lastlt = !type ? LastLoginTry.client : LastLoginTry.web,
  50. timeLimit = !type ? 1000*60*10 : 1000*5,
  51. tryLimit = !type ? 1000*2 : 1000*2;
  52.  
  53. const Now = helper.Now(),
  54. canTry = () => (Math.floor(Now - (lastlt+tryLimit)) > 0),
  55. canLogin = () => (Math.floor(Now - (lastl+timeLimit)) > 0),
  56. nextTry = () => {
  57. const val = Math.floor(Now - (lastlt+tryLimit));
  58. return val > 0 ? 1000 : (val)*-1;
  59. },
  60. nextLogin = () => {
  61. const val = Math.floor(Now - (lastl+timeLimit));
  62. return val > 0 ? 1000 : (val)*-1;
  63. };
  64.  
  65. if(type){
  66. if( canTry() ){
  67. LastLoginTry.web = Now;
  68. if( canLogin() ){
  69. if(client.client.loggedOn){
  70. client.setPersona(SteamUser.EPersonaState.Offline);
  71. client.webLogOn();
  72. } else {
  73. clearTimeout(timeouts['next_try']);
  74. timeouts['next_try'] = setTimeout(tryLogin, 1000);
  75. }
  76. } else {
  77. helper.warn(`Next weblogin in ${nextLogin()/1000} seconds.`);
  78. clearTimeout(timeouts['web_timeout']);
  79. timeouts['web_timeout'] = setTimeout(tryLogin, nextLogin());
  80. }
  81. } else {
  82. helper.debug(`Trying to weblogin again in ${nextTry()/1000} seconds.`);
  83. clearTimeout(timeouts['web_timeout']);
  84. timeouts['web_timeout'] = setTimeout(tryLogin, nextTry());
  85. }
  86. } else {
  87. if( canTry() ){
  88. LastLoginTry.client = Now;
  89. if( canLogin() ){
  90. login();
  91. } else {
  92. helper.warn(`Next login in ${nextLogin()/1000/60} minutes.`);
  93. clearTimeout(timeouts['d_timeout']);
  94. timeouts['d_timeout'] = setTimeout(tryLogin, nextLogin());
  95. }
  96. } else {
  97. helper.debug(`Trying to login again in ${nextTry()/1000} seconds.`);
  98. clearTimeout(timeouts['d_timeout']);
  99. timeouts['d_timeout'] = setTimeout(tryLogin, nextTry());
  100. }
  101. }
  102. }
  103.  
  104. function login(){
  105. if(!client.client.loggedOn){
  106. helper.log('Connecting to Steam..');
  107. if(didLogin){
  108. client.logOn(true);
  109. } else {
  110. client.logOn( helper.getLogOn( config.username, config.password ) );
  111. }
  112. }
  113. }
  114.  
  115. function Request(){
  116. helper.debug("#Auto Requester Fired");
  117. try {
  118. inventory.getCustomerSets(config.request_ignore, config.request_target, (err, sets) => {
  119. if(err){
  120. helper.warn("Failed to auto request sets, Error in get sets information!");
  121. } else {
  122. if(sets.length){
  123. let Request_Amount = Math.min.apply( Math, [ sets.length, config.request_qty ] ),
  124. toRequest=[],
  125. offer = manager.createOffer(config.request_tradelink);
  126.  
  127. for(let i=0;i<Request_Amount;i++){ toRequest.push(sets[i]); }
  128.  
  129. helper.debug(`#Found ${sets.length} sets, and requesting ${Request_Amount}.`);
  130.  
  131. offer.addTheirItems([].concat.apply([], toRequest));
  132. offer.data('SellInfo', 'admin');
  133.  
  134. offer.send( err => {
  135. if(err){
  136. helper.warn("Failed to auto request sets, Error in send offer!");
  137. } else {
  138. helper.debug(`#sucessfuly requested ${Request_Amount} sets!`);
  139. }
  140. } );
  141. } else {
  142. helper.debug("#Didn't find sets to requests.");
  143. }
  144. }
  145. });
  146. } catch (e) {
  147. helper.warn("Failed to auto request sets, maybe is something wrong in the config file..");
  148. }
  149. }
  150.  
  151. client.on('accountLimitations', (limited, communityBanned, locked) => {
  152. if(limited){
  153. helper.logError("This account is limited!", "Account error");
  154. client.logOff();
  155. }
  156. else if(communityBanned){
  157. helper.logError("This account is banned from community!", "Account error");
  158. client.logOff();
  159. }
  160. else if(locked){
  161. helper.logError("This account is locked!", "Account error");
  162. client.logOff();
  163. }
  164. });
  165.  
  166. client.on('loggedOn', () => {
  167. didLogin = true;
  168. if(config.changeBotName) {
  169. client.setPersona(SteamUser.EPersonaState.Online, config.changeBotName.replace("{csgo_rate}", `${keySets}:${keyPrice}`));
  170. } else {
  171. client.setPersona(SteamUser.EPersonaState.Online);
  172. }
  173. LastLogin.client = helper.Now();
  174. inventory.ID64 = client.steamID.getSteamID64();
  175. helper.log("Conecting to SteamCommunity..");
  176. });
  177.  
  178. client.on('groupRelationship', (sid, relationship) => { if(relationship == SteamUser.EClanRelationship.Invited){ client.respondToGroupInvite(sid, false); } });
  179.  
  180. client.on('steamGuard', (domain, callback) => { helper.getCode(config.sharedse, code => { callback(code); }); });
  181.  
  182. client.on('webSession', (sessionID, newCookie) => {
  183. LastLogin.web = helper.Now();
  184. helper.debug("webLogOn");
  185. if(inventory.card_db){
  186. loadmanager(newCookie);
  187. } else {
  188. helper.log("Loading sets Database..");
  189. helper.updateTradingCardDb( data => { if(data){ inventory.card_db = data; loadmanager(newCookie);} } );
  190. }
  191. });
  192.  
  193. function loadmanager(newCookie){
  194. if(!LastLoginTry.web){ helper.log('Loading APIKey..'); }
  195. manager.setCookies(newCookie, err => {
  196. if(err){
  197. helper.logError(err.message, "Fatal error");
  198. } else {
  199. if(!LastLoginTry.web){
  200. helper.log(`Got APIKey: ${manager.apiKey}`);
  201. if(config.request_enable){
  202. helper.debug(`#Auto requester started!, Interval: ${config.request_interval} minutes.`);
  203. clearInterval(timeouts['requester_interval']);
  204. if(config.request_interval > 30){
  205. helper.warn(`A big interval time in auto requester may cause errors!`);
  206. }
  207. timeouts['requester_interval'] = setInterval( () => { Request(); }, 1000*60*config.request_interval);
  208. }
  209. }
  210. inventory.apiKey = manager.apiKey;
  211. community.startConfirmationChecker(20000, config.identity);
  212. inventory.Load(0, () => { online(); });
  213. clearInterval(timeouts['CheckL_i']);
  214. timeouts['CheckL_i'] = setInterval(checkSteamLogged, 1000*60*4);
  215. }
  216. });
  217. }
  218.  
  219. client.on('disconnected', () => { helper.log("Bot Disconnected!"); });
  220.  
  221. community.on('sessionExpired', () => { helper.warn("Session expired!"); tryLogin(); });
  222.  
  223. //process.on("uncaughtException", (err) => { console.log(err); process.exit(1); });
  224.  
  225. community.on('confirmationAccepted', conf => {
  226. helper.debug(`confirmationAccepted type ${conf.type} triggered #${conf.id}`);
  227. if(conf.type == 2){
  228. helper.debug(`Searching for details of #${conf.creator}`);
  229. manager.getOffer(conf.creator, (err, myOffer) => {
  230. if(err){
  231. helper.logError(err.message, 'confirmationAccepted');
  232. } else {
  233. if(myOffer.isOurOffer){
  234. let response = msg.OfferSent;
  235. response += B+msg.OfferSent2.replace("{url}", `https://steamcommunity.com/tradeoffer/${conf.creator}`);
  236. customer.Message(myOffer.partner, response);
  237. helper.logTrade(`Successfully sent a trade offer for ${myOffer.partner}`);
  238. } else {
  239. helper.debug(`#${conf.creator} with confirmation id #${conf.id} isn't a trade offer sended by bot.`);
  240. }
  241. }
  242. });
  243. }
  244. });
  245.  
  246. function checkFriendRequests(){ for(let user in client.myFriends){ if(client.myFriends[user] == 2){ addFriend(user); } } }
  247.  
  248. function addFriend(user){
  249. client.addFriend(user, (err, result) => {
  250. if(err){
  251. helper.warn(`Failed to accept user #${user} friend request!: ${err.message}`);
  252. } else {
  253. //inviteToGroup(user);
  254. customer.Message(user, msg.Welcome.replace("{customer_name}", result));
  255. customer.UserInteract(user, 0);
  256. }
  257. });
  258. }
  259.  
  260. function checkSteamLogged() {
  261. community.loggedIn( (err, loggedIn) => {
  262. if (err) {
  263. helper.logError(err.message, 'checkSteamLogged');
  264. if(err.message.indexOf("socket hang up") > -1 || err.message.indexOf("ESOCKETTIMEDOUT") > -1){
  265. tryLogin();
  266. } else {
  267. clearTimeout(timeouts['check_steam_logged']);
  268. timeouts['check_steam_logged'] = setTimeout(checkSteamLogged, 1000*10);
  269. }
  270. } else if ( ! loggedIn ) {
  271. helper.debug("WebLogin check : NOT LOGGED IN !");
  272. tryLogin();
  273. } else {
  274. helper.debug("WebLogin check : LOGGED IN !");
  275. client.setPersona(SteamUser.EPersonaState.LookingToTrade);
  276. }
  277. });
  278. }
  279.  
  280. manager.on('pollData', pollData => { helper.storeData('poll.json', pollData, 1); });
  281.  
  282. manager.on('pollFailure', err => { helper.debug("pollFailure: "+err); tryLogin(); });
  283.  
  284. client.on('error', e => {
  285. helper.logError(e.message.replace("RateLimitExceeded", "Temporary rate limit exceeded"), "Fatal error");
  286. if(!didLogin){
  287. LastLogin.client = helper.Now();
  288. }
  289. tryLogin();
  290. });
  291.  
  292. function inviteToGroup(target){ if(config.group){ community.inviteUserToGroup(target, config.group); } }
  293.  
  294. function makeOffer(target, itemsFromMe, itemsFromThem, details, type, currency){
  295. helper.debug(`Creating trade offer for #${target} with ${itemsFromMe.length} items to send and ${itemsFromThem.length} items to receive`);
  296. try {
  297. const
  298. offer = manager.createOffer(target),
  299. addMyItemsCount = offer.addMyItems(itemsFromMe),
  300. addTheirItemsCount = offer.addTheirItems(itemsFromThem);
  301. offer.data('SellInfo', details);
  302. offer.data('SellInfoType', type);
  303. offer.data('SellInfoCurrency', currency);
  304. offer.getUserDetails( (err, me, them) => {
  305. if(err){
  306. if(err.message.toLowerCase().indexOf("is not available to trade. more information will be") > -1){
  307. customer.Message(target, msg.Trade_error1);
  308. helper.logTrade(`#${target} is unavailable to trade`);
  309. } else { helper.logError(err.message, 'offer.getUserDetails'); }
  310. } else {
  311. if(them.escrowDays){
  312. customer.Message(target, msg.Trade_hold);
  313. } else {
  314. helper.debug(`Sending offer for #${target}`);
  315. offer.send( (err, status) => {
  316. helper.debug(`Offer #${offer.id} status: ${status}, err: ${err}`);
  317. if (err){
  318. if(err.message.toLowerCase().indexOf("sent too many trade offers") > 1){
  319. customer.Message(target, msg.Trade_error2);
  320. } else if(err.message.toLowerCase().indexOf("please try again later. (26)") > 1){
  321. helper.warn("Error 26", 'offer.send');
  322. customer.Message(target, msg.Trade_error);
  323. } else {
  324. helper.logError(err.message, 'offer.send');
  325. customer.Message(target, msg.Trade_error);
  326. }
  327. } else {
  328. manager.getOffer(offer.id, (err, myOffer) => {
  329. if(err){
  330. helper.logError(err.message, 'manager.getOffer');
  331. customer.Message(target, msg.Trade_error);
  332. if(err.message.indexOf("socket hang up") > -1 || err.message.indexOf("ESOCKETTIMEDOUT") > -1){
  333. tryLogin();
  334. }
  335. } else {
  336. if(addMyItemsCount != myOffer.itemsToGive.length){
  337. helper.logError('Cant add itemsFromMe, some item is missing in my inventory!', 'manager.getOffer');
  338. customer.Message(target, msg.Trade_error);
  339. myOffer.cancel();
  340. } else if(addTheirItemsCount != myOffer.itemsToReceive.length){
  341. helper.logError('Cant add itemsFromThem, some item is missing in my inventory!', 'manager.getOffer');
  342. customer.Message(target, msg.Trade_error);
  343. myOffer.cancel();
  344. } else if (status == 'pending') {
  345. community.checkConfirmations();
  346. } else {
  347. let response = msg.OfferSent;
  348. response += B+msg.OfferSent2.replace("{url}", `https://steamcommunity.com/tradeoffer/${offer.id}`);
  349. customer.Message(target, response);
  350. helper.logTrade(`Successfully sent a trade offer for ${target}`);
  351. }
  352. }
  353. });
  354. }
  355. });
  356. }
  357. }
  358. });
  359. } catch(e) {
  360. customer.Message(target, msg.Trade_error);
  361. }
  362.  
  363. }
  364.  
  365. function playPrices(){
  366. let play = msg.play.replace("{have_sets}", helper.nFormat(inventory.haveSets())).replace("{csgo_rate}", `${keySets}:${keyPrice}`).replace("{gems_rate}", `${GemSet}:${GemPrice}`);
  367. if(inventory.enableTF){ play += msg.play2.replace("{tf_rate}", `${tfkeySets}:${tfkeyPrice}`); }
  368. client.gamesPlayed(play, true);
  369. }
  370.  
  371. function online(){ client.setPersona(SteamUser.EPersonaState.LookingToTrade); playPrices(); checkFriendRequests(); }
  372.  
  373. manager.on('newOffer', offer => {
  374. let partner = offer.partner.getSteamID64();
  375. if(config.admin.indexOf(partner) > -1){
  376. helper.logTrade(`New offer from admin #${partner}`);
  377. offer.accept( (err, res) => {
  378. if(err) {
  379. helper.warn("Unable to accept admin offer: " + err.message);
  380. }
  381. else {
  382. if(res == "pending"){
  383. helper.logTrade("Accepting admin offer..");
  384. community.checkConfirmations();
  385. } else {
  386. helper.logTrade("Admin Offer accepeted!");
  387. }
  388. }
  389. });
  390. }
  391. });
  392.  
  393. manager.on('receivedOfferChanged', (offer, oldState) => {
  394. helper.debug(`receivedOfferChanged Triggered at #${offer.id}, state: ${offer.state}, oldState: ${oldState}`);
  395. if(offer.state == 3 && customer.finishedTrades[offer.id] == null){
  396. customer.finishedTrades[offer.id] = new Date().getTime();
  397.  
  398. inventory.Load(1, () => {playPrices();client.setPersona(SteamUser.EPersonaState.LookingToTrade);});
  399. }
  400. });
  401.  
  402. manager.on('sentOfferChanged', (offer, oldState) => {
  403. helper.debug(`sentOfferChanged Triggered at #${offer.id}, state: ${offer.state}, oldState: ${oldState}`);
  404. if(offer.state == 3 && customer.finishedTrades[offer.id] == null){
  405. customer.finishedTrades[offer.id] = new Date().getTime();
  406.  
  407. inventory.Load(1, () => {playPrices();client.setPersona(SteamUser.EPersonaState.LookingToTrade);});
  408.  
  409. if(config.ThanksM && offer.data('SellInfo') != 'admin'){
  410. customer.canComment(offer.partner.getSteamID64(), canComment => {
  411. if(canComment){ community.postUserComment(offer.partner.getSteamID64(), config.ThanksM, err =>{
  412. if(!err){ customer.UserInteract(offer.partner.getSteamID64(), 1); }
  413. });
  414. }
  415. });
  416. customer.Message(offer.partner, msg.Thanks);
  417. }
  418. inviteToGroup(offer.partner.getSteamID64());
  419. if(offer.data('SellInfoType') != null){
  420. if(offer.data('SellInfoType') == 0){
  421. if(offer.data('SellInfoCurrency') == "tf key(s)"){ profit.sell.tf.sets = parseInt(profit.sell.tf.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.sell.tf.currency = parseInt(profit.sell.tf.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  422. if(offer.data('SellInfoCurrency') == "key(s)"){ profit.sell.csgo.sets = parseInt(profit.sell.csgo.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.sell.csgo.currency = parseInt(profit.sell.csgo.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  423. if(offer.data('SellInfoCurrency') == "gems"){ profit.sell.gems.sets = parseInt(profit.sell.gems.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.sell.gems.currency = parseInt(profit.sell.gems.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  424. helper.storeData('profit.json', profit, 1);
  425. helper.logTrade(`${offer.partner.getSteamID64()} have accepted an trade offer!, i have selled ${offer.data('SellInfo').split(":")[0]} set(s) for ${offer.data('SellInfo').split(":")[1]} ${offer.data('SellInfoCurrency')}!`);
  426. if(config.sellmsgs){
  427. customer.sendAdminMessages(`Hey!, i just have selled ${offer.data('SellInfo').split(":")[0]} Set(s) for ${offer.data('SellInfo').split(":")[1]} ${offer.data('SellInfoCurrency')}!`);
  428. }
  429. } else if(offer.data('SellInfoType') == 1){
  430. if(offer.data('SellInfoCurrency') == "tf key(s)"){ profit.buy.tf.sets = parseInt(profit.buy.tf.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.buy.tf.currency = parseInt(profit.buy.tf.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  431. if(offer.data('SellInfoCurrency') == "key(s)"){ profit.buy.csgo.sets = parseInt(profit.buy.csgo.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.buy.csgo.currency = parseInt(profit.buy.csgo.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  432. if(offer.data('SellInfoCurrency') == "gems"){ profit.buy.gems.sets = parseInt(profit.buy.gems.sets)+parseInt(offer.data('SellInfo').split(":")[0]); profit.buy.gems.currency = parseInt(profit.buy.gems.currency)+parseInt(offer.data('SellInfo').split(":")[1]);}
  433. helper.logTrade(`${offer.partner.getSteamID64()} have accepted an trade offer!, i have buyed ${offer.data('SellInfo').split(":")[0]} sets for ${offer.data('SellInfo').split(":")[1]} ${offer.data('SellInfoCurrency')}!`);
  434. if(config.sellmsgs){
  435. customer.sendAdminMessages(`Hey!, i just have buyed ${offer.data('SellInfo').split(":")[0]} Set(s) for ${offer.data('SellInfo').split(":")[1]} ${offer.data('SellInfoCurrency')}!`);
  436. }
  437. }
  438. }
  439. }
  440. });
  441.  
  442. function gemswithdraw (admin, qty){
  443. let InventoryGems = inventory.return_GemsQty();
  444. customer.Message(admin, msg.OwnerRequest);
  445. if(InventoryGems){
  446. if(InventoryGems >= qty) {
  447. inventory.getGems(qty, toGive => {
  448. makeOffer(admin, toGive, [], 'admin');
  449. });
  450. } else {
  451. customer.Message(admin, msg.Sorryme.replace("{currency_qty}", helper.nFormat(InventoryGems)).replace("{currency_name}", "gems").replace("{command}", "!gemswithdraw").replace("{command_qty}", InventoryGems));
  452. }
  453. } else {
  454. customer.Message(admin, msg.Sorryme2.replace("{currency_name}", "gems"))
  455. }
  456. }
  457.  
  458. function tfwithdraw (admin, qty){
  459. customer.Message(admin, msg.OwnerRequest);
  460. let Tf_keys = inventory.haveTfKeys();
  461. if(Tf_keys){
  462. if(Tf_keys >= qty){
  463. inventory.getToOffer_TF_Keys(qty, send => {
  464. makeOffer(admin, send, [], 'admin');
  465. });
  466. } else {
  467. customer.Message(admin, msg.Sorryme.replace("{currency_qty}", Tf_keys).replace("{currency_name}", "tf keys").replace("{command}", "!tfwithdraw").replace("{command_qty}", Tf_keys));
  468. }
  469. } else {
  470. customer.Message(admin, msg.Sorryme2.replace("{currency_name}", "tf keys"));
  471. }
  472. }
  473.  
  474. function withdraw (admin, qty){
  475. customer.Message(admin, msg.OwnerRequest);
  476. let user_keys = inventory.haveCsKeys();
  477. if(user_keys){
  478. if(user_keys >= qty){
  479. inventory.getToOffer_CS_Keys(qty, send => {
  480. makeOffer(admin, send, [], 'admin');
  481. });
  482. } else {
  483. customer.Message(admin, msg.Sorryme.replace("{currency_qty}", user_keys).replace("{currency_name}", "cs:go keys").replace("{command}", "!withdraw").replace("{command_qty}", user_keys));
  484. }
  485. } else {
  486. customer.Message(admin, msg.Sorryme2.replace("{currency_name}", "cs:go keys"));
  487. }
  488.  
  489. }
  490.  
  491. function tfdeposit(admin, qty){
  492. customer.Message(admin, msg.OwnerRequest);
  493. inventory.return_CustomerTFKeys(admin, (err, keys) => {
  494. if(err){
  495. handleInventoryErrors(err, admin);
  496. } else {
  497. let user_keys = keys.length;
  498. if(user_keys){
  499. if(user_keys >= qty){
  500. inventory.getToOfferKeys(keys, qty, 440, toReceive => {
  501. makeOffer(admin, [], toReceive, 'admin');
  502. });
  503. } else {
  504. customer.Message(admin, msg.Sorrythem.replace("{currency_qty}", user_keys).replace("{currency_name}", "tf keys").replace("{command}", "!tfdeposit").replace("{command_qty}", user_keys));
  505. }
  506. } else {
  507. customer.Message(admin, msg.Sorrythem2.replace("{currency_name}", "tf keys"));
  508. }
  509. }
  510. });
  511. }
  512.  
  513. function deposit(admin, qty){
  514. customer.Message(admin, msg.OwnerRequest);
  515. inventory.return_CustomerCSGOKeys(admin, (err, keys) => {
  516. if(err){
  517. handleInventoryErrors(err, admin);
  518. } else {
  519. let user_keys = keys.length;
  520. if(user_keys){
  521. if(user_keys >= qty){
  522. inventory.getToOfferKeys(keys, qty, 730, toReceive => {
  523. makeOffer(admin, [], toReceive, 'admin');
  524. });
  525. } else {
  526. customer.Message(admin, msg.Sorrythem.replace("{currency_qty}", user_keys).replace("{currency_name}", "cs:go keys").replace("{command}", "!deposit").replace("{command_qty}", user_keys));
  527. }
  528. } else {
  529. customer.Message(admin, msg.Sorrythem2.replace("{currency_name}", "cs:go keys"));
  530. }
  531. }
  532. });
  533. }
  534.  
  535. function depositgems(admin, qty){
  536. customer.Message(admin, msg.OwnerRequest);
  537. inventory.getCustomerGemAssets(admin, (err, Gems_Assets, Gems_Qty) => {
  538. if(err){
  539. handleInventoryErrors(err, admin);
  540. } else {
  541. if(Gems_Qty){
  542. if(Gems_Qty >= qty){
  543. inventory.getCustomerGems(Gems_Assets, qty, toReceive => {
  544. makeOffer(admin, [], toReceive, 'admin');
  545. });
  546. } else {
  547. customer.Message(admin, msg.Sorrythem.replace("{currency_qty}", Gems_Qty).replace("{currency_name}", "gems").replace("{command}", "!depositgems").replace("{command_qty}", Gems_Qty));
  548. }
  549. } else {
  550. customer.Message(admin, msg.Sorrythem2.replace("{currency_name}", "gems"));
  551. }
  552. }
  553. });
  554. }
  555.  
  556. function check(source){
  557. if(inventory.haveSets()) {
  558. customer.Message(source, msg.CustomerRequest);
  559. inventory.getUserBadges(source, 1, 5, (err, badge) => {
  560. if(err){
  561. handleBadgeErrors(err, source);
  562. } else {
  563. let Qty=0;
  564.  
  565. for(let appid in inventory.AvailableSets){
  566. Qty += Math.min.apply( Math, [ inventory.AvailableSets[appid].length, (badge[appid] != null ? badge[appid] : 5 ) ] );
  567. }
  568.  
  569. if(Qty){
  570. let response = msg.Check.replace("{have_sets}", helper.nFormat(Qty)).replace("{csgo_price}", ((Qty/keySets)*keyPrice).toFixed(1)).replace("{gems_price}", helper.nFormat(Math.round(Qty/GemSet)*GemPrice));
  571. if(inventory.enableTF){ response += msg.Check2.replace("{tf_price}", ((Qty/tfkeySets)*tfkeyPrice).toFixed(1));}
  572.  
  573. response += B+msg.Check_i.replace("{buy_qty}", parseInt(Qty/keySets)*keyPrice).replace("{buygems_qty}", Qty);
  574. if(inventory.enableTF){ response += msg.Check_i2.replace("{buytf_qty}", parseInt(Qty/tfkeySets)*tfkeyPrice);}
  575. if(inventory.haveCsKeys() && config.enableSell){ response += B+msg.Sell_keys; }
  576. customer.Message(source, response);
  577. } else {
  578. let response = msg.Donthave;
  579. if(inventory.haveCsKeys() && config.enableSell){ response += B+msg.Sell_keys; }
  580. customer.Message(source, response);
  581. }
  582. }
  583. });
  584.  
  585. } else {
  586. let response = msg.Donthave;
  587. if(inventory.haveCsKeys() && config.enableSell){ response += B+msg.Sell_keys; }
  588. customer.Message(source, response);
  589. }
  590. }
  591.  
  592. function buy(source, qty, compare, mode){
  593. customer.Message(source, msg.CustomerRequest);
  594. inventory.return_CustomerCSGOKeys(source, (err, KeysFromThemAsset) => {
  595. if(err){
  596. handleInventoryErrors(err, source);
  597. } else {
  598. let user_keys = KeysFromThemAsset.length;
  599. if(user_keys){
  600. let need = keyPrice*qty,
  601. set_need = keySets*qty;
  602. if(user_keys >= need){
  603. inventory.getAvailableSetsForCustomer(source, compare, mode, set_need, (err, toSend) => {
  604. if(err){
  605. handleBadgeErrors(err, source);
  606. } else {
  607. if(toSend.length == set_need){
  608. inventory.getToOfferKeys(KeysFromThemAsset, need, 730, toReceive => {
  609. makeOffer(source, [].concat.apply([], toSend), toReceive, `${set_need}:${need}`, 0, "key(s)");
  610. });
  611. } else {
  612. customer.Message(source, msg.i_need.replace("{currency_qty}", toSend.length).replace("{currency}", "sets").replace("{needed}", set_need));
  613. }
  614. }
  615. });
  616. } else {
  617. customer.Message(source, msg.them_need.replace("{currency_qty}", user_keys).replace("{currency}", "cs:go keys").replace("{needed}", need));
  618. }
  619. } else {
  620. customer.Message(source, msg.Sorrythem2.replace("{currency_name}", "cs:go keys"));
  621. }
  622. }
  623. });
  624. }
  625.  
  626. function buytf(source, qty, compare, mode){
  627. customer.Message(source, msg.CustomerRequest);
  628. inventory.return_CustomerTFKeys(source, (err, KeysFromThemAsset) => {
  629. if(err){
  630. handleInventoryErrors(err, source);
  631. } else {
  632. let user_keys = KeysFromThemAsset.length;
  633. if(user_keys){
  634. let need = tfkeyPrice*qty;
  635. let set_need = tfkeySets*qty;
  636. if(user_keys >= need){
  637. inventory.getAvailableSetsForCustomer(source, compare, mode, set_need, (err, toSend) => {
  638. if(err){
  639. handleBadgeErrors(err, source);
  640. } else {
  641. if(toSend.length == set_need){
  642. inventory.getToOfferKeys(KeysFromThemAsset, need, 440, toReceive => {
  643. makeOffer(source, [].concat.apply([], toSend), toReceive, `${set_need}:${need}`, 0, "tf key(s)");
  644. });
  645. } else {
  646. customer.Message(source, msg.i_need.replace("{currency_qty}", toSend.length).replace("{currency}", "sets").replace("{needed}", set_need));
  647. }
  648. }
  649. });
  650. } else {
  651. customer.Message(source, msg.them_need.replace("{currency_qty}", user_keys).replace("{currency}", "tf keys").replace("{needed}", need));
  652. }
  653. } else {
  654. customer.Message(source, msg.Sorrythem2.replace("{currency_name}", "tf keys"));
  655. }
  656. }
  657. });
  658. }
  659.  
  660. function buygems(source, qty, compare, mode){
  661. customer.Message(source, msg.CustomerRequest);
  662. inventory.getCustomerGemAssets(source, (err, Gems_Assets, Gems_Qty) => {
  663. if(err){
  664. handleInventoryErrors(err, source);
  665. } else {
  666. let need = GemPrice*qty;
  667. let set_need = GemSet*qty;
  668. if(Gems_Qty){
  669. if(Gems_Qty >= need){
  670. inventory.getAvailableSetsForCustomer(source, compare, mode, set_need, (err, toSend) => {
  671. if(err){
  672. handleBadgeErrors(err, source);
  673. } else {
  674. if(toSend.length == set_need){
  675. inventory.getCustomerGems(Gems_Assets, need, toReceive => {
  676. makeOffer(source, [].concat.apply([], toSend), toReceive, `${set_need}:${need}`, 0, "gems");
  677. });
  678. } else {
  679. customer.Message(source, msg.i_need.replace("{currency_qty}", toSend.length).replace("{currency}", "sets").replace("{needed}", set_need));
  680. }
  681. }
  682. });
  683. } else {
  684. customer.Message(source, msg.them_need.replace("{currency_qty}", Gems_Qty).replace("{currency}", "gems").replace("{needed}", need));
  685. }
  686. } else {
  687. customer.Message(source, msg.Sorrythem2.replace("{currency_name}", "gems"));
  688. }
  689. }
  690. });
  691. }
  692.  
  693. function checkam(source, amount, type, callback){
  694. customer.Message(source, msg.CustomerRequest);
  695. inventory.getUserBadges(source, 0, 0, (err, badge, player_level, player_xp) => {
  696. if(err){
  697. handleBadgeErrors(err, source);
  698. } else {
  699. let xpWon=(type ? keySets/keyPrice : tfkeySets/tfkeyPrice)*100*amount;
  700.  
  701. let totalExp=player_xp+xpWon;
  702.  
  703. let i=player_level-1;
  704. let can=0;
  705. do {
  706. i++;
  707. if(i > config.maxLevelComm){
  708. let response = `I'm not allowed to calculate level above than ${config.maxLevelComm} :/`;
  709. response += `${B}Sorry but can you try a lower level?`;
  710. customer.Message(source, response);
  711. can++;
  712. break;
  713. }
  714. }
  715. while (totalExp-helper.getLevelExp(i) > 0);
  716. if(!can){
  717. callback(player_level, i);
  718. }
  719. }
  720. });
  721. }
  722.  
  723. function checkgam(source, amount, callback){
  724. customer.Message(source, msg.CustomerRequest);
  725. inventory.getUserBadges(source, 0, 0, (err, badge, player_level, player_xp) => {
  726. if(err){
  727. handleBadgeErrors(err, source);
  728. } else {
  729. let xpWon=(GemSet/GemPrice)*100*amount;
  730.  
  731. let totalExp=player_xp+xpWon;
  732.  
  733. let i=parseInt(player_level)-1;
  734. let can=0;
  735. do {
  736. i++;
  737. if(i > config.maxLevelComm){
  738. let response = `I'm not allowed to calculate level above than ${config.maxLevelComm} :/`;
  739. response += `${B}Sorry but can you try a lower level?`;
  740. customer.Message(source, response);
  741. can++;
  742. break;
  743. }
  744. }
  745. while (totalExp-helper.getLevelExp(i) > 0);
  746. if(!can){
  747. callback(player_level, i);
  748. }
  749. }
  750. });
  751. }
  752.  
  753. function sell(source, keys){
  754. if(inventory.haveCsKeys()){
  755. if(inventory.haveCsKeys() >= keys){
  756. customer.Message(source, msg.CustomerRequest);
  757. inventory.getCustomerSets(false, source, (err, customer_sets) => {
  758. if(err){
  759. handleInventoryErrors(err, source);
  760. } else {
  761. let requested_sets=parseInt((keys/keyBuyPrice)*keyBuySets);
  762. if(customer_sets.length > 0){
  763. if(customer_sets.length >= requested_sets){
  764. customer.Message(source, msg.SendingOffer);
  765. inventory.getToOfferSets(customer_sets, requested_sets, toRequest => {
  766. inventory.getToOffer_CS_Keys(keys, toSend => {
  767. makeOffer(source, toSend, [].concat.apply([], toRequest), `${requested_sets}:${keys}`, 1, "key(s)");
  768. });
  769. });
  770. } else {
  771. customer.Message(source, msg.them_need.replace("{currency_qty}", +customer_sets.length).replace("{currency}", "sets").replace("{needed}", requested_sets));
  772. }
  773. } else {
  774. customer.Message(source, msg.ThemDonthave);
  775. }
  776. }
  777. });
  778. } else {
  779. customer.Message(source, msg.i_need.replace("{currency_qty}", inventory.haveCsKeys()).replace("{currency}", "cs:go keys").replace("{needed}", keys));
  780. }
  781. } else {
  782. customer.Message(source, msg.Sorryme2.replace("{currency_name}", "cs:go keys"))
  783. }
  784. }
  785.  
  786. function sellgems(source, sets){
  787. let GemsQty = inventory.return_GemsQty();
  788. if(GemsQty){
  789. let need = GemBuyPrice*sets;
  790. if(GemsQty >= need){
  791. customer.Message(source, msg.CustomerRequest);
  792. inventory.getCustomerSets(false, source, (err, customer_sets) => {
  793. if(err){
  794. handleInventoryErrors(err, source);
  795. } else {
  796. if(customer_sets.length > 0){
  797. if(customer_sets.length >= sets){
  798. customer.Message(source, msg.SendingOffer);
  799. inventory.getToOfferSets(customer_sets, sets, toRequest => {
  800. inventory.getGems(need, toSend => {
  801. makeOffer(source, toSend, [].concat.apply([], toRequest), `${sets}:${need}`, 1, "gems");
  802. });
  803. });
  804. } else {
  805. customer.Message(source, msg.them_need.replace("{currency_qty}", +customer_sets.length).replace("{currency}", "sets").replace("{needed}", sets));
  806. }
  807. } else {
  808. customer.Message(source, msg.ThemDonthave);
  809. }
  810. }
  811. });
  812. } else {
  813. customer.Message(source, msg.i_need.replace("{currency_qty}", GemsQty).replace("{currency}", "gems").replace("{needed}", need));
  814. }
  815. } else {
  816. customer.Message(source, msg.Sorryme2.replace("{currency_name}", "gems"))
  817. }
  818. }
  819.  
  820. function selltf(source, keys){
  821. if(inventory.haveTfKeys()){
  822. if(inventory.haveTfKeys() >= keys){
  823. customer.Message(source, msg.CustomerRequest);
  824. inventory.getCustomerSets(false, source, (err, customer_sets) => {
  825. if(err){
  826. handleInventoryErrors(err, source);
  827. } else {
  828. let requested_sets=parseInt((keys/tfkeyBuyPrice)*tfkeyBuySets);
  829. if(customer_sets.length > 0){
  830. if(customer_sets.length >= requested_sets){
  831. customer.Message(source, msg.SendingOffer);
  832. inventory.getToOfferSets(customer_sets, requested_sets, toRequest => {
  833. inventory.getToOffer_TF_Keys(keys, toSend => {
  834. makeOffer(source, toSend, [].concat.apply([], toRequest), `${requested_sets}:${keys}`, 1, "tf key(s)");
  835. });
  836. });
  837. } else {
  838. customer.Message(source, msg.them_need.replace("{currency_qty}", +customer_sets.length).replace("{currency}", "sets").replace("{needed}", requested_sets));
  839. }
  840. } else {
  841. customer.Message(source, msg.ThemDonthave);
  842. }
  843. }
  844. });
  845. } else {
  846. customer.Message(source, msg.i_need.replace("{currency_qty}", inventory.haveTfKeys()).replace("{currency}", "tf keys").replace("{needed}", keys));
  847. }
  848. } else {
  849. customer.Message(source, msg.Sorryme2.replace("{currency_name}", "tf keys"))
  850. }
  851. }
  852.  
  853. function sellcheck(source){
  854. customer.Message(source, msg.CustomerRequest);
  855. inventory.getCustomerSets(false, source, (err, customer_sets) => {
  856. if(err){
  857. handleInventoryErrors(err, source);
  858. } else {
  859. let cansell=customer_sets.length;
  860. if(cansell > 0){
  861. let response = msg.SellCheck.replace("{amount}", cansell);
  862. response += B+msg.SellCheck2.replace("{csgokeys_amount}", parseInt((cansell/keyBuySets)*keyBuyPrice)).replace("{csgosets_amount}", (keyBuySets/keyBuyPrice)*parseInt((cansell/keyBuySets)*keyBuyPrice)).replace("{gems_amount}", helper.nFormat((cansell/GemBuySet)*GemBuyPrice)).replace("{gemsets_amount}", cansell);
  863. if(inventory.enableTF){
  864. response += msg.SellCheck3.replace("{tfkeys_amount}", parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice)).replace("{tfsets_amount}", (tfkeyBuySets/tfkeyBuyPrice)*parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice));
  865. }
  866. response += B+msg.SellCheck_i.replace("{sell_qty}", parseInt((cansell/keyBuySets)*keyBuyPrice)).replace("{sellgems_qty}", cansell);
  867. if(inventory.enableTF){ response+= msg.SellCheck_i2.replace("{selltf_qty}", parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice));}
  868. customer.Message(source, response);
  869. } else {
  870. customer.Message(source, msg.ThemDonthave);
  871. }
  872. }
  873. });
  874. }
  875.  
  876. function block(admin, target){
  877. if(config.admin.indexOf(target) > -1){
  878. customer.Message(admin, 'You can\'t block this user!');
  879. } else {
  880. client.blockUser(target, result => {
  881. if(result == 1){
  882. customer.Message(admin, `Successfully blocked user ${target} !`);
  883. } else {
  884. customer.Message(admin, 'Fail!, did you put the right SteamID64 ??');
  885. }
  886. });
  887. }
  888. }
  889.  
  890. function unblock(admin, target){
  891. if(config.admin.indexOf(target) > -1){
  892. customer.Message(admin, B+'You can\'t unblock this user!');
  893. } else {
  894. client.unblockUser(target, result => {
  895. if(result == 1){
  896. customer.Message(admin, `Successfully unblocked user ${target} !`);
  897. } else {
  898. customer.Message(admin, 'Fail!, did you put the right SteamID64 ??');
  899. }
  900. });
  901. }
  902. }
  903.  
  904. function stats(admin){
  905. let response = `I currently have ${helper.nFormat(inventory.haveSets())} sets, ${inventory.haveCsKeys()} CS:GO keys, ${helper.nFormat(inventory.return_GemsQty())} Gems`;
  906. if(inventory.enableTF){response += `, ${inventory.haveTfKeys()} Tf keys`;}
  907. response += " on my inventory.";
  908. customer.Message(admin, response);
  909. }
  910.  
  911. function _profit(admin){
  912. let response = `I have sold ${helper.nFormat(profit.sell.csgo.sets)} sets for ${helper.nFormat(profit.sell.csgo.currency)} CS:GO keys, ${helper.nFormat(profit.sell.gems.sets)} sets for ${helper.nFormat(profit.sell.gems.currency)} Gems`;
  913. if(inventory.enableTF){response += `, ${helper.nFormat(profit.sell.tf.sets)} sets for ${helper.nFormat(profit.sell.tf.currency)} Tf keys`;}
  914. response += `${B}I have buyed ${helper.nFormat(profit.buy.csgo.sets)} sets for ${helper.nFormat(profit.buy.csgo.currency)} CS:GO keys, ${helper.nFormat(profit.buy.gems.sets)} sets for ${helper.nFormat(profit.buy.gems.currency)} Gems`;
  915. if(inventory.enableTF){response += `, ${helper.nFormat(profit.buy.tf.sets)} sets for ${helper.nFormat(profit.buy.tf.currency)} Tf keys`;}
  916. customer.Message(admin, response);
  917. }
  918.  
  919. function stock(admin){
  920. customer.Message(admin, msg.OwnerRequest);
  921. inventory.getCustomerSets(true, admin, (err, sets) => {
  922. if(err){
  923. handleInventoryErrors(err, admin);
  924. } else {
  925. if(sets.length){
  926. customer.Message(admin, `I've found ${sets.length} sets!, i'll send the trade offer now xD`);
  927. makeOffer(admin, [], [].concat.apply([], sets), 'admin');
  928. } else {
  929. customer.Message(admin, msg.ThemDonthave);
  930. }
  931. }
  932. });
  933. }
  934.  
  935. function level(source, qty){
  936. customer.Message(source, msg.CustomerRequest);
  937. inventory.getUserBadges(source, 0, 0, (err, badge, player_level, player_xp) => {
  938. if(err){
  939. handleBadgeErrors(err, source);
  940. } else {
  941. if(qty < player_level){
  942. customer.Message(source, `You've already reached level ${qty}!!`);
  943. } else {
  944. let needed=Math.ceil( ((helper.getLevelExp(parseInt(qty)))-player_xp)/100 ),
  945. response = msg.Level.replace("{needed}", needed).replace("{desired_level}", qty);
  946. response += B+msg.Level_c.replace("{price_keys}", ((needed/keySets)*keyPrice).toFixed(1)).replace("{price_gems}", helper.nFormat((needed/GemSet)*GemPrice));
  947. if(inventory.enableTF){response += msg.Level_c2.replace("{price_tf}", ((needed/tfkeySets)*tfkeyPrice).toFixed(1));}
  948. response += B+msg.Level2;
  949. customer.Message(source, response);
  950. }
  951. }
  952. });
  953. }
  954.  
  955. function restart_(){
  956. helper.log('Restarting..');
  957. if(!client.steamID){
  958. tryLogin();
  959. } else {
  960. client.relog();
  961. }
  962. }
  963. function shutdown() {
  964. helper.log('Shutdown requested, bye..');
  965. try {
  966. client.logOff();
  967. client.once('disconnected', () => { process.exit(1); });
  968. } catch(e) {
  969. process.exit(1);
  970. }
  971. setTimeout(() => { process.exit(1); }, 1500);
  972. }
  973.  
  974. client.on('friendMessage', (source, message) => {
  975. helper.storeChatLogData(source, message);
  976.  
  977. if(customer.LastInteract[source] && Math.floor(helper.Now() - customer.LastInteract[source]) < 500){
  978. if(!customer.Warns[source]){ customer.Warns[source] = 0; }
  979. customer.Warns[source]++;
  980. if(customer.Warns[source] == 1){ customer.Message(source, msg.SpamWarn1); }
  981. if(customer.Warns[source] == 2){ customer.Message(source, msg.SpamWarn2); }
  982. if(customer.Warns[source] > 5){ client.blockUser(source); }
  983. else if(customer.Warns[source] > 2){
  984. customer.Message(source, msg.SpamWarn3);
  985. customer.sendAdminMessages(`User #${source} has sending to much messages and have been removed from bot friendlist!`);
  986. helper.warn(`User #${source} has sending to much messages and have been removed from bot friendlist!`);
  987. client.removeFriend(source);
  988. }
  989. return;
  990. }
  991.  
  992. customer.UserInteract(source, 0);
  993.  
  994. let m = message.toLowerCase();
  995.  
  996. if(inventory.loading){
  997. if(m.indexOf('!buy') > -1 || m.indexOf('!sell') > -1 || m.indexOf('!gemswithdraw') > -1 || m.indexOf('!withdraw') > -1 || m.indexOf('!deposit') > -1 | m.indexOf('!tfdeposit') > -1 | m.indexOf('!tfwithdraw') > -1){
  998. customer.Message(source, msg.Loading);
  999. return;
  1000. }
  1001. }
  1002.  
  1003. if(m == "!help" || m == "!commands "){
  1004. let response = 'Commands:';
  1005. response += B+'!owner - show my owner profile, if you have any problems you may contact me!';
  1006. response += B+'!stats - show current bot amount of currencies';
  1007. response += B+'!prices to see our prices';
  1008. response += B;
  1009. response += B+'!level [your dream level] - calculate how many sets and how many keys it\'ll cost to desired level';
  1010. response += B+'!check - show how many sets the bot have available and how much you can craft';
  1011. response += B+'!check [amount] - show how many sets and which level you would reach for a specific amount of keys';
  1012. if(inventory.enableTF){response += B+'!checktf [amount] - show how many sets and which level you would reach for a specific amount of keys';}
  1013. response += B+'!checkgems [amount] - show how many sets and which level you would reach for a specific amount of gems';
  1014. response += B;
  1015. response += B+'!buy [amount of CS:GO keys] - use to buy that amount of CS:GO keys for sets you dont have, following the current BOT rate';
  1016. if(inventory.enableTF){response += B+'!buytf [amount of Tf keys] - use to buy that amount of CS:GO keys for sets you dont have, following the current BOT rate';}
  1017. response += B+'!buygems [amount of sets] - use to buy that amount of sets for gems, following the current BOT rate';
  1018. response += B+'!buyany [amount of CS:GO keys] - use to buy that amount of CS:GO keys for any sets, following the current BOT rate';
  1019. response += B;
  1020. response += B+'!buyone [amount of CS:GO keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate';
  1021. if(inventory.enableTF){response += B+'!buyonetf [amount of Tf keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate';}
  1022. response += B+'!buyonegems [amount of sets] - use this if you are a badge collector. sames as !buyone, buy you pay with gems!';
  1023. response += B;
  1024. if(config.enableSell){response += B+'!sell [amount of CS:GO keys] - sell your sets for CS:GO Key(s)';}
  1025. if(config.enableSell){response += B+'!sellgems [amount of sets] - sell your sets for gems';}
  1026. if(inventory.enableTF && config.enableSell){response += B+'!selltf [amount of Tf keys] - sell your sets for Tf Key(s)';}
  1027. if(config.enableSell){ response +=B+'!sellcheck - show information about the set(s) you can sell'; }
  1028. customer.Message(source, response);
  1029. }
  1030.  
  1031. else if(m.indexOf("!checktf") > -1 && inventory.enableTF){
  1032. parseInputs(message, source, 1, inputs => {
  1033. if(inputs){
  1034. checkam(source, inputs, 0, (lvl, desired) => {
  1035. if(lvl != level){
  1036. customer.Message(source, `With ${inputs} tf key(s) you'll get ${parseInt(inputs/tfkeyPrice)*tfkeySets} set(s) and reach level ${desired}, interested? try !buytf ${parseInt( inputs/tfkeyPrice )}`);
  1037. } else {
  1038. customer.Message(source, `With ${inputs} tf key(s) you'll get ${parseInt(inputs/tfkeyPrice)*tfkeySets} set(s) but still on level ${lvl}, interested? try !buytf ${parseInt(inputs/tfkeyPrice)}`);
  1039. }
  1040. });
  1041. }
  1042. }, config.maxTradeKeys);
  1043. }
  1044.  
  1045. else if(m.indexOf("!checkgems") > -1){
  1046. parseInputs(message, source, GemPrice, inputs => {
  1047. if(inputs){
  1048. checkgam(source, inputs, (lvl, desired) => {
  1049. if(lvl != desired){
  1050. customer.Message(source, `With ${inputs} gems you'll get ${parseInt(inputs/GemPrice)*GemSet} set(s), interested? try !buygems ${parseInt(inputs/GemPrice)}`);
  1051. } else {
  1052. customer.Message(source, `With ${inputs} gems you'll get ${parseInt(inputs/GemPrice)*GemSet} set(s) but'll stay on level ${lvl}, interested? try !buygems ${parseInt(inputs/GemPrice)}`);
  1053. }
  1054. });
  1055. }
  1056. }, config.maxTradeKeys*keySets*GemPrice );
  1057. }
  1058.  
  1059. else if(m.indexOf("!check") > -1){
  1060. if(m.split(" ")[1]){
  1061. parseInputs(message, source, 1, inputs => {
  1062. if(inputs){
  1063. checkam(source, inputs, 1, (lvl, desired) => {
  1064. if(lvl != level){
  1065. customer.Message(source, `With ${inputs} key(s) you'll get ${parseInt(inputs/keyPrice)*keySets} set(s) and reach level ${desired}, interested? try !buy ${parseInt(inputs/keyPrice)}`);
  1066. } else {
  1067. customer.Message(source, `With ${inputs} key(s) you'll get ${parseInt(inputs/keyPrice)*keySets} set(s) but'll stay on level ${lvl}, interested? try !buy ${parseInt(inputs/keyPrice)}`);
  1068. }
  1069. });
  1070. }
  1071. }, config.maxTradeKeys);
  1072. } else { check(source); }
  1073. }
  1074.  
  1075. else if (m == '!prices' || m == '!price' || m == '!rate' || m == '!rates' ) {
  1076. let response = 'The currently prices are:';
  1077. response += `${B}${keySets} sets for ${keyPrice} CS:GO Key(s)`;
  1078. if(inventory.enableTF){response += `${B}${tfkeySets} set(s) for ${tfkeyPrice} Tf Key(s)`;}
  1079. response += `${B}${GemPrice} Gems for ${GemSet} set(s)`;
  1080. response += B;
  1081. response += B+'Also, we\'re buying '+keyBuySets+' sets for '+keyBuyPrice+' CS:GO Key(s)';
  1082. if(inventory.enableTF){response += `${B}${tfkeyBuySets} sets for ${tfkeyBuyPrice} Tf Key(s)`;}
  1083. response += `${B}${GemBuySet} sets for ${GemBuyPrice} Gems`;
  1084. response += B;
  1085. response += `${B}Type !help for more information!`;
  1086. customer.Message(source, response);
  1087. }
  1088.  
  1089.  
  1090. else if(m.indexOf('!level') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ level(source, inputs); } }, config.maxLevelComm); }
  1091. else if(m.indexOf('!buygems') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ buygems(source, inputs, 1, 5); } }, config.maxTradeKeys*keySets); }
  1092. else if(m.indexOf('!buyonetf') > -1 && inventory.enableTF){ parseInputs(message, source, 1, inputs => { if(inputs){ buytf(source, inputs, 1, 1); } }, config.maxTradeKeys); }
  1093. else if(m.indexOf('!buyonegems') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ buygems(source, inputs, 1, 1); } }, config.maxTradeKeys*keySets); }
  1094. else if(m.indexOf('!buyone') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ buy(source, inputs, 1, 1); } }, config.maxTradeKeys); }
  1095. else if(m.indexOf('!buytf') > -1 && inventory.enableTF){ parseInputs(message, source, 1, inputs => { if(inputs){ buytf(source, inputs, 1, 5); } }, config.maxTradeKeys); }
  1096. else if(m.indexOf('!buyany') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ buy(source, inputs, 0, 5); } }, config.maxTradeKeys); }
  1097. else if(m.indexOf('!buy') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ buy(source, inputs, 1, 5); } }, config.maxTradeKeys); }
  1098. else if(m.indexOf('!sellcheck') > -1 && config.enableSell){ sellcheck(source); }
  1099. else if(m.indexOf('!selltf') > -1 && inventory.enableTF && config.enableSell){ parseInputs(message, source, 1, inputs => { if(inputs){ selltf(source, inputs); } }, config.maxTradeKeys); }
  1100. else if(m.indexOf('!sellgems') > -1 && config.enableSell){ parseInputs(message, source, 1, inputs => { if(inputs){ sellgems(source, inputs); } }, config.maxTradeKeys*keyBuySets); }
  1101. else if(m.indexOf('!sell') > -1 && config.enableSell){ parseInputs(message, source, 1, inputs => { if(inputs){ sell(source, inputs); } }, config.maxTradeKeys); }
  1102.  
  1103. else if (m == '!owner') {
  1104. let response = "There is something wrong?";
  1105. response += B+"Let me know if you're experiencing issues with my bot!";
  1106. config.admin.forEach( target => { response += `${B}https://steamcommunity.com/profiles/${target}`; });
  1107. customer.Message(source, response);
  1108. }
  1109.  
  1110. else if (m == '!dev' || m == '!proof' || m == '!developer') { customer.Message(source, `This bot was developed by https://steamcommunity.com/profiles/76561198177999769 ${B} - Please don't buy from another person.`); community.inviteUserToGroup(source, '103582791458599631');}
  1111. else if(m == '!stats'){ stats(source); }
  1112.  
  1113. else if(config.admin.indexOf(source.getSteamID64()) > -1){
  1114. if (m == '!admin') {
  1115. let response = 'Admin Commands:';
  1116. response += B+'!withdraw [amount] - withdraw x CS:GO keys';
  1117. if(inventory.enableTF){response += B+'!tfwithdraw [amount] - withdraw x Tf keys';}
  1118. response += B+'!gemswithdraw [amount] - withdraw x Gems';
  1119. response += B;
  1120. response += B+'!deposit [amount] - deposit x CS:GO keys';
  1121. if(inventory.enableTF){response += B+'!tfdeposit [amount] - deposit x Tf keys';}
  1122. response += B+'!depositgems [amount] - deposit x Gems';
  1123. response += B;
  1124. response += B+'!block [SteamID64] - block user';
  1125. response += B+'!unblock [SteamID64] - unblock user';
  1126. response += B;
  1127. response += B+'!stock - bot will send a trade offer requesting all your available sets to trade';
  1128. response += B+'!profit - show bot sells';
  1129. response += B;
  1130. response += B+'!restart - restart the bot(logoff and login)';
  1131. response += B+'!shutdown - logoff bot and close application';
  1132. customer.Message(source, response);
  1133. }
  1134.  
  1135. else if(m == '!profit'){ _profit(source); }
  1136. else if(m == '!stock'){ stock(source); }
  1137. else if(m.indexOf('!gemswithdraw') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ gemswithdraw(source, inputs); } }); }
  1138. else if(m.indexOf('!tfwithdraw') > -1 && inventory.enableTF){ parseInputs(message, source, 1, inputs => { if(inputs){ tfwithdraw(source, inputs); } }); }
  1139. else if(m.indexOf('!withdraw') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ withdraw(source, inputs); } }); }
  1140. else if(m.indexOf('!tfdeposit') > -1 && inventory.enableTF){ parseInputs(message, source, 1, inputs => { if(inputs){ tfdeposit(source, inputs); } }); }
  1141. else if(m.indexOf('!depositgems') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ depositgems(source, inputs); } }); }
  1142. else if(m.indexOf('!deposit') > -1){ parseInputs(message, source, 1, inputs => { if(inputs){ deposit(source, inputs); } }); }
  1143. else if(m.indexOf('!block') > -1){ isId64(message, source, sid => { if(sid){block(source, sid);} }); }
  1144. else if(m.indexOf('!unblock') > -1){ isId64(message, source, sid => { if(sid){unblock(source, sid);} }); }
  1145.  
  1146. else if(m == '!restart'){ customer.Message(source, "I'll be back in a minute!"); restart_(); }
  1147. else if(m == '!shutdown'){ customer.Message(source, "I going down :("); shutdown(); }
  1148.  
  1149. else { customer.Message(source, msg.UnknowAdmin); }
  1150. }
  1151.  
  1152. else { customer.Message(source, msg.Unknow); }
  1153. });
  1154.  
  1155. client.on('friendRelationship', (steamid, relationship) => { if (relationship === 2) { addFriend(steamid); } });
  1156.  
  1157. function isId64(message, target, callback){ const sid=message.split(" ")[1]; if(/[0-9]{17}/.test(sid)){ callback(sid); } else { customer.Message(target, `Try ${message.split(" ")[0]} [SteamId64]`); callback(0); } }
  1158.  
  1159. function parseInputs(message, target, min, callback, max){
  1160. const
  1161. qty=parseInt(message.split(" ")[1]),
  1162. isNumber=!(isNaN(qty));
  1163. if(isNumber){
  1164. if(!(qty >= min)){ customer.Message(target, `The amount value should be ${min} or higher.`); callback(0); }
  1165. else { if(max && qty > max){ customer.Message(target, `The amount value should be ${max} or lower`); callback(0); } else { callback(qty); } }
  1166. }
  1167. else { customer.Message(target, `Try ${message.split(" ")[0]} [amount]`); callback(0); }
  1168. }
  1169.  
  1170. function handleInventoryErrors(err, target){
  1171. if(err.message.indexOf("profile is private") > -1){
  1172. customer.Message(target, msg.Inventory_priv);
  1173. } else {
  1174. helper.logError(err.message, 'Inventory');
  1175. customer.Message(target, msg.Inventory_error);
  1176. }
  1177. }
  1178.  
  1179. function handleBadgeErrors(err, source){
  1180. if(err.message == 'empty'){
  1181. customer.Message(source, "I can't look at your badges if your profile is private, can you make it public for me? ty ^^");
  1182. } else {
  1183. helper.logError(err.message, 'Badge');
  1184. customer.Message(source, msg.Badge_error);
  1185. }
  1186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement