Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2017
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 79.71 KB | None | 0 0
  1. var path = fs = require('fs');
  2. var request = require('request');
  3. var mkdirp = require('mkdirp');
  4. var SteamTotp = require('steam-totp');
  5. var SteamUser = require('steam-user');
  6.  
  7. var SteamCommunity = require('steamcommunity');
  8. var TradeOfferManager = require('steam-tradeoffer-manager');
  9.  
  10. var config=require('./data/config.json');
  11. var KeysAccepted=require('./data/acceptablekeys.json');
  12.  
  13. var client = new SteamUser();
  14. var loginKey=null;
  15. var card_db=null;
  16. var restart=0;
  17. var debug_mode=0;
  18. var pp=0;
  19.  
  20. if (fs.existsSync(process.cwd()+'/data/sets_db.json')) { IsJsonString(fs.readFileSync(process.cwd()+'/data/sets_db.json'), function(is){ if(is){ let non_market=require('./data/nonmarketable_db.json'); card_db=Object.assign(JSON.parse(fs.readFileSync(process.cwd()+'/data/sets_db.json')), non_market); } }); }
  21. if (fs.existsSync(process.cwd()+'/data/loginKey')) { loginKey = fs.readFileSync(process.cwd()+'/data/loginKey').toString(); }
  22.  
  23. var community = new SteamCommunity();
  24. var manager = new TradeOfferManager({ "steam": client, "language": "en", "community":community, "pollInterval": "10000", "cancelTime": "7200000" });
  25.  
  26. var CurrentKeys=[];
  27. var CurrentTFKeys=[];
  28. var InventoryGemsAssets={};
  29. var InventoryCardsGame={};
  30. var AvailableSets={};
  31.  
  32. var keyPrice = parseInt(config.SetsPrice.split(':')[1]);
  33. var keySets = parseInt(config.SetsPrice.split(':')[0]);
  34.  
  35. var keyBuyPrice = parseInt(config.BuyPrice.split(':')[1]);
  36. var keyBuySets = parseInt(config.BuyPrice.split(':')[0]);
  37.  
  38. var tfkeyPrice = parseInt(config.TF2Price.split(':')[1]);
  39. var tfkeySets = parseInt(config.TF2Price.split(':')[0]);
  40.  
  41. var tfkeyBuyPrice = parseInt(config.TF2BuyPrice.split(':')[1]);
  42. var tfkeyBuySets = parseInt(config.TF2BuyPrice.split(':')[0]);
  43.  
  44. var GemPrice = parseInt(config.GemsPrice.split(':')[1]);
  45. var GemSet = parseInt(config.GemsPrice.split(':')[0]);
  46.  
  47. var GemBuyPrice = parseInt(config.GemsBuyPrice.split(':')[1]);
  48. var GemBuySet = parseInt(config.GemsBuyPrice.split(':')[0]);
  49.  
  50. var LastInteract={};
  51. var Warns={};
  52.  
  53. function IsJsonString(string, callback) {
  54. if(string.length){
  55. string = string.toString();
  56. let rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  57. let meta = {"\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", "\"": "\\\"", "\\": "\\\\"};
  58. rx_escapable.lastIndex = 0;
  59. callback(rx_escapable.test(string) ? "\"" + string.replace(rx_escapable, function (a) {
  60. var c = meta[a];
  61. callback(typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4));
  62. }) + "\"" : "\"" + string + "\"");
  63. } else {
  64. callback(false);
  65. }
  66. }
  67.  
  68. if (fs.existsSync(process.cwd()+'/data/usersinteract.json')) {
  69. IsJsonString(fs.readFileSync(process.cwd()+'/data/usersinteract.json'), function(is){
  70. if(is){
  71. LastInteract = JSON.parse(fs.readFileSync(process.cwd()+'/data/usersinteract.json'));
  72. } else {
  73. LastInteract = {};
  74. debug("Tryed to parse a wrong JSON string [data/usersinteract.json]");
  75. }
  76. });
  77. }
  78.  
  79. function StoreUsersInteract(){
  80. createPath(process.cwd()+'/data/', function(){
  81. let logger = fs.createWriteStream(process.cwd()+'/data/usersinteract.json');
  82. logger.write(JSON.stringify(LastInteract));
  83. logger.end();
  84. });
  85. }
  86.  
  87. function UserInteract(user){ LastInteract[user] = new Date().getTime(); StoreUsersInteract(); }
  88.  
  89. function debug(msg, json){
  90. getCurDateTime(function(time){
  91. if(json){
  92. storeDebugData(time+' - > '+JSON.stringify(msg)+'\r\n');
  93. if(debug_mode){console.log(time+' DEBUG - > '+JSON.stringify(msg));}
  94. } else {
  95. storeDebugData(time+' - > '+msg+'\r\n');
  96. if(debug_mode){console.log(time+' DEBUG - > '+msg);}
  97. }
  98. });
  99. }
  100.  
  101. function storeDebugData(data){
  102. createPath(process.cwd()+'/history/', function(){
  103. let logger = fs.createWriteStream(process.cwd()+'/history/debug.txt', { flags: 'a' });
  104. logger.write(data);
  105. logger.end();
  106. });
  107. }
  108.  
  109. function storeChatLogData(source, message, me){
  110. getCurDateTime(function(time){
  111. let filePath=process.cwd()+"/history/chat/"+time.split(" ")[0];
  112. createPath(filePath, function(){
  113. let chatlog = fs.createWriteStream(filePath+'/'+source+'.txt', { flags: 'a' });
  114. if(me){
  115. chatlog.write('['+time.split(" ")[1]+'] Bot: '+message+'\r\n');
  116. } else {
  117. chatlog.write('['+time.split(" ")[1]+'] User: '+message+'\r\n');
  118. }
  119. chatlog.end();
  120. });
  121. });
  122. }
  123.  
  124. function getCurDateTime(callback){
  125. let m = new Date();
  126. let dateString =
  127. m.getFullYear() + "-" +
  128. ("0" + (m.getMonth()+1)).slice(-2) + "-" +
  129. ("0" + m.getDate()).slice(-2) + " " +
  130. ("0" + m.getHours()).slice(-2) + ":" +
  131. ("0" + m.getMinutes()).slice(-2) + ":" +
  132. ("0" + m.getSeconds()).slice(-2);
  133. callback(dateString);
  134. }
  135.  
  136. function log(data){
  137. getCurDateTime(function(time){
  138. let filePath=process.cwd()+"/history/log";
  139. console.log(time+' INFO - > '+data);
  140. createPath(filePath, function(){
  141. let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
  142. chatlog.write('['+time.split(" ")[1]+'] '+data+'\r\n');
  143. chatlog.end();
  144. });
  145. });
  146. }
  147.  
  148. function logError(data, event){
  149. getCurDateTime(function(time){
  150. let filePath=process.cwd()+"/history/error";
  151. console.log(time+' ERROR - > '+event+': '+data);
  152. createPath(filePath, function(){
  153. let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
  154. chatlog.write('['+time.split(" ")[1]+'] '+event+': '+data+'\r\n');
  155. chatlog.end();
  156. });
  157. });
  158. }
  159.  
  160. function logTrade(data){
  161. getCurDateTime(function(time){
  162. let filePath=process.cwd()+"/history/trade";
  163. console.log(time+' TRADE - > '+data);
  164. createPath(filePath, function(){
  165. let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
  166. chatlog.write('['+time.split(" ")[1]+'] '+data+'\r\n');
  167. chatlog.end();
  168. });
  169. });
  170. }
  171.  
  172. createPath(process.cwd()+'/data/', function(){
  173. if (fs.existsSync(process.cwd()+'/data/poll.json')) {
  174. IsJsonString(fs.readFileSync(process.cwd()+'/data/poll.json'), function(is){
  175. if(is){
  176. manager.pollData = JSON.parse(fs.readFileSync(process.cwd()+'/data/poll.json'));
  177. } else {
  178. debug("Tryed to parse a wrong JSON string", 'data/poll.json');
  179. }
  180. });
  181. }
  182. });
  183.  
  184. function createPath(filePath, callback) {
  185. if (fs.existsSync(filePath)) { callback(); return; }
  186. mkdirp.sync(filePath, function (err) {
  187. if (err) {
  188. logError(err, "createPath: "+filePath);
  189. return;
  190. }
  191. });
  192. callback();
  193. }
  194.  
  195. function Message(steamid, msg){ client.chatMessage(steamid, msg); storeChatLogData(steamid, msg, true); }
  196.  
  197. log('Coneccting to Steam..');
  198.  
  199. function getLogOn(callback){
  200. SteamTotp.getTimeOffset(function(err, offset, latency) {
  201. callback({
  202. "accountName": config.username,
  203. "password": config.password,
  204. "twoFactorCode": SteamTotp.generateAuthCode(config.sharedse, offset),
  205. "rememberPassword":true,
  206. "promptSteamGuardCode": false/*,
  207. "loginKey":loginKey*/
  208. });
  209. });
  210. }
  211.  
  212. getLogOn(function(logindata){ client.logOn(logindata); });
  213.  
  214. setInterval(function(){
  215. log("Updating sets Database..");
  216. updateTradingCardDb(function(){ log("Sets Database up to date!"); });
  217. }, 1000*60*60*24);
  218.  
  219. setInterval(function(){
  220. let Now = new Date().getTime();
  221. for(let user in LastInteract){
  222. if(user != config.admin && Math.floor(Now - LastInteract[user]) > 1000*60*60*24*config.maxDays){
  223. Message(user, "Hey, it's been a while since you've been active...");
  224. Message(user, "I'll unfriend you, but if you need anything, just add me again :)");
  225. Message(user, "Hope I'll see you again, bye!");
  226. Message(config.admin, "User #"+user+" has have been inactive for a long time and has been removed from bot friendlist!");
  227. log("User #"+user+" has have been inactive for a long time and has been removed from bot friendlist!");
  228. client.removeFriend(user);
  229. delete LastInteract[user];
  230. StoreUsersInteract();
  231. }
  232. }
  233. }, 1000*60*60);
  234.  
  235. client.on('loggedOn', function(details) {
  236. if(config.changeBotName) { client.setPersona(SteamUser.EPersonaState.Online, config.changeBotName); }
  237. else { client.setPersona(SteamUser.EPersonaState.Online); }
  238. log("Logging to SteamCommunity..");
  239. if(restart){ client.webLogOn(); restart=0;}
  240. });
  241.  
  242. client.on('steamGuard', function(domain, callback) {
  243. //console.log("Steam Guard code needed from email ending in " + domain);
  244. SteamTotp.getTimeOffset(function(err, offset, latency) {
  245. let code = SteamUser.generateAuthCode(config.sharedse, offset);
  246. callback(code);
  247. });
  248. });
  249.  
  250. if(debug_mode){ community.on('debug', function(details) {debug(details);}); manager.on('debug', function(details) {debug(details);}); }
  251.  
  252.  
  253. client.on('webSession', function(sessionID, newCookie) {
  254. log("Connected!");
  255. if(card_db){
  256. loadmanager(newCookie);
  257. } else {
  258. log("Loading sets Database...");
  259. updateTradingCardDb(function(){ loadmanager(newCookie); });
  260. }
  261. });
  262.  
  263. function loadmanager(newCookie){
  264. log('Loading APIKey...');
  265. manager.setCookies(newCookie, function(err){
  266. if(err){ logError(err.message, "webSession"); return; }
  267. log('Got APIKey: '+manager.apiKey);
  268. community.startConfirmationChecker(15000, config.identity);
  269. LoadInventories();
  270. setInterval(function(){checkSteamLogged();}, 1000*60*4);
  271. });
  272. }
  273.  
  274. client.on('loginKey', function(key) { fs.writeFile(process.cwd()+'/data/loginKey', key, function() {}); loginKey=key; });
  275.  
  276. client.on('disconnected', function(r, msg) { logError(""+msg, ""+r); });
  277.  
  278. community.on('sessionExpired', function(err) {
  279. if(err){ logError(err.message, 'sessionExpired'); }
  280. client.setPersona(SteamUser.EPersonaState.Offline);
  281. client.webLogOn();
  282. });
  283.  
  284. community.on('confirmationAccepted', function(conf) {
  285. debug("confirmationAccepted type "+conf.type+" triggered #"+conf.id);
  286. if(conf.type == 2){
  287. debug("Searching for details of #"+conf.creator);
  288. manager.getOffer(conf.creator, function(err, myOffer){
  289. if(err){
  290. logError(err.message, 'confirmationAccepted');
  291. } else {
  292. if(myOffer.isOurOffer){
  293. Message(myOffer.partner, "Trade offer confirmed!");
  294. Message(myOffer.partner, "Click here to accept it: https://www.steamcommunity.com/tradeoffer/"+conf.creator);
  295. logTrade("Successfully sent a trade offer for "+myOffer.partner);
  296. } else {
  297. debug("#"+conf.creator+" with confirmation id #"+conf.id+" isnt a trade offer sended by bot.");
  298. }
  299. }
  300.  
  301. });
  302. }
  303. });
  304.  
  305. function checkFriendRequests(){ for(let user in client.myFriends){ if(client.myFriends[user] == 2){ addFriend(user); } } }
  306.  
  307. function addFriend(user){
  308. client.addFriend(user, function(err, result){
  309. if(err){ logError(err.message, 'checkFriendRequests'); }
  310. inviteToGroup(user);
  311. Message(user, 'Hi '+result+', thanks for add me!');
  312. Message(user, 'Type !help for instructions.');
  313. UserInteract(user);
  314. });
  315. }
  316.  
  317. function checkSteamLogged() {
  318. community.loggedIn( function (err, loggedIn, familyView) {
  319. if (err) {
  320. logError(err.message, 'community.loggedIn');
  321. setTimeout(checkSteamLogged, 1000*30); // check again in 4 min
  322. } else if ( ! loggedIn ) {
  323. debug("WebLogin check : NOT LOGGED IN !");
  324. client.setPersona(SteamUser.EPersonaState.Offline);
  325. client.webLogOn();
  326. } else {
  327. debug("WebLogin check : Already logged in !");
  328. client.setPersona(SteamUser.EPersonaState.LookingToTrade);
  329. }
  330. });
  331. }
  332.  
  333. function isInventoryloaded(callback){
  334. if(Object.keys(InventoryCardsGame).length > 0) {callback(1);}
  335. else if(CurrentKeys.length > 0) {callback(1);}
  336. else if(CurrentTFKeys.length > 0) {callback(1);}
  337. else { callback(0); }
  338.  
  339. }
  340.  
  341. createPath(process.cwd()+'/data/', function(){ manager.on('pollData', function(pollData) { fs.writeFile(process.cwd()+'/data/poll.json', JSON.stringify(pollData), function() {}); }); });
  342.  
  343. client.on('error', function(e) { logError(e.message, "client error"); });
  344.  
  345. function inviteToGroup(target){
  346. if(config.group){
  347. community.inviteUserToGroup(target, config.group, function (err) {
  348. if(err)
  349. logError(err.message, "inviteToGroup");
  350. });
  351. }
  352. }
  353.  
  354. function gemswithdraw (qty){
  355. let GemsSelected=0;
  356. let toGive=[];
  357. Message(config.admin, "Hey owner!, please wait a few seconds and I'll quickly proccess your request!");
  358.  
  359. return_GemsQty(function(GemsInInventorySelected){
  360. if(GemsInInventorySelected >= qty) {
  361. for(let key in InventoryGemsAssets){
  362. let GemAssetQty=InventoryGemsAssets[key];
  363. let GemAsset=key;
  364. let falta=qty-GemsSelected;
  365.  
  366. if(GemAssetQty >= falta && falta > 0){
  367. toGive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
  368. GemsSelected+=falta;
  369. }
  370. else if(GemAssetQty < falta && falta > 0){
  371. toGive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
  372. GemsSelected+=GemAssetQty;
  373. }
  374. }
  375.  
  376. makeOffer(config.admin, toGive, [], 'admin');
  377. } else {
  378. Message(config.admin, "I only have "+GemsInInventorySelected+" Gems on my inventory, try !gemswithdraw "+GemsInInventorySelected)
  379. }
  380. });
  381. }
  382.  
  383. function tfwithdraw (qty){
  384. Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
  385. if(CurrentTFKeys.length > 0){
  386. if(qty <= CurrentTFKeys.length){
  387. log('Admin has requested a withdraw of '+qty+' TF Key(s)!');
  388. let send=[];
  389. for(let b=0;b<CurrentTFKeys.length;b++){
  390. send.push({ appid:440, contextid:2, amount:1, assetid: CurrentTFKeys[b] });
  391. if(send.length == qty){
  392. makeOffer(config.admin, send, [], 'admin');
  393. break;
  394. }
  395. }
  396. } else {
  397. Message(config.admin, 'Found only '+CurrentTFKeys.length+' Keys, try !tfwithdraw '+CurrentTFKeys.length);
  398. //log('Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
  399. }
  400. } else {
  401. Message(config.admin, "I don't have any TF keys on my inventory ;--;");
  402. }
  403. }
  404.  
  405. function withdraw (qty){
  406. Message(config.admin, "Hey owner, please wait a few seconds and i'll quickly proccess your request!");
  407. if(CurrentKeys.length > 0){
  408. if(qty <= CurrentKeys.length){
  409. log('Admin has requested a withdraw of '+qty+' CS:GO Key(s)!');
  410. let send=[];
  411. for(let b=0;b<CurrentKeys.length;b++){
  412. send.push({ appid:730, contextid:2, amount:1, assetid: CurrentKeys[b] });
  413. if(send.length == qty){
  414. makeOffer(config.admin, send, [], 'admin');
  415. break;
  416. }
  417. }
  418. } else {
  419. Message(config.admin, 'Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
  420. //log('Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
  421. }
  422. } else {
  423. Message(config.admin, "Owner don't have any CS:GO keys on my inventory ;--;");
  424. }
  425. }
  426.  
  427. function pushNewKey(item){ if(CurrentKeys.indexOf(item.id) == -1) { CurrentKeys.push(item.id); } }
  428.  
  429. function RemoveKey(item){ if(CurrentKeys.indexOf(item) > -1) { CurrentKeys.splice(CurrentKeys.indexOf(item), 1); } }
  430.  
  431. function pushNewTFKey(item){ if(CurrentTFKeys.indexOf(item.id) == -1) { CurrentTFKeys.push(item.id); } }
  432.  
  433. function RemoveTFKey(item){ if(CurrentTFKeys.indexOf(item) > -1) { CurrentTFKeys.splice(CurrentTFKeys.indexOf(item), 1); } }
  434.  
  435. function loadCSGOInventory(callback){ CurrentKeys=[]; log('Loading CS:GO Keys..');
  436. community.getUserInventoryContents(client.steamID, 730, 2, true, function(err, items, currency, total){
  437. if(err){ logError(err.message, 'loadCSGOInventory'); }
  438. else if(items.length == 0){ log('CS:GO Inventory is empty!'); if(callback) { callback(); } }
  439. else {
  440. items.forEach(function(item, i) { if(KeysAccepted.indexOf(item.market_hash_name)> -1){ pushNewKey(item); } });
  441. log(CurrentKeys.length+" CS:GO Key(s) on Inventory!");
  442. if(callback) { callback(); }
  443. }
  444. });
  445. }
  446.  
  447. function loadTF2Inventory(callback){ CurrentTFKeys=[]; log('Loading TF Keys..');
  448. community.getUserInventoryContents(client.steamID, 440, 2, true, function(err, items, currency, total){
  449. if(err){ if(err.message.toLowerCase().indexOf("fail") > -1){logError("You need to have a TF item to load your TF inventory.", 'loadTF2Inventory'); if(callback) { callback(); } } else { logError(err.message, 'loadTF2Inventory'); } }
  450. else if(items.length == 0){ log('TF2 Inventory is empty!'); if(callback) { callback(); } }
  451. else {
  452. items.forEach(function(item, i) { if(item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){ pushNewTFKey(item); } });
  453. log(CurrentTFKeys.length+" TF Key(s) on Inventory!");
  454. if(callback) { callback(); }
  455. }
  456. });
  457. }
  458.  
  459. function LoadInventories(){
  460. isInventoryloaded(function(isInvLoaded){
  461. if(!isInvLoaded) {
  462. if(config.enableTF){
  463. loadCSGOInventory(function(){
  464. loadTF2Inventory(loadInventory);
  465. });
  466. } else {
  467. loadCSGOInventory(loadInventory);
  468. }
  469.  
  470. } else {
  471. client.setPersona(SteamUser.EPersonaState.LookingToTrade);
  472. playPrices();
  473. }
  474. });
  475. }
  476.  
  477. function updateTradingCardDb(callback){
  478. request("http://cdn.steam.tools/data/set_data.json", { json: true }, (err, r, body) => {
  479. if (!err && r.statusCode == 200 && body) {
  480. let data = {};
  481. body.sets.forEach(function(set, index){ data[set.appid] = set.true_count; });
  482. let non_market=require('./data/nonmarketable_db.json');
  483. card_db=Object.assign(data, non_market);
  484. fs.writeFile(process.cwd()+'/data/sets_db.json', JSON.stringify(data), (err) => { if (err) { logError('Error in store CardsInfo!Reason: '+err.message, 'updateTradingCardDb') } else {callback();} });
  485. } else {
  486. logError('Error in load Sets DB! Reason: '+err.message, 'updateTradingCardDb');
  487. }
  488. });
  489. }
  490.  
  491. function return_GemsQty(callback){
  492. let qty=0;
  493. for(let key in InventoryGemsAssets){ qty+=InventoryGemsAssets[key]; }
  494. callback(qty);
  495. }
  496.  
  497. function getAllCards(callback){
  498. let cards=[];
  499. for (let appid in InventoryCardsGame) {
  500. for (let card in InventoryCardsGame[appid]) {
  501. InventoryCardsGame[appid][card].forEach(function(assetid, index){
  502. //cards.push({name:InventoryCardsGame[appid][card], id:assetid});
  503. cards.push(assetid);
  504. });
  505.  
  506. }
  507. }
  508. callback(cards);
  509. }
  510.  
  511. function return_AvailableSets(callback){
  512. let sets=0;
  513. for(let key in AvailableSets){ sets+=AvailableSets[key].length; }
  514. callback(sets);
  515. }
  516.  
  517. function checkGameSet(gameApp, callback){
  518. debug("Looking sets for #"+gameApp);
  519. if(card_db[gameApp]){
  520.  
  521. if(Object.keys(InventoryCardsGame[gameApp]).length == card_db[gameApp]){
  522. let max=[];
  523. for(let key in InventoryCardsGame[gameApp]){ max.push(InventoryCardsGame[gameApp][key].length); }
  524. max=Math.min.apply( Math, max );
  525.  
  526. for (let i=0;i<max;i++) {
  527. let currentSet=[];
  528. for(let key in InventoryCardsGame[gameApp]){ currentSet.push({ appid:753, contextid:6, amount:1, assetid: InventoryCardsGame[gameApp][key][i] }); }
  529. if(!AvailableSets[gameApp]){AvailableSets[gameApp]=[];}
  530. AvailableSets[gameApp].push(currentSet);
  531. }
  532. debug("Successfully checked #"+gameApp);
  533. callback();
  534. } else {
  535. debug("Successfully checked #"+gameApp);
  536. callback();
  537. }
  538. } else {
  539. debug("sets database doesnt have data about #"+gameApp);
  540. callback();
  541. }
  542. }
  543.  
  544. function checkGamesSetInfo(appIds, callback){
  545. let checked=0;
  546. appIds.forEach(function(appId, i){ checkGameSet(appId , function(){checked++;}); });
  547. let c = setInterval(function(){ if(checked == appIds.length){ clearInterval(c); callback(); } }, 800);
  548. }
  549.  
  550. function getAllGames(callback){ callback(Object.keys(InventoryCardsGame)); }
  551.  
  552. function pushGems(item, amount){
  553. if(!InventoryGemsAssets[item.id]){ InventoryGemsAssets[item.id] = 0; }
  554. InventoryGemsAssets[item.id] += amount;
  555. }
  556.  
  557. function getInventoryGemsQty(callback){
  558. let totalGems=0;
  559. for (let _key in InventoryGemsAssets){
  560. totalGems += parseInt(InventoryGemsAssets[_key]);
  561. }
  562. callback(totalGems);
  563. }
  564.  
  565. function removeGems(id, qty){
  566. if(InventoryGemsAssets[id]){
  567. InventoryGemsAssets[id] -= qty;
  568. if(InventoryGemsAssets[id] < 0){ delete InventoryGemsAssets[id]; }
  569. } else {
  570. logError('Trying to remove gems out of bot inventory!', 'removeGems')
  571. }
  572. }
  573.  
  574. function handleAddNewItem(item, amount){
  575. if(config.enableTF && item.appid == 440 && item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
  576. pushNewTFKey(item);
  577. } else if(item.appid == 730 && KeysAccepted.indexOf(item.market_hash_name) > -1){
  578. pushNewKey(item);
  579. } else if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1){
  580. pushGems(item, amount);
  581. } else if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
  582. pushInventoryCard(item);
  583. }
  584. }
  585.  
  586. function handleRemoveItem(item, amount){
  587. if(config.enableTF && item.appid == 440 && item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
  588. RemoveTFKey(item.id);
  589. } else if(item.appid == 730 && KeysAccepted.indexOf(item.market_hash_name) > -1){
  590. RemoveKey(item.id);
  591. } else if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1){
  592. removeGems(item.id, amount);
  593. } else if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
  594. removeInventoryCard(item);
  595. }
  596. }
  597.  
  598. function pushInventoryCard(item){
  599. let appid=item.market_hash_name.split("-")[0];
  600. if(appid != 753){
  601. if(!InventoryCardsGame[appid]){ InventoryCardsGame[appid] = {}; }
  602. if(!InventoryCardsGame[appid][item.market_hash_name]){ InventoryCardsGame[appid][item.market_hash_name] = []; }
  603. if(InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id) == -1){
  604. InventoryCardsGame[appid][item.market_hash_name].push(item.id);
  605. }
  606. }
  607. }
  608.  
  609. function removeInventoryCard(item){
  610. let appid=item.market_hash_name.split("-")[0];
  611. if(appid != 753){
  612. if(InventoryCardsGame[appid] && InventoryCardsGame[appid][item.market_hash_name] && InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id) > -1){
  613. InventoryCardsGame[appid][item.market_hash_name].splice(InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id), 1);
  614. } else {
  615. logError('Trying to remove an inventory card out of bot inventory!', 'removeInventoryCard')
  616. }
  617. }
  618. }
  619.  
  620. function makeOffer(target, itemsFromMe, itemsFromThem, details, type, currency){
  621. debug("Creating trade offer for #"+target+" with "+itemsFromMe.length+" items to send and "+itemsFromThem.length+" items to receive");
  622. let offer = manager.createOffer(target);
  623. let addMyItemsCount = offer.addMyItems(itemsFromMe);
  624. let addTheirItemsCount = offer.addTheirItems(itemsFromThem);
  625. offer.data('cancelTime', 'undefined');
  626. offer.data('SellInfo', details);
  627. offer.data('SellInfoType', type);
  628. offer.data('SellInfoCurrency', currency);
  629. offer.getUserDetails(function(err, them, me){
  630. if(err){
  631. if(err.message.toLowerCase().indexOf("is not available to trade. more information will be") > -1){
  632. Message(target, "You're unavailable to trade, please try again later :)");
  633. logTrade("#"+target+" is unavailable to trade");
  634. } else { logError(err.message, 'makeOffer'); }
  635. return;
  636. }
  637. if(them.escrowDays){
  638. Message(target, "Sorry but I can't trade if you have trade hold!");
  639. Message(target, "Come back later please?");
  640. } else {
  641. debug("Sending offer for #"+target);
  642. offer.send(function(err, status) {
  643. debug("Offer #"+offer.id+" status: "+status+", "+err);
  644. if (err){ if(err.message.toLowerCase().indexOf("sent too many trade offers") > 1){
  645. Message(target, "I have sent too many trade offers or have too many outstanding trade offers with you. Please cancel some before you request more :)");
  646. } else {
  647. logError(err.message, 'makeOffer');
  648. Message(target, "Some error has occurred, please try again later?");
  649. } } else {
  650. manager.getOffer(offer.id, function(err, myOffer){
  651. if(err){logError(err.message, 'makeOffer');return;}
  652. if(addMyItemsCount != myOffer.itemsToGive.length){
  653. logError('Cant add itemsFromMe, some item is missing in my inventory!', 'makeOffer');
  654. Message(target, "Some error has occurred, please try again later.");
  655. myOffer.cancel();
  656. } else if(addTheirItemsCount != myOffer.itemsToReceive.length){
  657. logError('Cant add itemsFromThem, some item is missing in my inventory!', 'makeOffer');
  658. Message(target, "Some error has occurred, please try again later.");
  659. myOffer.cancel();
  660. } else if (status == 'pending') {
  661. Message(target, "Trade offer sent! Confirming it..");
  662. logTrade("Sended a trade offer for "+target+", waiting for mobile confirmation.");
  663. community.checkConfirmations();
  664. } else {
  665. Message(target, "Trade offer sent!!");
  666. Message(target, "Click here to accept it: https://www.steamcommunity.com/tradeoffer/"+offer.id);
  667. logTrade("Successfully sent a trade offer for "+target);
  668. }
  669. });
  670. }
  671. });
  672. }
  673. });
  674.  
  675. }
  676.  
  677. function playPrices(){
  678. return_AvailableSets(function(havesets){
  679. let g = "[H] "+havesets+" sets - "+keySets+":"+keyPrice+" CS:GO Key / "+GemSet+":"+GemPrice+" Gems"; if(config.enableTF){ g +=" / "+tfkeySets+":"+tfkeyPrice+" TF Key!"; }
  680. client.gamesPlayed(g);
  681. });
  682. if(!pp){ pp++; setTimeout(function(){pp=0;playPrices()}, 1000*60*5); }
  683. }
  684.  
  685. function online(){ client.setPersona(SteamUser.EPersonaState.LookingToTrade); playPrices(); checkFriendRequests(); return_AvailableSets(function(founded){ log('Found '+founded+' card sets!'); });}
  686.  
  687. function loadInventory(){
  688. log('Loading Steam Inventory..');
  689. community.getUserInventoryContents(client.steamID, 753, 6, true, function(err, items, currency, total){
  690. if(err){ logError(err.message, 'loadInventory'); loadInventory(); }
  691. else if(items.length == 0){ log('Steam Inventory is empty!'); online();}
  692. else {
  693. items.forEach( function(item, i) { handleAddNewItem(item, item.amount); });
  694.  
  695. getInventoryGemsQty(function(totalGems){
  696. getAllCards(function(cards){
  697. let loginfo='Found '+cards.length+' cards';
  698. if(totalGems > 0){
  699. loginfo +=', and '+totalGems+' Gems on inventory!';
  700. } else {
  701. loginfo +=' on inventory!';
  702. }
  703. log(loginfo);
  704. });
  705. });
  706. debug("Looking for sets..");
  707. getAllGames(function(games){ checkGamesSetInfo(games, function(){online();}); });
  708.  
  709. }
  710. });
  711. }
  712.  
  713. function getLevelExp(level){
  714. let inicial=100;
  715. let lastexp=0;
  716. let level_exp=[];
  717. for(let i=1;i<level+1;i++){
  718. let exp=lastexp+inicial;
  719. lastexp=exp;
  720. level_exp.push( { "value":exp } );
  721. if(i==level){ return exp; }
  722. if(!((i/10) % 1 != 0 && !isNaN((i/10) % 1))){ inicial +=100; }
  723. }
  724. }
  725.  
  726. manager.on('newOffer', function(offer) {
  727. var partner=offer.partner.getSteamID64();
  728.  
  729. if(partner==config.admin){ logTrade("New offer from admin!");
  730. offer.accept(function(err, res) {
  731. if (err) { Message(config.admin, "Unable to accept offer: " + err.message); logTrade("Unable to accept admin offer: " + err.message); }
  732. else { if(res == "pending"){ community.checkConfirmations(); } else { logTrade("Admin Offer accepeted!"); } }
  733. });
  734. }
  735. });
  736.  
  737. manager.on('receivedOfferChanged', function(offer, oldState) {
  738. debug("receivedOfferChanged Triggered at #"+offer.id+", state: "+offer.state+", oldState: "+oldState)
  739. if(offer.state == 3 ){
  740. //Handle gived items
  741. offer.itemsToGive.forEach(function(item, index){ handleRemoveItem(item, item.amount); });
  742.  
  743. //Handle received items
  744. offer.getReceivedItems(function(err, items) { if(err){logError(err.message, 'receivedOfferChanged');} else {
  745. items.forEach(function(item, index){ handleAddNewItem(item, item.amount); });
  746.  
  747. //Update CardSets
  748. log('Updating sets database..');
  749. getAllGames(function(games){ AvailableSets={}; checkGamesSetInfo(games, function(){ playPrices(); }); });
  750. } });
  751. }
  752. });
  753.  
  754. manager.on('sentOfferChanged', function(offer, oldState) {
  755. debug("sentOfferChanged Triggered at #"+offer.id+", state: "+offer.state+", oldState: "+oldState)
  756. if(offer.state == 3 ){
  757. //Handle gived items
  758. offer.itemsToGive.forEach(function(item, index){ handleRemoveItem(item, item.amount); });
  759.  
  760. //Handle received items
  761. offer.getReceivedItems(function(err, items) { if(err){logError(err.message, 'sentOfferChanged');} else {
  762. items.forEach(function(item, index){ handleAddNewItem(item, item.amount); });
  763.  
  764. //Update CardSets
  765. log('Updating sets database..');
  766. getAllGames(function(games){ AvailableSets={}; checkGamesSetInfo(games, function(){ playPrices(); }); });
  767. } });
  768.  
  769. if(config.ThanksM && offer.data('SellInfo') != 'admin'){
  770. community.postUserComment(offer.partner.toString(), config.ThanksM);
  771. Message(offer.partner, "Thanks for using my Level UP service!");
  772. Message(offer.partner, "Can you leave a +Rep on my profile? Thanks!");
  773. }
  774. inviteToGroup(offer.partner.getSteamID64());
  775. if(offer.data('SellInfoType') != null){
  776. if(offer.data('SellInfoType') == 0){
  777. 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')+'!');
  778. Message(config.admin, "Hey!, i just have selled "+offer.data('SellInfo').split(":")[0]+" Set(s) for "+offer.data('SellInfo').split(":")[1]+" "+offer.data('SellInfoCurrency')+"!");
  779. } else if(offer.data('SellInfoType') == 1){
  780. 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')+'!');
  781. Message(config.admin, "Hey!, i just have buyed "+offer.data('SellInfo').split(":")[0]+" Set(s) for "+offer.data('SellInfo').split(":")[1]+" "+offer.data('SellInfoCurrency')+"!");
  782. }
  783. }
  784. }
  785. });
  786.  
  787. function tfdeposit(qty){
  788. let cath=[]; let sended=0;
  789. Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
  790. community.getUserInventoryContents(config.admin, 440, 2, true, function(err, items, currency, total){
  791. if(err){ logError(err.message, 'tfdeposit'); Message(config.admin, 'An error has occurred, please try again later.'); return; }
  792.  
  793. if(items.length > 0){
  794. for(let a=0;a<items.length;a++){
  795. if(items[a].market_hash_name && items[a].market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
  796. cath.push({ appid:440, contextid:2, amount:1, assetid: items[a].id });
  797. }
  798. if(cath.length == qty ){
  799. if(sended == 0){ sended++; makeOffer(config.admin, [], cath, 'admin'); }
  800. break;
  801. }
  802. }
  803. }
  804.  
  805. if(sended == 0 ){
  806. if(cath.length > 0){ Message(config.admin, 'Found only '+cath.length+' tf keys in owner inventory, try !tfdeposit '+cath.length); }
  807. else { Message(config.admin, 'Owner dont have any TF Keys available to trade...'); }
  808. }
  809. });
  810. }
  811.  
  812. function deposit(qty){
  813. let cath=[]; let sended=0;
  814. Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
  815. community.getUserInventoryContents(config.admin, 730, 2, true, function(err, items, currency, total){
  816. if(err){ logError(err.message, 'deposit'); Message(config.admin, 'An error has occurred, please try again later.'); return; }
  817. if(items.length > 0){
  818. for(let a=0;a<items.length;a++){
  819. if(items[a].market_hash_name && KeysAccepted.indexOf(items[a].market_hash_name) > -1){
  820. cath.push({ appid:730, contextid:2, amount:1, assetid: items[a].id });
  821. }
  822. if(cath.length == qty ){
  823. if(sended == 0){ sended++; makeOffer(config.admin, [], cath, 'admin'); }
  824. break;
  825. }
  826. }
  827. }
  828.  
  829. if(sended == 0 ){
  830. if(cath.length > 0){ Message(config.admin, 'Found only '+cath.length+' keys in owner inventory, try !deposit '+cath.length); }
  831. else { Message(config.admin, 'Owner currently dont have any CS:GO Keys available to trade...'); }
  832. }
  833. });
  834. }
  835. //Deposit Gems
  836. function depositgems(qty){
  837. let cath=[]; let sended=0;
  838. Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
  839. community.getUserInventoryContents(config.admin, 753, 6, true, function(err, items, currency, total){
  840. if(err){ logError(err.message, 'deposit'); Message(config.admin, 'Something wrong has happened, please try again later .. ?'); return; }
  841. let UserGemsAssets={};
  842. let UserGemsQty=0;
  843.  
  844. items.forEach(function(item, index){
  845. if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
  846. UserGemsAssets[item.id]=item.amount;
  847. UserGemsQty+=parseInt(item.amount);
  848. }
  849. });
  850.  
  851. if(UserGemsQty > 0){
  852. if(UserGemsQty < qty){
  853. Message(config.admin, 'Found only '+UserGemsQty+' gems in owner inventory, try !depositgems '+UserGemsQty);
  854. }
  855. else {
  856. let SelecionedGemsQty=0;
  857. let toReceive=[];
  858. for(let key in UserGemsAssets){
  859. let GemAssetQty=UserGemsAssets[key];
  860. let GemAsset=key;
  861. let falta=qty-SelecionedGemsQty;
  862.  
  863. if(GemAssetQty >= falta && falta > 0){
  864. toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
  865. SelecionedGemsQty+=falta;
  866. }
  867. else if(GemAssetQty < falta && falta > 0){
  868. toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
  869. SelecionedGemsQty+=GemAssetQty;
  870. }
  871. }
  872. makeOffer(config.admin, [], toReceive, 'admin');
  873. }
  874. } else { Message(config.admin, 'Owner dont have any Gems available to trade..'); }
  875.  
  876. });
  877. }
  878.  
  879. function check(source){
  880. if(Object.keys(AvailableSets).length > 0) {
  881. Message(source, "Thanks for asking! Let me check your badges.");
  882. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  883. if(err){ logError(err.message, 'check'); Message(source, 'Something wrong has happened, please try again later .. ?'); return; }
  884. let Qty=0;
  885. let badges=r.response.badges;
  886. let badge={};
  887.  
  888. for(let key in badges){
  889. let current_badge=badges[key];
  890. let appid=current_badge.appid;
  891. let lvl=current_badge.level;
  892. if(appid && current_badge.border_color == 0){
  893. badge[appid] = 5-parseInt(lvl);
  894. }
  895. }
  896.  
  897. for(let appid in AvailableSets){
  898. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  899. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
  900. Qty+=available_qty;
  901. }
  902.  
  903. if(Qty > 0){
  904. Message(source, 'I currently have '+Qty+' set(s) that you have yet to craft.');
  905. let r = "To buy all of them it'll cost "+nFormat((Qty/keySets)*keyPrice)+" CS:GO Key(s) or "+Math.round(Qty/GemSet)*GemPrice+" Gems";
  906. if(config.enableTF){
  907. r += " or "+nFormat((Qty/tfkeySets)*tfkeyPrice)+" TF Key(s)!"
  908. }
  909. Message(source, r);
  910. r = 'Interested? Try !buy '+parseInt(Qty/keySets)*keyPrice+', or !buygems '+Qty;
  911. if(config.enableTF){
  912. r += ' or !buytf '+parseInt(Qty/tfkeySets)*tfkeyPrice;
  913. }
  914. Message(source, r);
  915. if(CurrentKeys.length > 0){ Message(source, 'Wanna buy my keys? Try !sellcheck'); }
  916. } else {
  917. Message(source, 'Unfortunately I do not have any sets that you have yet to craft :/');
  918. Message(source, 'Come back later, will you?');
  919. if(CurrentKeys.length > 0){ Message(source, 'If you want to buy my keys try !sellcheck!'); }
  920. }
  921. });
  922.  
  923. } else {
  924. Message(source, 'Unfortunately I dont have any set that you have yet to craft.');
  925. Message(source, 'Come back later, will you?');
  926. Message(source, 'If you want to buy my keys try !sell !');
  927. }
  928.  
  929.  
  930. }
  931.  
  932. function return_CustomerCSGOKeys(sid64, callback){
  933. community.getUserInventoryContents(sid64, 730, 2, true, function(err, items, currency, total){
  934. if(err){ logError(err.message, 'return_CustomerCSGOKeys'); callback(err); }
  935. else if(items.length == 0){ callback(null, []); }
  936. else {
  937. let KeysFromThemAsset=[];
  938. items.forEach(function(item, d){ if(KeysAccepted.indexOf(item.market_hash_name) > -1){ KeysFromThemAsset.push(item.assetid); } });
  939. callback(null, KeysFromThemAsset);
  940. }
  941. });
  942. }
  943.  
  944. function return_CustomerTFKeys(sid64, callback){
  945. community.getUserInventoryContents(sid64, 440, 2, true, function(err, items, currency, total){
  946. if(err){ logError(err.message, 'return_CustomerTFKeys'); callback(err); }
  947. else if(items.length == 0){ callback(null, []); }
  948. else {
  949. let KeysFromThemAsset=[];
  950. items.forEach(function(item, d){ if(item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){ KeysFromThemAsset.push(item.assetid); } });
  951. callback(null, KeysFromThemAsset);
  952. }
  953. });
  954. }
  955.  
  956. function buygems(source, qty){
  957. Message(source, "I'll send the trade offer in a minute!");
  958. community.getUserInventoryContents(source, 753, 6, true, function(err, items, currency, total){
  959. if(err){ logError(err.message, 'buygems'); Message(source, 'An error has occurred, please try again later.'); }
  960. else if(items.length == 0){ Message(source, 'Your Steam Inventory is empty :/'); }
  961. else {
  962. let UserGemsAssets={};
  963. let UserGemsQty=0;
  964.  
  965. items.forEach(function(item, index){
  966. if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
  967. if(!UserGemsAssets[item.id]){UserGemsAssets[item.id] = 0;}
  968. UserGemsAssets[item.id] += parseInt(item.amount);
  969. UserGemsQty+=parseInt(item.amount);
  970. }
  971. });
  972.  
  973. if(UserGemsQty >= (GemPrice*qty)){
  974. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  975. let Qty=0;
  976. let toSend=[];
  977. let badges=r.response.badges;
  978. let badge={};
  979.  
  980. for(let key in badges){
  981. let current_badge=badges[key];
  982. let appid=current_badge.appid;
  983. let lvl=current_badge.level;
  984. if(appid && current_badge.border_color == 0){
  985. badge[appid] = 5-parseInt(lvl);
  986. }
  987. }
  988.  
  989. for(let appid in AvailableSets){
  990. let available_qty=0;
  991. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  992. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
  993. Qty+=available_qty;
  994. if(available_qty && (toSend.length < (GemSet*qty))){
  995. for(let i=0;i<available_qty;i++){
  996. if(toSend.length < (GemSet*qty)){
  997. toSend.push(AvailableSets[appid][i]);
  998. if(toSend.length == (GemSet*qty)){ break; }
  999. }
  1000. }
  1001. }
  1002. }
  1003.  
  1004. if(Qty >= (GemSet*qty)){
  1005. let SelecionedGemsQty=0;
  1006. let toReceive=[];
  1007. let added=0;
  1008.  
  1009. for(let key in UserGemsAssets){
  1010. let GemAssetQty=UserGemsAssets[key];
  1011. let GemAsset=key;
  1012. let falta=(GemPrice*qty)-SelecionedGemsQty;
  1013.  
  1014. if(GemAssetQty >= falta && falta > 0){
  1015. toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
  1016. SelecionedGemsQty+=falta;
  1017. }
  1018. else if(GemAssetQty < falta && falta > 0){
  1019. toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
  1020. SelecionedGemsQty+=GemAssetQty;
  1021. }
  1022. }
  1023.  
  1024. makeOffer(source, [].concat.apply([], toSend), toReceive, (GemSet*qty)+":"+(GemPrice*qty), 0, "gems");
  1025. } else {
  1026. Message(source, "Sorry, since you're a badge collector, I have only '+Qty+' sets available that you have yet to craft.");
  1027. if(Qty >= GemSet){
  1028. Message(source, 'Try !buygems '+Math.round(Qty/GemSet)+'!');
  1029. } else {
  1030. Message(source, 'Come back later, will you?');
  1031. }
  1032. }
  1033. });
  1034.  
  1035. } else {
  1036. Message(source, 'Sorry, but you need '+(GemPrice*qty)+' gems for this purchae and you only have '+UserGemsQty+' :(');
  1037. }
  1038.  
  1039. }
  1040. });
  1041. }
  1042.  
  1043. function buyany(source, qty){
  1044. Message(source, "I'll send the trade offer in a minute!");
  1045. return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
  1046. if(err){
  1047. Message(source, "For some reason I can't load your cs:go inventory. please try again later :(");
  1048. } else {
  1049. if(KeysFromThemAsset.length >= (keyPrice*qty)){
  1050. let Qty=0;
  1051. let toSend=[];
  1052. let badge={};
  1053.  
  1054. for(let appid in AvailableSets){
  1055. let available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) );
  1056. Qty+=available_qty;
  1057. if(available_qty && (toSend.length < (keySets*qty))){
  1058. for(let i=0;i<available_qty;i++){
  1059. if(toSend.length < (keySets*qty)){
  1060. toSend.push(AvailableSets[appid][i]);
  1061. if(toSend.length == (keySets*qty)){ break; }
  1062. }
  1063. }
  1064. }
  1065. }
  1066.  
  1067. if(Qty >= (keySets*qty)){
  1068. let toReceive=[];
  1069. for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
  1070. makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
  1071. } else {
  1072. Message(source, 'Hey, i have only '+Qty+' Sets available..');
  1073. if(Qty >= keySets){
  1074. Message(source, 'Try !buyany '+Math.round(Qty/keySets)+'!');
  1075. } else {
  1076. Message(source, 'Come back later please ?');
  1077. }
  1078. }
  1079.  
  1080.  
  1081. } else {
  1082. Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you have only '+KeysFromThemAsset.length+' :(');
  1083. }
  1084. }
  1085. });
  1086.  
  1087. }
  1088.  
  1089. function buytf(source, qty){
  1090. Message(source, "I'll send the trade offer in a minute!");
  1091. return_CustomerTFKeys(source, function(err, KeysFromThemAsset){
  1092. if(err){
  1093. Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
  1094. } else {
  1095. if(KeysFromThemAsset.length >= (tfkeyPrice*qty)){
  1096. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1097. let Qty=0;
  1098. let toSend=[];
  1099. let badges=r.response.badges;
  1100. let badge={};
  1101.  
  1102. for(let key in badges){
  1103. let current_badge=badges[key];
  1104. let appid=current_badge.appid;
  1105. let lvl=current_badge.level;
  1106. if(appid && current_badge.border_color == 0){
  1107. badge[appid] = 5-parseInt(lvl);
  1108. }
  1109. }
  1110.  
  1111.  
  1112. for(let appid in AvailableSets){
  1113. let available_qty=0;
  1114. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  1115. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
  1116. Qty+=available_qty;
  1117. if(available_qty && (toSend.length < (tfkeySets*qty))){
  1118. for(let i=0;i<available_qty;i++){
  1119. if(toSend.length < (tfkeySets*qty)){
  1120. toSend.push(AvailableSets[appid][i]);
  1121. if(toSend.length == (tfkeySets*qty)){ break; }
  1122. }
  1123. }
  1124. }
  1125. }
  1126.  
  1127. if(Qty >= (tfkeySets*qty)){
  1128. let toReceive=[];
  1129. for(let i=0;i<(tfkeyPrice*qty);i++){ toReceive.push({ appid:440, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
  1130. makeOffer(source, [].concat.apply([], toSend), toReceive, (tfkeySets*qty)+":"+(tfkeyPrice*qty), 0, "tf key(s)");
  1131. } else {
  1132. Message(source, 'Hey, I only '+Qty+' sets available that you have yet to craft.');
  1133. if(Qty >= tfkeySets){
  1134. Message(source, 'Try !buytf '+Math.round(Qty/tfkeySets)+'!');
  1135. } else {
  1136. Message(source, 'Come back later, will you?');
  1137. }
  1138. }
  1139. });
  1140.  
  1141. } else {
  1142. Message(source, 'Sorry, but you need '+(keyPrice*qty)+' tf key(s) for this purchase, and you only '+KeysFromThemAsset.length+' :(');
  1143. }
  1144. }
  1145. });
  1146. }
  1147.  
  1148. function buy(source, qty){
  1149. Message(source, "I'll send the trade offer in a minute!");
  1150. debug("user #"+source+" requested !buy "+qty);
  1151. return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
  1152. if(err){
  1153. Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
  1154. } else {
  1155. if(KeysFromThemAsset.length >= (keyPrice*qty)){
  1156. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1157. let Qty=0;
  1158. let toSend=[];
  1159. let badges=r.response.badges;
  1160. let badge={};
  1161.  
  1162. for(let key in badges){
  1163. let current_badge=badges[key];
  1164. let appid=current_badge.appid;
  1165. let lvl=current_badge.level;
  1166. if(appid && current_badge.border_color == 0){
  1167. badge[appid] = 5-parseInt(lvl);
  1168. }
  1169. }
  1170.  
  1171.  
  1172. for(let appid in AvailableSets){
  1173. let available_qty=0;
  1174. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  1175. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
  1176. Qty+=available_qty;
  1177. if(available_qty && (toSend.length < (keySets*qty))){
  1178. for(let i=0;i<available_qty;i++){
  1179. if(toSend.length < (keySets*qty)){
  1180. toSend.push(AvailableSets[appid][i]);
  1181. if(toSend.length == (keySets*qty)){ break; }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. debug("Founded "+Qty+" sets available to #"+source);
  1187. debug("Putting "+toSend.length+" sets in trade offer for #"+source);
  1188.  
  1189. if(Qty >= (keySets*qty)){
  1190. let toReceive=[];
  1191. for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
  1192. debug("Putting "+toReceive.length+" keys to send for #"+source);
  1193. makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
  1194. } else {
  1195. Message(source, 'Hey, I only have '+Qty+' sets available that you have yet to craft.');
  1196. if(Qty >= keySets){
  1197. Message(source, 'Try !buy '+Math.round(Qty/keySets)+'!');
  1198. } else {
  1199. Message(source, 'Come back later, will you?');
  1200. }
  1201. }
  1202. });
  1203.  
  1204. } else {
  1205. Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
  1206. }
  1207. }
  1208. });
  1209. }
  1210.  
  1211. function buyone(source, qty){
  1212. Message(source, "I'll send the trade offer in a minute!");
  1213. return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
  1214. if(err){
  1215. Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
  1216. } else {
  1217. if(KeysFromThemAsset.length >= (keyPrice*qty)){
  1218. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1219. let Qty=0;
  1220. let toSend=[];
  1221. let badges=r.response.badges;
  1222. let badge={};
  1223.  
  1224. for(let key in badges){
  1225. let current_badge=badges[key];
  1226. let appid=current_badge.appid;
  1227. let lvl=current_badge.level;
  1228. if(appid && current_badge.border_color == 0){
  1229. badge[appid] = (lvl) ? 0 : 1;
  1230. }
  1231. }
  1232.  
  1233.  
  1234. for(let appid in AvailableSets){
  1235. let available_qty=0;
  1236. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  1237. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
  1238. Qty+=available_qty;
  1239. if(available_qty && (toSend.length < (keySets*qty))){
  1240. for(let i=0;i<available_qty;i++){
  1241. if(toSend.length < (keySets*qty)){
  1242. toSend.push(AvailableSets[appid][i]);
  1243. if(toSend.length == (keySets*qty)){ break; }
  1244. }
  1245. }
  1246. }
  1247. }
  1248.  
  1249. if(Qty >= (keySets*qty)){
  1250. let toReceive=[];
  1251. for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
  1252. makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
  1253. } else {
  1254. Message(source, 'Hey, I have only '+Qty+' sets available which you yet to craft.');
  1255. if(Qty >= keySets){
  1256. Message(source, 'Try !buyone '+Math.round(Qty/keySets)+'!');
  1257. } else {
  1258. Message(source, 'Come back later, will you?');
  1259. }
  1260. }
  1261. });
  1262.  
  1263. } else {
  1264. Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
  1265. }
  1266. }
  1267. });
  1268. }
  1269.  
  1270. function buyonetf(source, qty){
  1271. Message(source, "I'll send the trade offer in a minute!");
  1272. return_CustomerTFKeys(source, function(err, KeysFromThemAsset){
  1273. if(err){
  1274. Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
  1275. } else {
  1276. if(KeysFromThemAsset.length >= (tfkeyPrice*qty)){
  1277. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1278. let Qty=0;
  1279. let toSend=[];
  1280. let badges=r.response.badges;
  1281. let badge={};
  1282.  
  1283. badges.forEach(function(current_badge, baindex){
  1284. let appid=current_badge.appid;
  1285. let lvl=current_badge.level;
  1286. if(appid && current_badge.border_color == 0){
  1287. badge[appid] = (lvl) ? 0 : 1;
  1288. }
  1289. });
  1290.  
  1291.  
  1292. for(let appid in AvailableSets){
  1293. let available_qty=0;
  1294. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  1295. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
  1296. Qty+=available_qty;
  1297. if(available_qty && (toSend.length < (tfkeySets*qty))){
  1298. for(let i=0;i<available_qty;i++){
  1299. if(toSend.length < (tfkeySets*qty)){
  1300. toSend.push(AvailableSets[appid][i]);
  1301. if(toSend.length == (tfkeySets*qty)){ break; }
  1302. }
  1303. }
  1304. }
  1305. }
  1306.  
  1307. if(Qty >= (tfkeySets*qty)){
  1308. let toReceive=[];
  1309. for(let i=0;i<(tfkeyPrice*qty);i++){ toReceive.push({ appid:440, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
  1310. makeOffer(source, [].concat.apply([], toSend), toReceive, (tfkeySets*qty)+":"+(tfkeyPrice*qty), 0, "tf key(s)");
  1311. } else {
  1312. Message(source, 'Hey, I have only '+Qty+' sets available which you have yet to craft.');
  1313. if(Qty >= tfkeySets){
  1314. Message(source, 'Try !buyonetf '+Math.round(Qty/tfkeySets)+'!');
  1315. } else {
  1316. Message(source, 'Come back later, will you?');
  1317. }
  1318. }
  1319. });
  1320.  
  1321. } else {
  1322. Message(source, 'Sorry, but you need '+(tfkeyPrice*qty)+' tf key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
  1323. }
  1324. }
  1325. });
  1326. }
  1327.  
  1328. function buyonegems(source, qty){
  1329. Message(source, "I'll send the trade offer in a minute!");
  1330. community.getUserInventoryContents(source, 753, 6, true, function(err, items, currency, total){
  1331. if(err){ logError(err.message, 'buygems'); Message(source, 'An error has occurred, please try again later.'); }
  1332. else if(items.length == 0){ Message(source, 'Your Steam Inventory is empty :/'); }
  1333. else {
  1334. let UserGemsAssets={};
  1335. let UserGemsQty=0;
  1336.  
  1337. items.forEach(function(item, index){
  1338. if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
  1339. UserGemsAssets[item.id]=item.amount;
  1340. UserGemsQty+=parseInt(item.amount);
  1341. }
  1342. });
  1343.  
  1344. if(UserGemsQty >= (GemPrice*qty)){
  1345. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1346. let Qty=0;
  1347. let toSend=[];
  1348. let badges=r.response.badges;
  1349. let badge={};
  1350.  
  1351. for(let key in badges){
  1352. let current_badge=badges[key];
  1353. let appid=current_badge.appid;
  1354. let lvl=current_badge.level;
  1355. if(appid && current_badge.border_color == 0){
  1356. badge[appid] = (lvl) ? 0 : 1;
  1357. }
  1358. }
  1359.  
  1360.  
  1361. for(let appid in AvailableSets){
  1362. let available_qty=0;
  1363. if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
  1364. else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
  1365. Qty+=available_qty;
  1366. if(available_qty && (toSend.length < (GemSet*qty))){
  1367. for(let i=0;i<available_qty;i++){
  1368. if(toSend.length < (GemSet*qty)){
  1369. toSend.push(AvailableSets[appid][i]);
  1370. if(toSend.length == (GemSet*qty)){ break; }
  1371. }
  1372. }
  1373. }
  1374. }
  1375.  
  1376. if(Qty >= (GemSet*qty)){
  1377. let toReceive=[];
  1378. let SelecionedGemsQty=0;
  1379. for(let key in UserGemsAssets){
  1380. let GemAssetQty=UserGemsAssets[key];
  1381. let GemAsset=key;
  1382. let falta=(GemPrice*qty)-SelecionedGemsQty;
  1383.  
  1384. if(GemAssetQty >= falta && falta > 0){
  1385. toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
  1386. SelecionedGemsQty+=falta;
  1387. }
  1388. else if(GemAssetQty < falta && falta > 0){
  1389. toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
  1390. SelecionedGemsQty+=GemAssetQty;
  1391. }
  1392. }
  1393. makeOffer(source, [].concat.apply([], toSend), toReceive, (GemSet*qty)+":"+(GemPrice*qty), 0, "gems");
  1394. } else {
  1395. Message(source, 'Hey, I have only '+Qty+' sets available that you have yet to craft.');
  1396. if(Qty >= GemSet){
  1397. Message(source, 'Try !buyonegems '+Math.round(Qty/GemSet)+'!');
  1398. } else {
  1399. Message(source, 'Come back later, will you?');
  1400. }
  1401. }
  1402. });
  1403.  
  1404. } else {
  1405. Message(source, 'Sorry, but you need '+(GemPrice*qty)+' gems for this purchase, and you only have '+UserGemsQty+' :(');
  1406. }
  1407.  
  1408. }
  1409. });
  1410. }
  1411.  
  1412. function checkam(source, amount, callback){
  1413. Message(source, "Thanks for asking! Let me calculate...");
  1414. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1415. if(err){ logError(err.message, 'checkam'); Message(source, 'An error has occurred, please try again later.'); return; }
  1416. let response=r.response;
  1417. let player_xp=parseInt(response.player_xp);
  1418.  
  1419. let xpWon=((keySets/keyPrice)*100)*amount;
  1420.  
  1421. let totalExp=player_xp+xpWon;
  1422.  
  1423. let i=parseInt(response.player_level)-1;
  1424. let can=1;
  1425. do {
  1426. i++;
  1427. if(i > config.maxLevelComm){
  1428. Message(source, "I'm not allowed to calculate level above than "+config.maxLevelComm+" :/");
  1429. Message(source, "Sorry, but can you try a lower level?");
  1430. can++;
  1431. break;
  1432. }
  1433. }
  1434. while (getLevelExp(i) <= totalExp);
  1435. if(can==1){callback(response.player_level, (i-1));}
  1436. });
  1437. }
  1438.  
  1439. function checkgam(source, amount, callback){
  1440. Message(source, "Thanks for asking. Let me calculate...");
  1441. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
  1442. if(err){ logError(err.message, 'checkgam'); Message(source, 'An error has occurred. Please try again later.'); return; }
  1443. let response=r.response;
  1444. let player_xp=parseInt(response.player_xp);
  1445.  
  1446. let xpWon=((GemSet/GemPrice)*100)*amount;
  1447.  
  1448. let totalExp=player_xp+xpWon;
  1449.  
  1450. let i=parseInt(response.player_level)-1;
  1451. do {
  1452. i++;
  1453. if(i > config.maxLevelComm){
  1454. Message(source, "I'm not allowed to calculate levels more than "+config.maxLevelComm+" :/");
  1455. Message(source, "Sorry, but can you try a lower level?");
  1456. break;
  1457. }
  1458. }
  1459. while (getLevelExp(i) <= totalExp);
  1460. callback(response.player_level, (i-1));
  1461. });
  1462. }
  1463.  
  1464. function return_CustomerSets(ignore, sid64, callback){
  1465. community.getUserInventoryContents(sid64, 753, 6, true, function(err, items, currency, total){
  1466. if(err){ logError(err.message, 'return_CustomerSets'); callback(err); }
  1467. else if(items.length == 0){ Message('Your steam Inventory is empty!'); callback(null, []); }
  1468. else {
  1469. let customer_sets=[];
  1470. let customer_cards={};
  1471.  
  1472. items.forEach( function(item, i) {
  1473. if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
  1474. let appid=item.market_hash_name.split("-")[0];
  1475. if(!customer_cards[appid]){customer_cards[appid]={};}
  1476. if(!customer_cards[appid][item.market_hash_name]){customer_cards[appid][item.market_hash_name]=[];}
  1477. customer_cards[appid][item.market_hash_name].push(item.id);
  1478. }
  1479. });
  1480.  
  1481. for(let appid in customer_cards){
  1482. if(card_db[appid] && Object.keys(customer_cards[appid]).length == card_db[appid]){
  1483. let max=[];
  1484. for(let card in customer_cards[appid]){ max.push(customer_cards[appid][card].length); }
  1485. max=Math.min.apply( Math, max );
  1486.  
  1487. if(!ignore){
  1488. if((Object.keys(customer_cards[appid]).length+max) > config.maxStock){
  1489. max -= (Object.keys(customer_cards[appid]).length+max)-config.maxStock;
  1490. if ( max < 0) { max = 0; }
  1491. }
  1492. }
  1493.  
  1494. for (let i=0;i<max;i++) {
  1495. let currentCustomerSet=[];
  1496. for(let card in customer_cards[appid]){
  1497. currentCustomerSet.push({ appid:753, contextid:6, amount:1, assetid: customer_cards[appid][card][i] });
  1498. }
  1499. customer_sets.push(currentCustomerSet);
  1500. }
  1501. }
  1502. }
  1503. callback(null, customer_sets);
  1504. }
  1505. });
  1506. }
  1507.  
  1508. function sell(sid64, keys){
  1509. if(CurrentKeys.length < keys){
  1510. Message(sid64, "Sorry, but I don't have enough keys for this request :(");
  1511. } else {
  1512. Message(sid64, "Thanks! Just hold on for a sec..");
  1513. return_CustomerSets(false, sid64, function(err, customer_sets){
  1514. if(!err){
  1515. let requested_sets=parseInt((keys/keyBuyPrice)*keyBuySets);
  1516. if(customer_sets.length >= requested_sets){
  1517. Message(sid64, "Sending your trade offer...");
  1518. let toSend=[];
  1519. let toRequest=[];
  1520. for(let i=0;i<requested_sets;i++){ toRequest.push(customer_sets[i]); }
  1521. for(let i=0;i<keys;i++){ toSend.push({ appid:730, contextid:2, amount:1, assetid: CurrentKeys[i] }); }
  1522. toRequest = [].concat.apply([], toRequest);
  1523. makeOffer(sid64, toSend, toRequest, requested_sets+":"+keys, 1, "key(s)");
  1524. } else {
  1525. Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later.");
  1526. }
  1527. } else {
  1528. Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
  1529. }
  1530. });
  1531. }
  1532. }
  1533.  
  1534. function sellgems(sid64, sets){
  1535. return_GemsQty(function(CurrentGemsQty){
  1536. if(CurrentGemsQty < (sets*GemBuyPrice)){
  1537. Message(sid64, "Sorry, but I don't have enough Gems for this request :(");
  1538. } else {
  1539. Message(sid64, "Thanks, just hold on for a sec...");
  1540. return_CustomerSets(false, sid64, function(err, customer_sets){
  1541. if(!err){
  1542.  
  1543. if(customer_sets.length >= sets){
  1544. Message(sid64, "Sending your trade offer...");
  1545. let toSend=[];
  1546. let toRequest=[];
  1547. let GemsSelected=0;
  1548. for(let i=0;i<sets;i++){ toRequest.push(customer_sets[i]); }
  1549.  
  1550. for(let key in InventoryGemsAssets){
  1551. let GemAssetQty=InventoryGemsAssets[key];
  1552. let GemAsset=key;
  1553. let falta=(sets*GemBuyPrice)-GemsSelected;
  1554.  
  1555. if(GemAssetQty >= falta && falta > 0){
  1556. toSend.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
  1557. GemsSelected+=falta;
  1558. }
  1559. else if(GemAssetQty < falta && falta > 0){
  1560. toSend.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
  1561. GemsSelected+=GemAssetQty;
  1562. }
  1563. }
  1564.  
  1565. toRequest = [].concat.apply([], toRequest);
  1566. makeOffer(sid64, toSend, toRequest, sets+":"+GemsSelected, 1, "gems");
  1567. } else {
  1568. Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later.");
  1569. }
  1570. } else {
  1571. Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
  1572. }
  1573. });
  1574. }
  1575. });
  1576. }
  1577.  
  1578. function selltf(sid64, keys){
  1579. if(CurrentTFKeys.length < keys){
  1580. Message(sid64, "Sorry but i don't have enough keys for this request :(");
  1581. } else {
  1582. Message(sid64, "Thanks, just hold on for a sec...");
  1583. return_CustomerSets(false, sid64, function(err, customer_sets){
  1584. if(!err){
  1585. let requested_sets=parseInt((keys/tfkeyBuyPrice)*tfkeyBuySets);
  1586.  
  1587. if(customer_sets.length >= requested_sets){
  1588. Message(sid64, "Sending your trade offer...");
  1589. let toSend=[];
  1590. let toRequest=[];
  1591. for(let i=0;i<requested_sets;i++){ toRequest.push(customer_sets[i]); }
  1592. for(let i=0;i<keys;i++){ toSend.push({ appid:440, contextid:2, amount:1, assetid: CurrentTFKeys[i] }); }
  1593. toRequest = [].concat.apply([], toRequest);
  1594. makeOffer(sid64, toSend, toRequest, requested_sets+":"+keys, 1, "tf key(s)");
  1595. } else {
  1596. Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later?");
  1597. }
  1598. } else {
  1599. Message(sid64, "For some reason I can't take a look an your inventory. Please try again later :(");
  1600. }
  1601. });
  1602. }
  1603. }
  1604.  
  1605. function sellcheck(sid64){
  1606. Message(sid64, 'Hold on! loading your inventory..');
  1607. return_CustomerSets(false, sid64, function(err, customer_sets){
  1608. if(err){
  1609. Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
  1610. } else {
  1611. let cansell=customer_sets.length;
  1612. if(cansell > 0){
  1613. Message(sid64, "You have "+cansell+" set(s) that I can buy.");
  1614. let r = "I'll pay "+parseInt((cansell/keyBuySets)*keyBuyPrice)+" CS:GO Key(s) for "+(keyBuySets/keyBuyPrice)*parseInt((cansell/keyBuySets)*keyBuyPrice)+" sets or "+(cansell/GemBuySet)*GemBuyPrice+" Gems for "+(GemBuySet/GemBuyPrice)*((cansell/GemBuySet)*GemBuyPrice)+" sets";
  1615. if(config.enableTF){
  1616. r += " or "+parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice)+" TF2 keys for "+(tfkeyBuySets/tfkeyBuyPrice)*parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice)+" sets";
  1617. }
  1618. Message(sid64, r);
  1619. r = "Interested? Try !sell "+parseInt((cansell/keyBuySets)*keyBuyPrice);
  1620. if(config.enableTF){ r+= " or !sellgems "+cansell+" or !selltf "+parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice); }
  1621. Message(sid64,r);
  1622. } else {
  1623. Message(sid64, "Unfortunately you don't have any sets that I can buy. Please try again later.");
  1624. }
  1625. }
  1626. });
  1627. }
  1628.  
  1629. function block(target){
  1630. Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
  1631. client.blockUser(target, function(result){
  1632. if(result == 1){
  1633. Message(config.admin, 'Successfully blocked user '+target+' !');
  1634. } else {
  1635. Message(config.admin, 'Fail!, did you put the right SteamID64 ??');
  1636. }
  1637. })
  1638. }
  1639.  
  1640. function unblock(target){
  1641. Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
  1642. client.unblockUser(target, function(result){
  1643. if(result == 1){
  1644. Message(config.admin, 'Successfully unblocked user '+target+' !');
  1645. } else {
  1646. Message(config.admin, 'Fail!, did you put the right SteamID64 ??');
  1647. }
  1648. })
  1649. }
  1650.  
  1651. function stock(){
  1652. Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
  1653. return_CustomerSets(true, config.admin, function(err, sets){
  1654. if(err){
  1655. Message(config.admin, "Something gone wrong, try again!");
  1656. } else {
  1657. if(sets.length > 0){
  1658. Message(config.admin, "I have found "+sets.length+" sets!, i'll send the trade offer now !");
  1659. makeOffer(config.admin, [], [].concat.apply([], sets), 'admin');
  1660. } else {
  1661. Message(config.admin, "Unfortunately you don't have any sets i can request, please try again later!");
  1662. }
  1663. }
  1664. });
  1665. }
  1666.  
  1667. function restart_(){ log('Restarting..'); restart=1; CurrentKeys=[]; CurrentTFKeys=[]; InventoryCardsGame={}; AvailableSets={}; client.relog(); }
  1668. function shutdown() {
  1669. log('Shutdown requested, bye...');
  1670. try{ client.logOff(); client.once('disconnected', function() { process.exit(1); }); } catch(e) { process.exit(1); }
  1671. setTimeout(function() { process.exit(1); }, 500);
  1672. }
  1673.  
  1674. function nFormat(n){
  1675. if(n.toString().indexOf(".") > -1){
  1676. let i = n.toString().split(".")[0];
  1677. let f = n.toString().split(".")[1].substring(0,1);
  1678. n = parseFloat(i+"."+f);
  1679. }
  1680. return n;
  1681. }
  1682.  
  1683. client.on('friendMessage', function(source, message) {
  1684.  
  1685. storeChatLogData(source, message);
  1686.  
  1687. let Now = new Date().getTime();
  1688. if(LastInteract[source] && Math.floor(Now - LastInteract[source]) < 500){
  1689. if(!Warns[source]){ Warns[source] = 0; }
  1690. Warns[source]++;
  1691. if(Warns[source] == 1){ Message(source, "Please don't spam me :("); }
  1692. if(Warns[source] == 2){ Message(source, "Please don't spam me, next time I'll have to unfriend you!"); }
  1693. if(Warns[source] > 2){
  1694. Message(source, "You're sending to many messages to me, I'm unfriending you, bye!");
  1695. Message(config.admin, "User #"+source+" has been sending to many messages and has been removed from the bot's friendlist!");
  1696. log("User #"+source+" has been sending to many messages and has been removed from the bot's friendlist!");
  1697. client.removeFriend(source);
  1698. }
  1699. return;
  1700. }
  1701.  
  1702. UserInteract(source);
  1703. message = message.toLowerCase();
  1704. if (message == '!admin' && source == config.admin) {
  1705. Message(source, 'Admin Commands:');
  1706. Message(source, '!withdraw [amount] withdraw x CS:GO keys');
  1707. if(config.enableTF){Message(source, '!tfwithdraw [amount] withdraw x TF keys');}
  1708. Message(source, '!gemswithdraw [amount] withdraw x Gems');
  1709. Message(source, '');
  1710. Message(source, "!deposit [amount] - deposit x CS:GO keys");
  1711. if(config.enableTF){Message(source, "!tfdeposit [amount] - deposit x TF keys");}
  1712. Message(source, "!depositgems [amount] - deposit x Gems");
  1713. Message(source, '');
  1714. Message(source, '!block [SteamID64] block user');
  1715. Message(source, '!unblock [SteamID64] unblock user');
  1716. Message(source, '!stock bot will send a trade offer requesting all your available sets to trade');
  1717. Message(source, '');
  1718. Message(source, '!restart restart the bot(logoff and login)');
  1719. Message(source, '!shutdown logoff bot and close application');
  1720. }
  1721. else
  1722. if (message == '!help') {
  1723. Message(source, 'Commands:');
  1724. Message(source, '!owner - shows the profile of my owner. If you have any problems you should contact him!');
  1725. Message(source, '!prices to see our prices');
  1726. Message(source, '');
  1727. Message(source, "!level [your dream level] - calculate how many sets and how many keys it'll cost to desired level");
  1728. Message(source, '!check - show how many sets the bot have available and how much you can craft');
  1729. Message(source, '!check [amount] - show how many sets and which level you would reach for a specific amount of keys');
  1730. if(config.enableTF){Message(source, '!checktf [amount] - show how many sets and which level you would reach for a specific amount of keys');}
  1731. Message(source, '!checkgems [amount] - show how many sets and which level you would reach for a specific amount of gems');
  1732. Message(source, '');
  1733. Message(source, '!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');
  1734. if(config.enableTF){Message(source, '!buytf [amount of TF keys] - use to buy that amount of CS:GO keys for sets you dont have, following the current BOT rate');}
  1735. Message(source, '!buygems [amount of sets] - use to buy that amount of sets for gems, following the current BOT rate');
  1736. Message(source, '!buyany [amount of CS:GO keys] - use to buy that amount of CS:GO keys for any sets, following the current BOT rate');
  1737. Message(source, '');
  1738. Message(source, '!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');
  1739. if(config.enableTF){Message(source, '!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');}
  1740. Message(source, '!buyonegems [amount of sets] - use this if you are a badge collector. sames as !buyone, buy you pay with gems!');
  1741. Message(source, '');
  1742. Message(source, '!sell [amount of CS:GO keys] to sell your sets for CS:GO Key(s)');
  1743. Message(source, '!sellgems [amount of sets] to sell your sets for gems');
  1744. if(config.enableTF){Message(source, '!selltf [amount of TF keys] to sell your sets for TF Key(s)');}
  1745. Message(source, '!sellcheck show information about the set(s) you can sell');
  1746. }
  1747. else if (message.indexOf('!check') > -1 && message.indexOf('!checkgems') == -1 && message.indexOf('!checktf') == -1) {
  1748. if(message.split(" ")[1]){
  1749. let inputs=parseInt(message.split(" ")[1]);
  1750. if(isNaN(inputs) == false){
  1751. if(inputs > 0){
  1752. checkam(source, inputs, function(lvl, desired){
  1753. if(lvl != level){
  1754. Message(source, "With "+inputs+" key(s) you'll get "+parseInt(inputs/keyPrice)*keySets+" set(s) and rearch level "+desired+", interested? try !buy "+parseInt(inputs/keyPrice));
  1755. } else {
  1756. Message(source, "With "+inputs+" key(s) you'll get "+parseInt(inputs/keyPrice)*keySets+" set(s) but still on level "+lvl+", interested? try !buy "+parseInt(inputs/keyPrice));
  1757. }
  1758.  
  1759. });
  1760. } else {
  1761. Message(source, "The amount value should be higher than 0");
  1762. }
  1763. }
  1764. else { Message(source, "Try !check [amount]"); }
  1765. } else {
  1766. check(source);
  1767.  
  1768. }
  1769.  
  1770. }
  1771. else if (message.indexOf('!checktf') > -1 && config.enableTF) {
  1772. let inputs=parseInt(message.split(" ")[1]);
  1773. if(isNaN(inputs) == false){
  1774. if(inputs > 0){
  1775. checkam(source, inputs, function(lvl, desired){
  1776. if(lvl != level){
  1777. Message(source, "With "+inputs+" tf key(s) you'll get "+parseInt(inputs/keyPrice)*keySets+" set(s) and reach level "+desired+", interested? Try !buytf "+parseInt(inputs/keyPrice));
  1778. } else {
  1779. Message(source, "With "+inputs+" tf key(s) you'll get "+parseInt(inputs/keyPrice)*keySets+" set(s) but still be level "+lvl+", interested? Try !buytf "+parseInt(inputs/keyPrice));
  1780. }
  1781. });
  1782. } else {
  1783. Message(source, "The amount value should be higher than 0");
  1784. }
  1785. }
  1786. else { Message(source, "Try !checktf [amount]"); }
  1787. }
  1788. else if (message.indexOf('!checkgems') > -1) {
  1789. let inputs=parseInt(message.split(" ")[1]);
  1790. if(isNaN(inputs) == false){
  1791. if(inputs >= GemPrice){
  1792. checkgam(source, inputs, function(lvl, desired){
  1793. if(lvl != desired){
  1794. Message(source, "With "+inputs+" gems you'll get "+parseInt(inputs/GemPrice)*GemSet+" set(s) and reach level "+desired+", interested? Try !buygems "+parseInt(inputs/GemPrice));
  1795. } else {
  1796. Message(source, "With "+inputs+" gems you'll get "+parseInt(inputs/GemPrice)*GemSet+" set(s) but still be level "+lvl+", interested? Try !buygems "+parseInt(inputs/GemPrice));
  1797. }
  1798. });
  1799. } else {
  1800. Message(source, "The minimum value is "+GemPrice);
  1801. }
  1802. }
  1803. else { Message(source, "Try !checkgems [amount]"); }
  1804. }
  1805. else if (message.indexOf('!block') > -1 && message.indexOf('!unblock') == -1 && source == config.admin) {
  1806. let inputs=(message.split(" ")[1]);
  1807. if(isNaN(parseInt(inputs)) == false){
  1808. block(inputs.toString());
  1809. }
  1810. else { Message(source, "Try !block [SteamID64]"); }
  1811. }
  1812. else if (message.indexOf('!unblock') > -1 && source == config.admin) {
  1813. let inputs=(message.split(" ")[1]);
  1814. if(isNaN(parseInt(inputs)) == false){
  1815. unblock(inputs.toString());
  1816. }
  1817. else { Message(source, "Try !unblock [SteamID64]"); }
  1818. }
  1819. else if (message == '!owner') {
  1820. Message(source, 'There is something wrong?');
  1821. Message(source, 'My SteamProfile: https://steamcommunity.com/profiles/'+config.admin);
  1822. }
  1823. else if (message.indexOf('!buy') > -1 && message.indexOf('!buygems') == -1 && message.indexOf('!buyany') == -1 && message.indexOf('!buyone') == -1 && message.indexOf('!buytf') == -1) {
  1824. if(message == '!buy' ){ Message(source, "Try !buy [amount]"); return; }
  1825. let inputs=parseInt(message.split(" ")[1]);
  1826. if(isNaN(inputs) == false){
  1827. if(inputs < 1) {
  1828. Message(source, "The amount value should be higher than 0");
  1829. } else {
  1830. Message(source, "Hey, thanks!");
  1831. buy(source, inputs);
  1832. }
  1833. }
  1834. else { Message(source, "Try !buy [amount]"); }
  1835. }
  1836. else if (message.indexOf('!buytf') > -1 && config.enableTF) {
  1837. if(message == '!buytf' ){ Message(source, "Try !buytf [amount]"); return; }
  1838. let inputs=parseInt(message.split(" ")[1]);
  1839. if(isNaN(inputs) == false){
  1840. if(inputs < 1) {
  1841. Message(source, "The amount value should be higher than 0");
  1842. } else {
  1843. Message(source, "Hey, thanks!");
  1844. buytf(source, inputs);
  1845. }
  1846. }
  1847. else { Message(source, "Try !buytf [amount]"); }
  1848. } else if(message.indexOf('!buygems') > -1){
  1849. if(message == '!buygems' ){ Message(source, "Try !buygems [amount]"); return; }
  1850. let inputs=parseInt(message.split(" ")[1]);
  1851. if(isNaN(inputs) == false){
  1852. if(inputs < 1) {
  1853. Message(source, "The amount value should be higher than 0");
  1854. } else {
  1855. Message(source, "Hey, thanks!");
  1856. buygems(source, inputs);
  1857. }
  1858. }
  1859. else { Message(source, "Try !buygems [amount]"); }
  1860. } else if(message.indexOf('!sell') > -1 && message.indexOf('!sellcheck') == -1 && message.indexOf('!sellgems') == -1 && message.indexOf('!selltf') == -1){
  1861. if(message == '!sell' ){ Message(source, "Try !sell [amount]"); return; }
  1862. let inputs=parseInt(message.split(" ")[1]);
  1863. if(isNaN(inputs) == false){
  1864. if(inputs < 1) {
  1865. Message(source, "The amount value should be higher than 0");
  1866. } else {
  1867. sell(source, inputs);
  1868. }
  1869. }
  1870. else { Message(source, "Try !sell [amount]"); }
  1871. } else if(message.indexOf('!sellgems') > -1){
  1872. if(message == '!sellgems' ){ Message(source, "Try !sellgems [amount]"); return; }
  1873. let inputs=parseInt(message.split(" ")[1]);
  1874. if(isNaN(inputs) == false){
  1875. if(inputs < 1) {
  1876. Message(source, "The amount value should be higher than 0");
  1877. } else {
  1878. sellgems(source, inputs);
  1879. }
  1880. }
  1881. else { Message(source, "Try !sellgems [amount]"); }
  1882. } else if(message.indexOf('!selltf') > -1 && config.enableTF){
  1883. if(message == '!selltf' ){ Message(source, "Try !selltf [amount]"); return; }
  1884. let inputs=parseInt(message.split(" ")[1]);
  1885. if(isNaN(inputs) == false){
  1886. if(inputs < 1) {
  1887. Message(source, "The amount value should be higher than 0");
  1888. } else {
  1889. selltf(source, inputs);
  1890. }
  1891. }
  1892. else { Message(source, "Try !selltf [amount]"); }
  1893. } else if(message.indexOf('!buyonegems') > -1){
  1894. if(message == '!buyonegems' ){ Message(source, "Try !buyonegems [amount]"); return; }
  1895. let inputs=parseInt(message.split(" ")[1]);
  1896. if(isNaN(inputs) == false){
  1897. if(inputs < 1) {
  1898. Message(source, "The amount value should be higher than 0");
  1899. } else {
  1900. Message(source, "Hey, thanks!");
  1901. buyonegems(source, inputs);
  1902. }
  1903. }
  1904. else { Message(source, "Try !buygems [amount]"); }
  1905. } else if(message.indexOf('!buyone') > -1 && message.indexOf('!buyonegems') == -1 && message.indexOf('!buyonetf') == -1){
  1906. if(message == '!buyone' ){ Message(source, "Try !buyone [amount]"); return; }
  1907. let inputs=parseInt(message.split(" ")[1]);
  1908. if(isNaN(inputs) == false){
  1909. if(inputs < 1) {
  1910. Message(source, "The amount value should be higher than 0");
  1911. } else {
  1912. Message(source, "Hey, thanks!");
  1913. buyone(source, inputs);
  1914. }
  1915. }
  1916. else { Message(source, "Try !buyone [amount]"); }
  1917. } else if(message.indexOf('!buyonetf') > -1 && config.enableTF){
  1918. if(message == '!buyonetf' ){ Message(source, "Try !buyonetf [amount]"); return; }
  1919. let inputs=parseInt(message.split(" ")[1]);
  1920. if(isNaN(inputs) == false){
  1921. if(inputs < 1) {
  1922. Message(source, "The amount value should be higher than 0");
  1923. } else {
  1924. Message(source, "Hey, thanks!");
  1925. buyonetf(source, inputs);
  1926. }
  1927. }
  1928. else { Message(source, "Try !buyonetf [amount]"); }
  1929. } else if(message.indexOf('!buyany') > -1){
  1930. if(message == '!buyany' ){ Message(source, "Try !buyany [amount]"); return; }
  1931. let inputs=parseInt(message.split(" ")[1]);
  1932. if(isNaN(inputs) == false){
  1933. if(inputs < 1) {
  1934. Message(source, "The amount value should be higher than 0");
  1935. } else {
  1936. Message(source, "Hey, thanks!");
  1937. buyany(source, inputs);
  1938. }
  1939. }
  1940. else { Message(source, "Try !buyany [amount]"); }
  1941. }
  1942. else if (message == '!prices') {
  1943. Message(source, 'The current prices are:');
  1944. Message(source, keySets+' set(s) for '+keyPrice+' CS:GO Key(s)');
  1945. if(config.enableTF){Message(source, tfkeySets+' set(s) for '+tfkeyPrice+' TF Key(s)');}
  1946. Message(source, GemPrice+' Gems for '+GemSet+' set(s)');
  1947. Message(source, 'Also, we are buying '+keyBuySets+' set(s) for '+keyBuyPrice+' CS:GO Key(s)');
  1948. if(config.enableTF){Message(source, +tfkeyBuySets+' set(s) for '+tfkeyBuyPrice+' TF Key(s)');}
  1949. Message(source, +GemBuySet+' set(s) for '+GemBuyPrice+' Gems');
  1950. Message(source, 'Type !help for more information!');
  1951. } else if (message == '!sellcheck') {
  1952. sellcheck(source);
  1953. }
  1954. else if (message.indexOf('!level') > -1) {
  1955. if(message == '!level' ){ Message(source, "Try !level [amount]"); return; }
  1956. let inputs=parseInt(message.split(" ")[1]);
  1957. if(isNaN(inputs) == false){
  1958. if(inputs < 1) {
  1959. Message(source, "The amount value should be higher than 0");
  1960. } else if(inputs > config.maxLevelComm){
  1961. Message(source, "I'm not allowed to calculate level above than "+config.maxLevelComm+" :/");
  1962. Message(source, "Sorry but can you try a lower level?");
  1963. } else {
  1964. level(source, inputs);
  1965. }
  1966. }
  1967. else { Message(source, "Try !level 'your dream level'"); }
  1968. }
  1969. else if (message.indexOf('!gemswithdraw') > -1 && source == config.admin) {
  1970. if(message == '!gemswithdraw' ){ Message(source, "Try !gemswithdraw [amount]"); return; }
  1971. let qty=parseInt(message.split(" ")[1]);
  1972. if(isNaN(qty) == false){
  1973. if(qty < 1) {
  1974. Message(source, "The amount value should be higher than 0"); }
  1975. else {
  1976. gemswithdraw(qty);
  1977. }
  1978. } else {
  1979. Message(source, "Try !gemswithdraw [amount]");
  1980. }
  1981. } else if (message.indexOf('!withdraw') > -1 && source == config.admin) {
  1982. if(message == '!withdraw' ){ Message(source, "Try !withdraw [amount]"); return; }
  1983. let qty=parseInt(message.split(" ")[1]);
  1984. if(isNaN(qty) == false){
  1985. if(qty < 1) {
  1986. Message(source, "The amount value should be higher than 0"); }
  1987. else {
  1988. withdraw(qty);
  1989. }
  1990. } else {
  1991. Message(source, "Try !withdraw [amount]");
  1992. }
  1993. } else if (message.indexOf('!tfwithdraw') > -1 && source == config.admin && config.enableTF) {
  1994. if(message == '!tfwithdraw' ){ Message(source, "Try !tfwithdraw [amount]"); return; }
  1995. let qty=parseInt(message.split(" ")[1]);
  1996. if(isNaN(qty) == false){
  1997. if(qty < 1) {
  1998. Message(source, "The amount value should be higher than 0"); }
  1999. else {
  2000. tfwithdraw(qty);
  2001. }
  2002. } else {
  2003. Message(source, "Try !tfwithdraw [amount]");
  2004. }
  2005. } else if (message.indexOf('!deposit') > -1 && source == config.admin && message.indexOf('!depositgems') == -1 && config.enableTF) {
  2006. if(message == '!deposit' ){ Message(source, "Try !deposit [amount]"); return; }
  2007. let qty=parseInt(message.split(" ")[1]);
  2008. if(isNaN(qty) == false){
  2009. if(qty < 1) {
  2010. Message(source, "The amount value should be higher than 0");
  2011. } else {
  2012. deposit(qty)
  2013. }
  2014.  
  2015. } else { Message(source, "Try !deposit [amount]"); }
  2016. } else if (message.indexOf('!tfdeposit') > -1 && source == config.admin && config.enableTF) {
  2017. if(message == '!tfdeposit'){ Message(source, "Try !tfdeposit [amount]"); return; }
  2018. let qty=parseInt(message.split(" ")[1]);
  2019. if(isNaN(qty) == false){
  2020. if(qty < 1) {
  2021. Message(source, "The amount value should be higher than 0");
  2022. } else {
  2023. tfdeposit(qty)
  2024. }
  2025.  
  2026. } else { Message(source, "Try !tfdeposit [amount]"); }
  2027. } else if (message.indexOf('!depositgems') > -1 && source == config.admin && config.enableTF) {
  2028. if(message == '!depositgems' ){ Message(source, "Try !depositgems [amount]"); return; }
  2029. let qty=parseInt(message.split(" ")[1]);
  2030. if(isNaN(qty) == false){
  2031. if(qty < 1) {
  2032. Message(source, "The amount value should be higher than 0");
  2033. } else {
  2034. depositgems(qty);
  2035. }
  2036.  
  2037. } else { Message(source, "Try !depositgems [amount]"); }
  2038. } else if(message.indexOf('!restart') > -1 && source == config.admin){
  2039. Message(source, "I'll be back in a minute!");
  2040. restart_();
  2041. } else if(message.indexOf('!shutdown') > -1 && source == config.admin){
  2042. Message(source, "I going down :(");
  2043. shutdown();
  2044. } else if(message.indexOf('!stock') > -1 && source == config.admin){
  2045. stock();
  2046. } else { Message(source, "Need help? Try !help"); }
  2047. });
  2048.  
  2049. client.on('friendRelationship', function(steamid, relationship) { if (relationship === 2) { addFriend(steamid); } });
  2050.  
  2051. function level (target, qty){
  2052. Message(target, "Thanks for asking! Let me calculate...");
  2053. client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":target, "key":manager.apiKey}, function(err, r){
  2054. if(err){logError(err.message, 'level'); return;}
  2055. let response = r.response;
  2056. if(qty < response.player_level){ Message(target, "You have already rearched level "+qty+"!!"); }
  2057. else {
  2058. let needed=Math.round( ((getLevelExp(parseInt(qty)))-parseInt(response.player_xp))/100 );
  2059. Message(target, "You'll need "+needed+" set(s) to reach level "+qty);
  2060. Message(target, "It'll cost "+nFormat((needed/keySets)*keyPrice)+" key(s) or "+(needed/GemSet)*GemPrice+" Gems");
  2061. Message(target, "Type !prices to see our prices!");
  2062. }
  2063. });
  2064. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement