Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var path = fs = require('fs');
- var request = require('request');
- var mkdirp = require('mkdirp');
- var SteamTotp = require('steam-totp');
- var SteamUser = require('steam-user');
- var SteamCommunity = require('steamcommunity');
- var TradeOfferManager = require('steam-tradeoffer-manager');
- var config=require('./data/config.json');
- var KeysAccepted=require('./data/acceptablekeys.json');
- var client = new SteamUser();
- var loginKey=null;
- var card_db=null;
- var restart=0;
- var debug_mode=0;
- var pp=0;
- 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); } }); }
- if (fs.existsSync(process.cwd()+'/data/loginKey')) { loginKey = fs.readFileSync(process.cwd()+'/data/loginKey').toString(); }
- var community = new SteamCommunity();
- var manager = new TradeOfferManager({ "steam": client, "language": "en", "community":community, "pollInterval": "10000", "cancelTime": "7200000" });
- var CurrentKeys=[];
- var CurrentTFKeys=[];
- var InventoryGemsAssets={};
- var InventoryCardsGame={};
- var AvailableSets={};
- var keyPrice = parseInt(config.SetsPrice.split(':')[1]);
- var keySets = parseInt(config.SetsPrice.split(':')[0]);
- var keyBuyPrice = parseInt(config.BuyPrice.split(':')[1]);
- var keyBuySets = parseInt(config.BuyPrice.split(':')[0]);
- var tfkeyPrice = parseInt(config.TF2Price.split(':')[1]);
- var tfkeySets = parseInt(config.TF2Price.split(':')[0]);
- var tfkeyBuyPrice = parseInt(config.TF2BuyPrice.split(':')[1]);
- var tfkeyBuySets = parseInt(config.TF2BuyPrice.split(':')[0]);
- var GemPrice = parseInt(config.GemsPrice.split(':')[1]);
- var GemSet = parseInt(config.GemsPrice.split(':')[0]);
- var GemBuyPrice = parseInt(config.GemsBuyPrice.split(':')[1]);
- var GemBuySet = parseInt(config.GemsBuyPrice.split(':')[0]);
- var LastInteract={};
- var Warns={};
- function IsJsonString(string, callback) {
- if(string.length){
- string = string.toString();
- let rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
- let meta = {"\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", "\"": "\\\"", "\\": "\\\\"};
- rx_escapable.lastIndex = 0;
- callback(rx_escapable.test(string) ? "\"" + string.replace(rx_escapable, function (a) {
- var c = meta[a];
- callback(typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4));
- }) + "\"" : "\"" + string + "\"");
- } else {
- callback(false);
- }
- }
- if (fs.existsSync(process.cwd()+'/data/usersinteract.json')) {
- IsJsonString(fs.readFileSync(process.cwd()+'/data/usersinteract.json'), function(is){
- if(is){
- LastInteract = JSON.parse(fs.readFileSync(process.cwd()+'/data/usersinteract.json'));
- } else {
- LastInteract = {};
- debug("Tryed to parse a wrong JSON string [data/usersinteract.json]");
- }
- });
- }
- function StoreUsersInteract(){
- createPath(process.cwd()+'/data/', function(){
- let logger = fs.createWriteStream(process.cwd()+'/data/usersinteract.json');
- logger.write(JSON.stringify(LastInteract));
- logger.end();
- });
- }
- function UserInteract(user){ LastInteract[user] = new Date().getTime(); StoreUsersInteract(); }
- function debug(msg, json){
- getCurDateTime(function(time){
- if(json){
- storeDebugData(time+' - > '+JSON.stringify(msg)+'\r\n');
- if(debug_mode){console.log(time+' DEBUG - > '+JSON.stringify(msg));}
- } else {
- storeDebugData(time+' - > '+msg+'\r\n');
- if(debug_mode){console.log(time+' DEBUG - > '+msg);}
- }
- });
- }
- function storeDebugData(data){
- createPath(process.cwd()+'/history/', function(){
- let logger = fs.createWriteStream(process.cwd()+'/history/debug.txt', { flags: 'a' });
- logger.write(data);
- logger.end();
- });
- }
- function storeChatLogData(source, message, me){
- getCurDateTime(function(time){
- let filePath=process.cwd()+"/history/chat/"+time.split(" ")[0];
- createPath(filePath, function(){
- let chatlog = fs.createWriteStream(filePath+'/'+source+'.txt', { flags: 'a' });
- if(me){
- chatlog.write('['+time.split(" ")[1]+'] Bot: '+message+'\r\n');
- } else {
- chatlog.write('['+time.split(" ")[1]+'] User: '+message+'\r\n');
- }
- chatlog.end();
- });
- });
- }
- function getCurDateTime(callback){
- let m = new Date();
- let dateString =
- m.getFullYear() + "-" +
- ("0" + (m.getMonth()+1)).slice(-2) + "-" +
- ("0" + m.getDate()).slice(-2) + " " +
- ("0" + m.getHours()).slice(-2) + ":" +
- ("0" + m.getMinutes()).slice(-2) + ":" +
- ("0" + m.getSeconds()).slice(-2);
- callback(dateString);
- }
- function log(data){
- getCurDateTime(function(time){
- let filePath=process.cwd()+"/history/log";
- console.log(time+' INFO - > '+data);
- createPath(filePath, function(){
- let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
- chatlog.write('['+time.split(" ")[1]+'] '+data+'\r\n');
- chatlog.end();
- });
- });
- }
- function logError(data, event){
- getCurDateTime(function(time){
- let filePath=process.cwd()+"/history/error";
- console.log(time+' ERROR - > '+event+': '+data);
- createPath(filePath, function(){
- let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
- chatlog.write('['+time.split(" ")[1]+'] '+event+': '+data+'\r\n');
- chatlog.end();
- });
- });
- }
- function logTrade(data){
- getCurDateTime(function(time){
- let filePath=process.cwd()+"/history/trade";
- console.log(time+' TRADE - > '+data);
- createPath(filePath, function(){
- let chatlog = fs.createWriteStream(filePath+'/'+time.split(" ")[0]+'.txt', { flags: 'a' });
- chatlog.write('['+time.split(" ")[1]+'] '+data+'\r\n');
- chatlog.end();
- });
- });
- }
- createPath(process.cwd()+'/data/', function(){
- if (fs.existsSync(process.cwd()+'/data/poll.json')) {
- IsJsonString(fs.readFileSync(process.cwd()+'/data/poll.json'), function(is){
- if(is){
- manager.pollData = JSON.parse(fs.readFileSync(process.cwd()+'/data/poll.json'));
- } else {
- debug("Tryed to parse a wrong JSON string", 'data/poll.json');
- }
- });
- }
- });
- function createPath(filePath, callback) {
- if (fs.existsSync(filePath)) { callback(); return; }
- mkdirp.sync(filePath, function (err) {
- if (err) {
- logError(err, "createPath: "+filePath);
- return;
- }
- });
- callback();
- }
- function Message(steamid, msg){ client.chatMessage(steamid, msg); storeChatLogData(steamid, msg, true); }
- log('Coneccting to Steam..');
- function getLogOn(callback){
- SteamTotp.getTimeOffset(function(err, offset, latency) {
- callback({
- "accountName": config.username,
- "password": config.password,
- "twoFactorCode": SteamTotp.generateAuthCode(config.sharedse, offset),
- "rememberPassword":true,
- "promptSteamGuardCode": false/*,
- "loginKey":loginKey*/
- });
- });
- }
- getLogOn(function(logindata){ client.logOn(logindata); });
- setInterval(function(){
- log("Updating sets Database..");
- updateTradingCardDb(function(){ log("Sets Database up to date!"); });
- }, 1000*60*60*24);
- setInterval(function(){
- let Now = new Date().getTime();
- for(let user in LastInteract){
- if(user != config.admin && Math.floor(Now - LastInteract[user]) > 1000*60*60*24*config.maxDays){
- Message(user, "Hey, it's been a while since you've been active...");
- Message(user, "I'll unfriend you, but if you need anything, just add me again :)");
- Message(user, "Hope I'll see you again, bye!");
- Message(config.admin, "User #"+user+" has have been inactive for a long time and has been removed from bot friendlist!");
- log("User #"+user+" has have been inactive for a long time and has been removed from bot friendlist!");
- client.removeFriend(user);
- delete LastInteract[user];
- StoreUsersInteract();
- }
- }
- }, 1000*60*60);
- client.on('loggedOn', function(details) {
- if(config.changeBotName) { client.setPersona(SteamUser.EPersonaState.Online, config.changeBotName); }
- else { client.setPersona(SteamUser.EPersonaState.Online); }
- log("Logging to SteamCommunity..");
- if(restart){ client.webLogOn(); restart=0;}
- });
- client.on('steamGuard', function(domain, callback) {
- //console.log("Steam Guard code needed from email ending in " + domain);
- SteamTotp.getTimeOffset(function(err, offset, latency) {
- let code = SteamUser.generateAuthCode(config.sharedse, offset);
- callback(code);
- });
- });
- if(debug_mode){ community.on('debug', function(details) {debug(details);}); manager.on('debug', function(details) {debug(details);}); }
- client.on('webSession', function(sessionID, newCookie) {
- log("Connected!");
- if(card_db){
- loadmanager(newCookie);
- } else {
- log("Loading sets Database...");
- updateTradingCardDb(function(){ loadmanager(newCookie); });
- }
- });
- function loadmanager(newCookie){
- log('Loading APIKey...');
- manager.setCookies(newCookie, function(err){
- if(err){ logError(err.message, "webSession"); return; }
- log('Got APIKey: '+manager.apiKey);
- community.startConfirmationChecker(15000, config.identity);
- LoadInventories();
- setInterval(function(){checkSteamLogged();}, 1000*60*4);
- });
- }
- client.on('loginKey', function(key) { fs.writeFile(process.cwd()+'/data/loginKey', key, function() {}); loginKey=key; });
- client.on('disconnected', function(r, msg) { logError(""+msg, ""+r); });
- community.on('sessionExpired', function(err) {
- if(err){ logError(err.message, 'sessionExpired'); }
- client.setPersona(SteamUser.EPersonaState.Offline);
- client.webLogOn();
- });
- community.on('confirmationAccepted', function(conf) {
- debug("confirmationAccepted type "+conf.type+" triggered #"+conf.id);
- if(conf.type == 2){
- debug("Searching for details of #"+conf.creator);
- manager.getOffer(conf.creator, function(err, myOffer){
- if(err){
- logError(err.message, 'confirmationAccepted');
- } else {
- if(myOffer.isOurOffer){
- Message(myOffer.partner, "Trade offer confirmed!");
- Message(myOffer.partner, "Click here to accept it: https://www.steamcommunity.com/tradeoffer/"+conf.creator);
- logTrade("Successfully sent a trade offer for "+myOffer.partner);
- } else {
- debug("#"+conf.creator+" with confirmation id #"+conf.id+" isnt a trade offer sended by bot.");
- }
- }
- });
- }
- });
- function checkFriendRequests(){ for(let user in client.myFriends){ if(client.myFriends[user] == 2){ addFriend(user); } } }
- function addFriend(user){
- client.addFriend(user, function(err, result){
- if(err){ logError(err.message, 'checkFriendRequests'); }
- inviteToGroup(user);
- Message(user, 'Hi '+result+', thanks for add me!');
- Message(user, 'Type !help for instructions.');
- UserInteract(user);
- });
- }
- function checkSteamLogged() {
- community.loggedIn( function (err, loggedIn, familyView) {
- if (err) {
- logError(err.message, 'community.loggedIn');
- setTimeout(checkSteamLogged, 1000*30); // check again in 4 min
- } else if ( ! loggedIn ) {
- debug("WebLogin check : NOT LOGGED IN !");
- client.setPersona(SteamUser.EPersonaState.Offline);
- client.webLogOn();
- } else {
- debug("WebLogin check : Already logged in !");
- client.setPersona(SteamUser.EPersonaState.LookingToTrade);
- }
- });
- }
- function isInventoryloaded(callback){
- if(Object.keys(InventoryCardsGame).length > 0) {callback(1);}
- else if(CurrentKeys.length > 0) {callback(1);}
- else if(CurrentTFKeys.length > 0) {callback(1);}
- else { callback(0); }
- }
- createPath(process.cwd()+'/data/', function(){ manager.on('pollData', function(pollData) { fs.writeFile(process.cwd()+'/data/poll.json', JSON.stringify(pollData), function() {}); }); });
- client.on('error', function(e) { logError(e.message, "client error"); });
- function inviteToGroup(target){
- if(config.group){
- community.inviteUserToGroup(target, config.group, function (err) {
- if(err)
- logError(err.message, "inviteToGroup");
- });
- }
- }
- function gemswithdraw (qty){
- let GemsSelected=0;
- let toGive=[];
- Message(config.admin, "Hey owner!, please wait a few seconds and I'll quickly proccess your request!");
- return_GemsQty(function(GemsInInventorySelected){
- if(GemsInInventorySelected >= qty) {
- for(let key in InventoryGemsAssets){
- let GemAssetQty=InventoryGemsAssets[key];
- let GemAsset=key;
- let falta=qty-GemsSelected;
- if(GemAssetQty >= falta && falta > 0){
- toGive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
- GemsSelected+=falta;
- }
- else if(GemAssetQty < falta && falta > 0){
- toGive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
- GemsSelected+=GemAssetQty;
- }
- }
- makeOffer(config.admin, toGive, [], 'admin');
- } else {
- Message(config.admin, "I only have "+GemsInInventorySelected+" Gems on my inventory, try !gemswithdraw "+GemsInInventorySelected)
- }
- });
- }
- function tfwithdraw (qty){
- Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
- if(CurrentTFKeys.length > 0){
- if(qty <= CurrentTFKeys.length){
- log('Admin has requested a withdraw of '+qty+' TF Key(s)!');
- let send=[];
- for(let b=0;b<CurrentTFKeys.length;b++){
- send.push({ appid:440, contextid:2, amount:1, assetid: CurrentTFKeys[b] });
- if(send.length == qty){
- makeOffer(config.admin, send, [], 'admin');
- break;
- }
- }
- } else {
- Message(config.admin, 'Found only '+CurrentTFKeys.length+' Keys, try !tfwithdraw '+CurrentTFKeys.length);
- //log('Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
- }
- } else {
- Message(config.admin, "I don't have any TF keys on my inventory ;--;");
- }
- }
- function withdraw (qty){
- Message(config.admin, "Hey owner, please wait a few seconds and i'll quickly proccess your request!");
- if(CurrentKeys.length > 0){
- if(qty <= CurrentKeys.length){
- log('Admin has requested a withdraw of '+qty+' CS:GO Key(s)!');
- let send=[];
- for(let b=0;b<CurrentKeys.length;b++){
- send.push({ appid:730, contextid:2, amount:1, assetid: CurrentKeys[b] });
- if(send.length == qty){
- makeOffer(config.admin, send, [], 'admin');
- break;
- }
- }
- } else {
- Message(config.admin, 'Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
- //log('Found only '+CurrentKeys.length+' Keys, try !withdraw '+CurrentKeys.length);
- }
- } else {
- Message(config.admin, "Owner don't have any CS:GO keys on my inventory ;--;");
- }
- }
- function pushNewKey(item){ if(CurrentKeys.indexOf(item.id) == -1) { CurrentKeys.push(item.id); } }
- function RemoveKey(item){ if(CurrentKeys.indexOf(item) > -1) { CurrentKeys.splice(CurrentKeys.indexOf(item), 1); } }
- function pushNewTFKey(item){ if(CurrentTFKeys.indexOf(item.id) == -1) { CurrentTFKeys.push(item.id); } }
- function RemoveTFKey(item){ if(CurrentTFKeys.indexOf(item) > -1) { CurrentTFKeys.splice(CurrentTFKeys.indexOf(item), 1); } }
- function loadCSGOInventory(callback){ CurrentKeys=[]; log('Loading CS:GO Keys..');
- community.getUserInventoryContents(client.steamID, 730, 2, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'loadCSGOInventory'); }
- else if(items.length == 0){ log('CS:GO Inventory is empty!'); if(callback) { callback(); } }
- else {
- items.forEach(function(item, i) { if(KeysAccepted.indexOf(item.market_hash_name)> -1){ pushNewKey(item); } });
- log(CurrentKeys.length+" CS:GO Key(s) on Inventory!");
- if(callback) { callback(); }
- }
- });
- }
- function loadTF2Inventory(callback){ CurrentTFKeys=[]; log('Loading TF Keys..');
- community.getUserInventoryContents(client.steamID, 440, 2, true, function(err, items, currency, total){
- 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'); } }
- else if(items.length == 0){ log('TF2 Inventory is empty!'); if(callback) { callback(); } }
- else {
- items.forEach(function(item, i) { if(item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){ pushNewTFKey(item); } });
- log(CurrentTFKeys.length+" TF Key(s) on Inventory!");
- if(callback) { callback(); }
- }
- });
- }
- function LoadInventories(){
- isInventoryloaded(function(isInvLoaded){
- if(!isInvLoaded) {
- if(config.enableTF){
- loadCSGOInventory(function(){
- loadTF2Inventory(loadInventory);
- });
- } else {
- loadCSGOInventory(loadInventory);
- }
- } else {
- client.setPersona(SteamUser.EPersonaState.LookingToTrade);
- playPrices();
- }
- });
- }
- function updateTradingCardDb(callback){
- request("http://cdn.steam.tools/data/set_data.json", { json: true }, (err, r, body) => {
- if (!err && r.statusCode == 200 && body) {
- let data = {};
- body.sets.forEach(function(set, index){ data[set.appid] = set.true_count; });
- let non_market=require('./data/nonmarketable_db.json');
- card_db=Object.assign(data, non_market);
- 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();} });
- } else {
- logError('Error in load Sets DB! Reason: '+err.message, 'updateTradingCardDb');
- }
- });
- }
- function return_GemsQty(callback){
- let qty=0;
- for(let key in InventoryGemsAssets){ qty+=InventoryGemsAssets[key]; }
- callback(qty);
- }
- function getAllCards(callback){
- let cards=[];
- for (let appid in InventoryCardsGame) {
- for (let card in InventoryCardsGame[appid]) {
- InventoryCardsGame[appid][card].forEach(function(assetid, index){
- //cards.push({name:InventoryCardsGame[appid][card], id:assetid});
- cards.push(assetid);
- });
- }
- }
- callback(cards);
- }
- function return_AvailableSets(callback){
- let sets=0;
- for(let key in AvailableSets){ sets+=AvailableSets[key].length; }
- callback(sets);
- }
- function checkGameSet(gameApp, callback){
- debug("Looking sets for #"+gameApp);
- if(card_db[gameApp]){
- if(Object.keys(InventoryCardsGame[gameApp]).length == card_db[gameApp]){
- let max=[];
- for(let key in InventoryCardsGame[gameApp]){ max.push(InventoryCardsGame[gameApp][key].length); }
- max=Math.min.apply( Math, max );
- for (let i=0;i<max;i++) {
- let currentSet=[];
- for(let key in InventoryCardsGame[gameApp]){ currentSet.push({ appid:753, contextid:6, amount:1, assetid: InventoryCardsGame[gameApp][key][i] }); }
- if(!AvailableSets[gameApp]){AvailableSets[gameApp]=[];}
- AvailableSets[gameApp].push(currentSet);
- }
- debug("Successfully checked #"+gameApp);
- callback();
- } else {
- debug("Successfully checked #"+gameApp);
- callback();
- }
- } else {
- debug("sets database doesnt have data about #"+gameApp);
- callback();
- }
- }
- function checkGamesSetInfo(appIds, callback){
- let checked=0;
- appIds.forEach(function(appId, i){ checkGameSet(appId , function(){checked++;}); });
- let c = setInterval(function(){ if(checked == appIds.length){ clearInterval(c); callback(); } }, 800);
- }
- function getAllGames(callback){ callback(Object.keys(InventoryCardsGame)); }
- function pushGems(item, amount){
- if(!InventoryGemsAssets[item.id]){ InventoryGemsAssets[item.id] = 0; }
- InventoryGemsAssets[item.id] += amount;
- }
- function getInventoryGemsQty(callback){
- let totalGems=0;
- for (let _key in InventoryGemsAssets){
- totalGems += parseInt(InventoryGemsAssets[_key]);
- }
- callback(totalGems);
- }
- function removeGems(id, qty){
- if(InventoryGemsAssets[id]){
- InventoryGemsAssets[id] -= qty;
- if(InventoryGemsAssets[id] < 0){ delete InventoryGemsAssets[id]; }
- } else {
- logError('Trying to remove gems out of bot inventory!', 'removeGems')
- }
- }
- function handleAddNewItem(item, amount){
- if(config.enableTF && item.appid == 440 && item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
- pushNewTFKey(item);
- } else if(item.appid == 730 && KeysAccepted.indexOf(item.market_hash_name) > -1){
- pushNewKey(item);
- } else if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1){
- pushGems(item, amount);
- } else if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
- pushInventoryCard(item);
- }
- }
- function handleRemoveItem(item, amount){
- if(config.enableTF && item.appid == 440 && item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
- RemoveTFKey(item.id);
- } else if(item.appid == 730 && KeysAccepted.indexOf(item.market_hash_name) > -1){
- RemoveKey(item.id);
- } else if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1){
- removeGems(item.id, amount);
- } else if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
- removeInventoryCard(item);
- }
- }
- function pushInventoryCard(item){
- let appid=item.market_hash_name.split("-")[0];
- if(appid != 753){
- if(!InventoryCardsGame[appid]){ InventoryCardsGame[appid] = {}; }
- if(!InventoryCardsGame[appid][item.market_hash_name]){ InventoryCardsGame[appid][item.market_hash_name] = []; }
- if(InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id) == -1){
- InventoryCardsGame[appid][item.market_hash_name].push(item.id);
- }
- }
- }
- function removeInventoryCard(item){
- let appid=item.market_hash_name.split("-")[0];
- if(appid != 753){
- if(InventoryCardsGame[appid] && InventoryCardsGame[appid][item.market_hash_name] && InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id) > -1){
- InventoryCardsGame[appid][item.market_hash_name].splice(InventoryCardsGame[appid][item.market_hash_name].indexOf(item.id), 1);
- } else {
- logError('Trying to remove an inventory card out of bot inventory!', 'removeInventoryCard')
- }
- }
- }
- function makeOffer(target, itemsFromMe, itemsFromThem, details, type, currency){
- debug("Creating trade offer for #"+target+" with "+itemsFromMe.length+" items to send and "+itemsFromThem.length+" items to receive");
- let offer = manager.createOffer(target);
- let addMyItemsCount = offer.addMyItems(itemsFromMe);
- let addTheirItemsCount = offer.addTheirItems(itemsFromThem);
- offer.data('cancelTime', 'undefined');
- offer.data('SellInfo', details);
- offer.data('SellInfoType', type);
- offer.data('SellInfoCurrency', currency);
- offer.getUserDetails(function(err, them, me){
- if(err){
- if(err.message.toLowerCase().indexOf("is not available to trade. more information will be") > -1){
- Message(target, "You're unavailable to trade, please try again later :)");
- logTrade("#"+target+" is unavailable to trade");
- } else { logError(err.message, 'makeOffer'); }
- return;
- }
- if(them.escrowDays){
- Message(target, "Sorry but I can't trade if you have trade hold!");
- Message(target, "Come back later please?");
- } else {
- debug("Sending offer for #"+target);
- offer.send(function(err, status) {
- debug("Offer #"+offer.id+" status: "+status+", "+err);
- if (err){ if(err.message.toLowerCase().indexOf("sent too many trade offers") > 1){
- 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 :)");
- } else {
- logError(err.message, 'makeOffer');
- Message(target, "Some error has occurred, please try again later?");
- } } else {
- manager.getOffer(offer.id, function(err, myOffer){
- if(err){logError(err.message, 'makeOffer');return;}
- if(addMyItemsCount != myOffer.itemsToGive.length){
- logError('Cant add itemsFromMe, some item is missing in my inventory!', 'makeOffer');
- Message(target, "Some error has occurred, please try again later.");
- myOffer.cancel();
- } else if(addTheirItemsCount != myOffer.itemsToReceive.length){
- logError('Cant add itemsFromThem, some item is missing in my inventory!', 'makeOffer');
- Message(target, "Some error has occurred, please try again later.");
- myOffer.cancel();
- } else if (status == 'pending') {
- Message(target, "Trade offer sent! Confirming it..");
- logTrade("Sended a trade offer for "+target+", waiting for mobile confirmation.");
- community.checkConfirmations();
- } else {
- Message(target, "Trade offer sent!!");
- Message(target, "Click here to accept it: https://www.steamcommunity.com/tradeoffer/"+offer.id);
- logTrade("Successfully sent a trade offer for "+target);
- }
- });
- }
- });
- }
- });
- }
- function playPrices(){
- return_AvailableSets(function(havesets){
- let g = "[H] "+havesets+" sets - "+keySets+":"+keyPrice+" CS:GO Key / "+GemSet+":"+GemPrice+" Gems"; if(config.enableTF){ g +=" / "+tfkeySets+":"+tfkeyPrice+" TF Key!"; }
- client.gamesPlayed(g);
- });
- if(!pp){ pp++; setTimeout(function(){pp=0;playPrices()}, 1000*60*5); }
- }
- function online(){ client.setPersona(SteamUser.EPersonaState.LookingToTrade); playPrices(); checkFriendRequests(); return_AvailableSets(function(founded){ log('Found '+founded+' card sets!'); });}
- function loadInventory(){
- log('Loading Steam Inventory..');
- community.getUserInventoryContents(client.steamID, 753, 6, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'loadInventory'); loadInventory(); }
- else if(items.length == 0){ log('Steam Inventory is empty!'); online();}
- else {
- items.forEach( function(item, i) { handleAddNewItem(item, item.amount); });
- getInventoryGemsQty(function(totalGems){
- getAllCards(function(cards){
- let loginfo='Found '+cards.length+' cards';
- if(totalGems > 0){
- loginfo +=', and '+totalGems+' Gems on inventory!';
- } else {
- loginfo +=' on inventory!';
- }
- log(loginfo);
- });
- });
- debug("Looking for sets..");
- getAllGames(function(games){ checkGamesSetInfo(games, function(){online();}); });
- }
- });
- }
- function getLevelExp(level){
- let inicial=100;
- let lastexp=0;
- let level_exp=[];
- for(let i=1;i<level+1;i++){
- let exp=lastexp+inicial;
- lastexp=exp;
- level_exp.push( { "value":exp } );
- if(i==level){ return exp; }
- if(!((i/10) % 1 != 0 && !isNaN((i/10) % 1))){ inicial +=100; }
- }
- }
- manager.on('newOffer', function(offer) {
- var partner=offer.partner.getSteamID64();
- if(partner==config.admin){ logTrade("New offer from admin!");
- offer.accept(function(err, res) {
- if (err) { Message(config.admin, "Unable to accept offer: " + err.message); logTrade("Unable to accept admin offer: " + err.message); }
- else { if(res == "pending"){ community.checkConfirmations(); } else { logTrade("Admin Offer accepeted!"); } }
- });
- }
- });
- manager.on('receivedOfferChanged', function(offer, oldState) {
- debug("receivedOfferChanged Triggered at #"+offer.id+", state: "+offer.state+", oldState: "+oldState)
- if(offer.state == 3 ){
- //Handle gived items
- offer.itemsToGive.forEach(function(item, index){ handleRemoveItem(item, item.amount); });
- //Handle received items
- offer.getReceivedItems(function(err, items) { if(err){logError(err.message, 'receivedOfferChanged');} else {
- items.forEach(function(item, index){ handleAddNewItem(item, item.amount); });
- //Update CardSets
- log('Updating sets database..');
- getAllGames(function(games){ AvailableSets={}; checkGamesSetInfo(games, function(){ playPrices(); }); });
- } });
- }
- });
- manager.on('sentOfferChanged', function(offer, oldState) {
- debug("sentOfferChanged Triggered at #"+offer.id+", state: "+offer.state+", oldState: "+oldState)
- if(offer.state == 3 ){
- //Handle gived items
- offer.itemsToGive.forEach(function(item, index){ handleRemoveItem(item, item.amount); });
- //Handle received items
- offer.getReceivedItems(function(err, items) { if(err){logError(err.message, 'sentOfferChanged');} else {
- items.forEach(function(item, index){ handleAddNewItem(item, item.amount); });
- //Update CardSets
- log('Updating sets database..');
- getAllGames(function(games){ AvailableSets={}; checkGamesSetInfo(games, function(){ playPrices(); }); });
- } });
- if(config.ThanksM && offer.data('SellInfo') != 'admin'){
- community.postUserComment(offer.partner.toString(), config.ThanksM);
- Message(offer.partner, "Thanks for using my Level UP service!");
- Message(offer.partner, "Can you leave a +Rep on my profile? Thanks!");
- }
- inviteToGroup(offer.partner.getSteamID64());
- if(offer.data('SellInfoType') != null){
- if(offer.data('SellInfoType') == 0){
- 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')+'!');
- Message(config.admin, "Hey!, i just have selled "+offer.data('SellInfo').split(":")[0]+" Set(s) for "+offer.data('SellInfo').split(":")[1]+" "+offer.data('SellInfoCurrency')+"!");
- } else if(offer.data('SellInfoType') == 1){
- 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')+'!');
- Message(config.admin, "Hey!, i just have buyed "+offer.data('SellInfo').split(":")[0]+" Set(s) for "+offer.data('SellInfo').split(":")[1]+" "+offer.data('SellInfoCurrency')+"!");
- }
- }
- }
- });
- function tfdeposit(qty){
- let cath=[]; let sended=0;
- Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
- community.getUserInventoryContents(config.admin, 440, 2, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'tfdeposit'); Message(config.admin, 'An error has occurred, please try again later.'); return; }
- if(items.length > 0){
- for(let a=0;a<items.length;a++){
- if(items[a].market_hash_name && items[a].market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){
- cath.push({ appid:440, contextid:2, amount:1, assetid: items[a].id });
- }
- if(cath.length == qty ){
- if(sended == 0){ sended++; makeOffer(config.admin, [], cath, 'admin'); }
- break;
- }
- }
- }
- if(sended == 0 ){
- if(cath.length > 0){ Message(config.admin, 'Found only '+cath.length+' tf keys in owner inventory, try !tfdeposit '+cath.length); }
- else { Message(config.admin, 'Owner dont have any TF Keys available to trade...'); }
- }
- });
- }
- function deposit(qty){
- let cath=[]; let sended=0;
- Message(config.admin, "Hey owner, please wait a few seconds and I'll quickly proccess your request!");
- community.getUserInventoryContents(config.admin, 730, 2, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'deposit'); Message(config.admin, 'An error has occurred, please try again later.'); return; }
- if(items.length > 0){
- for(let a=0;a<items.length;a++){
- if(items[a].market_hash_name && KeysAccepted.indexOf(items[a].market_hash_name) > -1){
- cath.push({ appid:730, contextid:2, amount:1, assetid: items[a].id });
- }
- if(cath.length == qty ){
- if(sended == 0){ sended++; makeOffer(config.admin, [], cath, 'admin'); }
- break;
- }
- }
- }
- if(sended == 0 ){
- if(cath.length > 0){ Message(config.admin, 'Found only '+cath.length+' keys in owner inventory, try !deposit '+cath.length); }
- else { Message(config.admin, 'Owner currently dont have any CS:GO Keys available to trade...'); }
- }
- });
- }
- //Deposit Gems
- function depositgems(qty){
- let cath=[]; let sended=0;
- Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
- community.getUserInventoryContents(config.admin, 753, 6, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'deposit'); Message(config.admin, 'Something wrong has happened, please try again later .. ?'); return; }
- let UserGemsAssets={};
- let UserGemsQty=0;
- items.forEach(function(item, index){
- if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
- UserGemsAssets[item.id]=item.amount;
- UserGemsQty+=parseInt(item.amount);
- }
- });
- if(UserGemsQty > 0){
- if(UserGemsQty < qty){
- Message(config.admin, 'Found only '+UserGemsQty+' gems in owner inventory, try !depositgems '+UserGemsQty);
- }
- else {
- let SelecionedGemsQty=0;
- let toReceive=[];
- for(let key in UserGemsAssets){
- let GemAssetQty=UserGemsAssets[key];
- let GemAsset=key;
- let falta=qty-SelecionedGemsQty;
- if(GemAssetQty >= falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
- SelecionedGemsQty+=falta;
- }
- else if(GemAssetQty < falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
- SelecionedGemsQty+=GemAssetQty;
- }
- }
- makeOffer(config.admin, [], toReceive, 'admin');
- }
- } else { Message(config.admin, 'Owner dont have any Gems available to trade..'); }
- });
- }
- function check(source){
- if(Object.keys(AvailableSets).length > 0) {
- Message(source, "Thanks for asking! Let me check your badges.");
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- if(err){ logError(err.message, 'check'); Message(source, 'Something wrong has happened, please try again later .. ?'); return; }
- let Qty=0;
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = 5-parseInt(lvl);
- }
- }
- for(let appid in AvailableSets){
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
- Qty+=available_qty;
- }
- if(Qty > 0){
- Message(source, 'I currently have '+Qty+' set(s) that you have yet to craft.');
- 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";
- if(config.enableTF){
- r += " or "+nFormat((Qty/tfkeySets)*tfkeyPrice)+" TF Key(s)!"
- }
- Message(source, r);
- r = 'Interested? Try !buy '+parseInt(Qty/keySets)*keyPrice+', or !buygems '+Qty;
- if(config.enableTF){
- r += ' or !buytf '+parseInt(Qty/tfkeySets)*tfkeyPrice;
- }
- Message(source, r);
- if(CurrentKeys.length > 0){ Message(source, 'Wanna buy my keys? Try !sellcheck'); }
- } else {
- Message(source, 'Unfortunately I do not have any sets that you have yet to craft :/');
- Message(source, 'Come back later, will you?');
- if(CurrentKeys.length > 0){ Message(source, 'If you want to buy my keys try !sellcheck!'); }
- }
- });
- } else {
- Message(source, 'Unfortunately I dont have any set that you have yet to craft.');
- Message(source, 'Come back later, will you?');
- Message(source, 'If you want to buy my keys try !sell !');
- }
- }
- function return_CustomerCSGOKeys(sid64, callback){
- community.getUserInventoryContents(sid64, 730, 2, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'return_CustomerCSGOKeys'); callback(err); }
- else if(items.length == 0){ callback(null, []); }
- else {
- let KeysFromThemAsset=[];
- items.forEach(function(item, d){ if(KeysAccepted.indexOf(item.market_hash_name) > -1){ KeysFromThemAsset.push(item.assetid); } });
- callback(null, KeysFromThemAsset);
- }
- });
- }
- function return_CustomerTFKeys(sid64, callback){
- community.getUserInventoryContents(sid64, 440, 2, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'return_CustomerTFKeys'); callback(err); }
- else if(items.length == 0){ callback(null, []); }
- else {
- let KeysFromThemAsset=[];
- items.forEach(function(item, d){ if(item.market_hash_name.indexOf("Mann Co. Supply Crate Key") > -1){ KeysFromThemAsset.push(item.assetid); } });
- callback(null, KeysFromThemAsset);
- }
- });
- }
- function buygems(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- community.getUserInventoryContents(source, 753, 6, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'buygems'); Message(source, 'An error has occurred, please try again later.'); }
- else if(items.length == 0){ Message(source, 'Your Steam Inventory is empty :/'); }
- else {
- let UserGemsAssets={};
- let UserGemsQty=0;
- items.forEach(function(item, index){
- if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
- if(!UserGemsAssets[item.id]){UserGemsAssets[item.id] = 0;}
- UserGemsAssets[item.id] += parseInt(item.amount);
- UserGemsQty+=parseInt(item.amount);
- }
- });
- if(UserGemsQty >= (GemPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = 5-parseInt(lvl);
- }
- }
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (GemSet*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (GemSet*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (GemSet*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (GemSet*qty)){
- let SelecionedGemsQty=0;
- let toReceive=[];
- let added=0;
- for(let key in UserGemsAssets){
- let GemAssetQty=UserGemsAssets[key];
- let GemAsset=key;
- let falta=(GemPrice*qty)-SelecionedGemsQty;
- if(GemAssetQty >= falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
- SelecionedGemsQty+=falta;
- }
- else if(GemAssetQty < falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
- SelecionedGemsQty+=GemAssetQty;
- }
- }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (GemSet*qty)+":"+(GemPrice*qty), 0, "gems");
- } else {
- Message(source, "Sorry, since you're a badge collector, I have only '+Qty+' sets available that you have yet to craft.");
- if(Qty >= GemSet){
- Message(source, 'Try !buygems '+Math.round(Qty/GemSet)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(GemPrice*qty)+' gems for this purchae and you only have '+UserGemsQty+' :(');
- }
- }
- });
- }
- function buyany(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
- if(err){
- Message(source, "For some reason I can't load your cs:go inventory. please try again later :(");
- } else {
- if(KeysFromThemAsset.length >= (keyPrice*qty)){
- let Qty=0;
- let toSend=[];
- let badge={};
- for(let appid in AvailableSets){
- let available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) );
- Qty+=available_qty;
- if(available_qty && (toSend.length < (keySets*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (keySets*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (keySets*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (keySets*qty)){
- let toReceive=[];
- for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
- } else {
- Message(source, 'Hey, i have only '+Qty+' Sets available..');
- if(Qty >= keySets){
- Message(source, 'Try !buyany '+Math.round(Qty/keySets)+'!');
- } else {
- Message(source, 'Come back later please ?');
- }
- }
- } else {
- Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you have only '+KeysFromThemAsset.length+' :(');
- }
- }
- });
- }
- function buytf(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- return_CustomerTFKeys(source, function(err, KeysFromThemAsset){
- if(err){
- Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
- } else {
- if(KeysFromThemAsset.length >= (tfkeyPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = 5-parseInt(lvl);
- }
- }
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (tfkeySets*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (tfkeySets*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (tfkeySets*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (tfkeySets*qty)){
- let toReceive=[];
- for(let i=0;i<(tfkeyPrice*qty);i++){ toReceive.push({ appid:440, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (tfkeySets*qty)+":"+(tfkeyPrice*qty), 0, "tf key(s)");
- } else {
- Message(source, 'Hey, I only '+Qty+' sets available that you have yet to craft.');
- if(Qty >= tfkeySets){
- Message(source, 'Try !buytf '+Math.round(Qty/tfkeySets)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(keyPrice*qty)+' tf key(s) for this purchase, and you only '+KeysFromThemAsset.length+' :(');
- }
- }
- });
- }
- function buy(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- debug("user #"+source+" requested !buy "+qty);
- return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
- if(err){
- Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
- } else {
- if(KeysFromThemAsset.length >= (keyPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = 5-parseInt(lvl);
- }
- }
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 5) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (keySets*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (keySets*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (keySets*qty)){ break; }
- }
- }
- }
- }
- debug("Founded "+Qty+" sets available to #"+source);
- debug("Putting "+toSend.length+" sets in trade offer for #"+source);
- if(Qty >= (keySets*qty)){
- let toReceive=[];
- for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
- debug("Putting "+toReceive.length+" keys to send for #"+source);
- makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
- } else {
- Message(source, 'Hey, I only have '+Qty+' sets available that you have yet to craft.');
- if(Qty >= keySets){
- Message(source, 'Try !buy '+Math.round(Qty/keySets)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
- }
- }
- });
- }
- function buyone(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- return_CustomerCSGOKeys(source, function(err, KeysFromThemAsset){
- if(err){
- Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
- } else {
- if(KeysFromThemAsset.length >= (keyPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = (lvl) ? 0 : 1;
- }
- }
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (keySets*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (keySets*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (keySets*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (keySets*qty)){
- let toReceive=[];
- for(let i=0;i<(keyPrice*qty);i++){ toReceive.push({ appid:730, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (keySets*qty)+":"+(keyPrice*qty), 0, "key(s)");
- } else {
- Message(source, 'Hey, I have only '+Qty+' sets available which you yet to craft.');
- if(Qty >= keySets){
- Message(source, 'Try !buyone '+Math.round(Qty/keySets)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(keyPrice*qty)+' key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
- }
- }
- });
- }
- function buyonetf(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- return_CustomerTFKeys(source, function(err, KeysFromThemAsset){
- if(err){
- Message(source, "For some reason I can't load your cs:go inventory. Please try again later :(");
- } else {
- if(KeysFromThemAsset.length >= (tfkeyPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- badges.forEach(function(current_badge, baindex){
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = (lvl) ? 0 : 1;
- }
- });
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (tfkeySets*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (tfkeySets*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (tfkeySets*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (tfkeySets*qty)){
- let toReceive=[];
- for(let i=0;i<(tfkeyPrice*qty);i++){ toReceive.push({ appid:440, contextid:2, amount:1, assetid: KeysFromThemAsset[i] }); }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (tfkeySets*qty)+":"+(tfkeyPrice*qty), 0, "tf key(s)");
- } else {
- Message(source, 'Hey, I have only '+Qty+' sets available which you have yet to craft.');
- if(Qty >= tfkeySets){
- Message(source, 'Try !buyonetf '+Math.round(Qty/tfkeySets)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(tfkeyPrice*qty)+' tf key(s) for this purchase, and you only have '+KeysFromThemAsset.length+' :(');
- }
- }
- });
- }
- function buyonegems(source, qty){
- Message(source, "I'll send the trade offer in a minute!");
- community.getUserInventoryContents(source, 753, 6, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'buygems'); Message(source, 'An error has occurred, please try again later.'); }
- else if(items.length == 0){ Message(source, 'Your Steam Inventory is empty :/'); }
- else {
- let UserGemsAssets={};
- let UserGemsQty=0;
- items.forEach(function(item, index){
- if(item.market_hash_name.toLowerCase().indexOf("753-gems") > -1) {
- UserGemsAssets[item.id]=item.amount;
- UserGemsQty+=parseInt(item.amount);
- }
- });
- if(UserGemsQty >= (GemPrice*qty)){
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- let Qty=0;
- let toSend=[];
- let badges=r.response.badges;
- let badge={};
- for(let key in badges){
- let current_badge=badges[key];
- let appid=current_badge.appid;
- let lvl=current_badge.level;
- if(appid && current_badge.border_color == 0){
- badge[appid] = (lvl) ? 0 : 1;
- }
- }
- for(let appid in AvailableSets){
- let available_qty=0;
- if(badge[appid] != null){ available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, badge[appid]) ); }
- else { available_qty=Math.min.apply( Math, new Array(AvailableSets[appid].length, 1) ); }
- Qty+=available_qty;
- if(available_qty && (toSend.length < (GemSet*qty))){
- for(let i=0;i<available_qty;i++){
- if(toSend.length < (GemSet*qty)){
- toSend.push(AvailableSets[appid][i]);
- if(toSend.length == (GemSet*qty)){ break; }
- }
- }
- }
- }
- if(Qty >= (GemSet*qty)){
- let toReceive=[];
- let SelecionedGemsQty=0;
- for(let key in UserGemsAssets){
- let GemAssetQty=UserGemsAssets[key];
- let GemAsset=key;
- let falta=(GemPrice*qty)-SelecionedGemsQty;
- if(GemAssetQty >= falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
- SelecionedGemsQty+=falta;
- }
- else if(GemAssetQty < falta && falta > 0){
- toReceive.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
- SelecionedGemsQty+=GemAssetQty;
- }
- }
- makeOffer(source, [].concat.apply([], toSend), toReceive, (GemSet*qty)+":"+(GemPrice*qty), 0, "gems");
- } else {
- Message(source, 'Hey, I have only '+Qty+' sets available that you have yet to craft.');
- if(Qty >= GemSet){
- Message(source, 'Try !buyonegems '+Math.round(Qty/GemSet)+'!');
- } else {
- Message(source, 'Come back later, will you?');
- }
- }
- });
- } else {
- Message(source, 'Sorry, but you need '+(GemPrice*qty)+' gems for this purchase, and you only have '+UserGemsQty+' :(');
- }
- }
- });
- }
- function checkam(source, amount, callback){
- Message(source, "Thanks for asking! Let me calculate...");
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- if(err){ logError(err.message, 'checkam'); Message(source, 'An error has occurred, please try again later.'); return; }
- let response=r.response;
- let player_xp=parseInt(response.player_xp);
- let xpWon=((keySets/keyPrice)*100)*amount;
- let totalExp=player_xp+xpWon;
- let i=parseInt(response.player_level)-1;
- let can=1;
- do {
- i++;
- if(i > config.maxLevelComm){
- Message(source, "I'm not allowed to calculate level above than "+config.maxLevelComm+" :/");
- Message(source, "Sorry, but can you try a lower level?");
- can++;
- break;
- }
- }
- while (getLevelExp(i) <= totalExp);
- if(can==1){callback(response.player_level, (i-1));}
- });
- }
- function checkgam(source, amount, callback){
- Message(source, "Thanks for asking. Let me calculate...");
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":source, "key":manager.apiKey}, function(err, r){
- if(err){ logError(err.message, 'checkgam'); Message(source, 'An error has occurred. Please try again later.'); return; }
- let response=r.response;
- let player_xp=parseInt(response.player_xp);
- let xpWon=((GemSet/GemPrice)*100)*amount;
- let totalExp=player_xp+xpWon;
- let i=parseInt(response.player_level)-1;
- do {
- i++;
- if(i > config.maxLevelComm){
- Message(source, "I'm not allowed to calculate levels more than "+config.maxLevelComm+" :/");
- Message(source, "Sorry, but can you try a lower level?");
- break;
- }
- }
- while (getLevelExp(i) <= totalExp);
- callback(response.player_level, (i-1));
- });
- }
- function return_CustomerSets(ignore, sid64, callback){
- community.getUserInventoryContents(sid64, 753, 6, true, function(err, items, currency, total){
- if(err){ logError(err.message, 'return_CustomerSets'); callback(err); }
- else if(items.length == 0){ Message('Your steam Inventory is empty!'); callback(null, []); }
- else {
- let customer_sets=[];
- let customer_cards={};
- items.forEach( function(item, i) {
- if(item.getTag("item_class").internal_name == "item_class_2" && item.getTag("cardborder").internal_name == "cardborder_0"){
- let appid=item.market_hash_name.split("-")[0];
- if(!customer_cards[appid]){customer_cards[appid]={};}
- if(!customer_cards[appid][item.market_hash_name]){customer_cards[appid][item.market_hash_name]=[];}
- customer_cards[appid][item.market_hash_name].push(item.id);
- }
- });
- for(let appid in customer_cards){
- if(card_db[appid] && Object.keys(customer_cards[appid]).length == card_db[appid]){
- let max=[];
- for(let card in customer_cards[appid]){ max.push(customer_cards[appid][card].length); }
- max=Math.min.apply( Math, max );
- if(!ignore){
- if((Object.keys(customer_cards[appid]).length+max) > config.maxStock){
- max -= (Object.keys(customer_cards[appid]).length+max)-config.maxStock;
- if ( max < 0) { max = 0; }
- }
- }
- for (let i=0;i<max;i++) {
- let currentCustomerSet=[];
- for(let card in customer_cards[appid]){
- currentCustomerSet.push({ appid:753, contextid:6, amount:1, assetid: customer_cards[appid][card][i] });
- }
- customer_sets.push(currentCustomerSet);
- }
- }
- }
- callback(null, customer_sets);
- }
- });
- }
- function sell(sid64, keys){
- if(CurrentKeys.length < keys){
- Message(sid64, "Sorry, but I don't have enough keys for this request :(");
- } else {
- Message(sid64, "Thanks! Just hold on for a sec..");
- return_CustomerSets(false, sid64, function(err, customer_sets){
- if(!err){
- let requested_sets=parseInt((keys/keyBuyPrice)*keyBuySets);
- if(customer_sets.length >= requested_sets){
- Message(sid64, "Sending your trade offer...");
- let toSend=[];
- let toRequest=[];
- for(let i=0;i<requested_sets;i++){ toRequest.push(customer_sets[i]); }
- for(let i=0;i<keys;i++){ toSend.push({ appid:730, contextid:2, amount:1, assetid: CurrentKeys[i] }); }
- toRequest = [].concat.apply([], toRequest);
- makeOffer(sid64, toSend, toRequest, requested_sets+":"+keys, 1, "key(s)");
- } else {
- Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later.");
- }
- } else {
- Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
- }
- });
- }
- }
- function sellgems(sid64, sets){
- return_GemsQty(function(CurrentGemsQty){
- if(CurrentGemsQty < (sets*GemBuyPrice)){
- Message(sid64, "Sorry, but I don't have enough Gems for this request :(");
- } else {
- Message(sid64, "Thanks, just hold on for a sec...");
- return_CustomerSets(false, sid64, function(err, customer_sets){
- if(!err){
- if(customer_sets.length >= sets){
- Message(sid64, "Sending your trade offer...");
- let toSend=[];
- let toRequest=[];
- let GemsSelected=0;
- for(let i=0;i<sets;i++){ toRequest.push(customer_sets[i]); }
- for(let key in InventoryGemsAssets){
- let GemAssetQty=InventoryGemsAssets[key];
- let GemAsset=key;
- let falta=(sets*GemBuyPrice)-GemsSelected;
- if(GemAssetQty >= falta && falta > 0){
- toSend.push({ appid:753, contextid:6, amount:falta, assetid: GemAsset });
- GemsSelected+=falta;
- }
- else if(GemAssetQty < falta && falta > 0){
- toSend.push({ appid:753, contextid:6, amount:GemAssetQty, assetid: GemAsset });
- GemsSelected+=GemAssetQty;
- }
- }
- toRequest = [].concat.apply([], toRequest);
- makeOffer(sid64, toSend, toRequest, sets+":"+GemsSelected, 1, "gems");
- } else {
- Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later.");
- }
- } else {
- Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
- }
- });
- }
- });
- }
- function selltf(sid64, keys){
- if(CurrentTFKeys.length < keys){
- Message(sid64, "Sorry but i don't have enough keys for this request :(");
- } else {
- Message(sid64, "Thanks, just hold on for a sec...");
- return_CustomerSets(false, sid64, function(err, customer_sets){
- if(!err){
- let requested_sets=parseInt((keys/tfkeyBuyPrice)*tfkeyBuySets);
- if(customer_sets.length >= requested_sets){
- Message(sid64, "Sending your trade offer...");
- let toSend=[];
- let toRequest=[];
- for(let i=0;i<requested_sets;i++){ toRequest.push(customer_sets[i]); }
- for(let i=0;i<keys;i++){ toSend.push({ appid:440, contextid:2, amount:1, assetid: CurrentTFKeys[i] }); }
- toRequest = [].concat.apply([], toRequest);
- makeOffer(sid64, toSend, toRequest, requested_sets+":"+keys, 1, "tf key(s)");
- } else {
- Message(sid64, "Unfortunately you don't have enough sets to sell to me. Please come back later?");
- }
- } else {
- Message(sid64, "For some reason I can't take a look an your inventory. Please try again later :(");
- }
- });
- }
- }
- function sellcheck(sid64){
- Message(sid64, 'Hold on! loading your inventory..');
- return_CustomerSets(false, sid64, function(err, customer_sets){
- if(err){
- Message(sid64, "For some reason I can't take a look at your inventory. Please try again later :(");
- } else {
- let cansell=customer_sets.length;
- if(cansell > 0){
- Message(sid64, "You have "+cansell+" set(s) that I can buy.");
- 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";
- if(config.enableTF){
- r += " or "+parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice)+" TF2 keys for "+(tfkeyBuySets/tfkeyBuyPrice)*parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice)+" sets";
- }
- Message(sid64, r);
- r = "Interested? Try !sell "+parseInt((cansell/keyBuySets)*keyBuyPrice);
- if(config.enableTF){ r+= " or !sellgems "+cansell+" or !selltf "+parseInt((cansell/tfkeyBuySets)*tfkeyBuyPrice); }
- Message(sid64,r);
- } else {
- Message(sid64, "Unfortunately you don't have any sets that I can buy. Please try again later.");
- }
- }
- });
- }
- function block(target){
- Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
- client.blockUser(target, function(result){
- if(result == 1){
- Message(config.admin, 'Successfully blocked user '+target+' !');
- } else {
- Message(config.admin, 'Fail!, did you put the right SteamID64 ??');
- }
- })
- }
- function unblock(target){
- Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
- client.unblockUser(target, function(result){
- if(result == 1){
- Message(config.admin, 'Successfully unblocked user '+target+' !');
- } else {
- Message(config.admin, 'Fail!, did you put the right SteamID64 ??');
- }
- })
- }
- function stock(){
- Message(config.admin, "Hey owner!, please wait a few seconds and i'll quickly proccess your request!");
- return_CustomerSets(true, config.admin, function(err, sets){
- if(err){
- Message(config.admin, "Something gone wrong, try again!");
- } else {
- if(sets.length > 0){
- Message(config.admin, "I have found "+sets.length+" sets!, i'll send the trade offer now !");
- makeOffer(config.admin, [], [].concat.apply([], sets), 'admin');
- } else {
- Message(config.admin, "Unfortunately you don't have any sets i can request, please try again later!");
- }
- }
- });
- }
- function restart_(){ log('Restarting..'); restart=1; CurrentKeys=[]; CurrentTFKeys=[]; InventoryCardsGame={}; AvailableSets={}; client.relog(); }
- function shutdown() {
- log('Shutdown requested, bye...');
- try{ client.logOff(); client.once('disconnected', function() { process.exit(1); }); } catch(e) { process.exit(1); }
- setTimeout(function() { process.exit(1); }, 500);
- }
- function nFormat(n){
- if(n.toString().indexOf(".") > -1){
- let i = n.toString().split(".")[0];
- let f = n.toString().split(".")[1].substring(0,1);
- n = parseFloat(i+"."+f);
- }
- return n;
- }
- client.on('friendMessage', function(source, message) {
- storeChatLogData(source, message);
- let Now = new Date().getTime();
- if(LastInteract[source] && Math.floor(Now - LastInteract[source]) < 500){
- if(!Warns[source]){ Warns[source] = 0; }
- Warns[source]++;
- if(Warns[source] == 1){ Message(source, "Please don't spam me :("); }
- if(Warns[source] == 2){ Message(source, "Please don't spam me, next time I'll have to unfriend you!"); }
- if(Warns[source] > 2){
- Message(source, "You're sending to many messages to me, I'm unfriending you, bye!");
- Message(config.admin, "User #"+source+" has been sending to many messages and has been removed from the bot's friendlist!");
- log("User #"+source+" has been sending to many messages and has been removed from the bot's friendlist!");
- client.removeFriend(source);
- }
- return;
- }
- UserInteract(source);
- message = message.toLowerCase();
- if (message == '!admin' && source == config.admin) {
- Message(source, 'Admin Commands:');
- Message(source, '!withdraw [amount] withdraw x CS:GO keys');
- if(config.enableTF){Message(source, '!tfwithdraw [amount] withdraw x TF keys');}
- Message(source, '!gemswithdraw [amount] withdraw x Gems');
- Message(source, '');
- Message(source, "!deposit [amount] - deposit x CS:GO keys");
- if(config.enableTF){Message(source, "!tfdeposit [amount] - deposit x TF keys");}
- Message(source, "!depositgems [amount] - deposit x Gems");
- Message(source, '');
- Message(source, '!block [SteamID64] block user');
- Message(source, '!unblock [SteamID64] unblock user');
- Message(source, '!stock bot will send a trade offer requesting all your available sets to trade');
- Message(source, '');
- Message(source, '!restart restart the bot(logoff and login)');
- Message(source, '!shutdown logoff bot and close application');
- }
- else
- if (message == '!help') {
- Message(source, 'Commands:');
- Message(source, '!owner - shows the profile of my owner. If you have any problems you should contact him!');
- Message(source, '!prices to see our prices');
- Message(source, '');
- Message(source, "!level [your dream level] - calculate how many sets and how many keys it'll cost to desired level");
- Message(source, '!check - show how many sets the bot have available and how much you can craft');
- Message(source, '!check [amount] - show how many sets and which level you would reach for a specific amount of keys');
- if(config.enableTF){Message(source, '!checktf [amount] - show how many sets and which level you would reach for a specific amount of keys');}
- Message(source, '!checkgems [amount] - show how many sets and which level you would reach for a specific amount of gems');
- Message(source, '');
- 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');
- 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');}
- Message(source, '!buygems [amount of sets] - use to buy that amount of sets for gems, following the current BOT rate');
- 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');
- Message(source, '');
- 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');
- 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');}
- Message(source, '!buyonegems [amount of sets] - use this if you are a badge collector. sames as !buyone, buy you pay with gems!');
- Message(source, '');
- Message(source, '!sell [amount of CS:GO keys] to sell your sets for CS:GO Key(s)');
- Message(source, '!sellgems [amount of sets] to sell your sets for gems');
- if(config.enableTF){Message(source, '!selltf [amount of TF keys] to sell your sets for TF Key(s)');}
- Message(source, '!sellcheck show information about the set(s) you can sell');
- }
- else if (message.indexOf('!check') > -1 && message.indexOf('!checkgems') == -1 && message.indexOf('!checktf') == -1) {
- if(message.split(" ")[1]){
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs > 0){
- checkam(source, inputs, function(lvl, desired){
- if(lvl != level){
- 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));
- } else {
- 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));
- }
- });
- } else {
- Message(source, "The amount value should be higher than 0");
- }
- }
- else { Message(source, "Try !check [amount]"); }
- } else {
- check(source);
- }
- }
- else if (message.indexOf('!checktf') > -1 && config.enableTF) {
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs > 0){
- checkam(source, inputs, function(lvl, desired){
- if(lvl != level){
- 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));
- } else {
- 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));
- }
- });
- } else {
- Message(source, "The amount value should be higher than 0");
- }
- }
- else { Message(source, "Try !checktf [amount]"); }
- }
- else if (message.indexOf('!checkgems') > -1) {
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs >= GemPrice){
- checkgam(source, inputs, function(lvl, desired){
- if(lvl != desired){
- Message(source, "With "+inputs+" gems you'll get "+parseInt(inputs/GemPrice)*GemSet+" set(s) and reach level "+desired+", interested? Try !buygems "+parseInt(inputs/GemPrice));
- } else {
- 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));
- }
- });
- } else {
- Message(source, "The minimum value is "+GemPrice);
- }
- }
- else { Message(source, "Try !checkgems [amount]"); }
- }
- else if (message.indexOf('!block') > -1 && message.indexOf('!unblock') == -1 && source == config.admin) {
- let inputs=(message.split(" ")[1]);
- if(isNaN(parseInt(inputs)) == false){
- block(inputs.toString());
- }
- else { Message(source, "Try !block [SteamID64]"); }
- }
- else if (message.indexOf('!unblock') > -1 && source == config.admin) {
- let inputs=(message.split(" ")[1]);
- if(isNaN(parseInt(inputs)) == false){
- unblock(inputs.toString());
- }
- else { Message(source, "Try !unblock [SteamID64]"); }
- }
- else if (message == '!owner') {
- Message(source, 'There is something wrong?');
- Message(source, 'My SteamProfile: https://steamcommunity.com/profiles/'+config.admin);
- }
- else if (message.indexOf('!buy') > -1 && message.indexOf('!buygems') == -1 && message.indexOf('!buyany') == -1 && message.indexOf('!buyone') == -1 && message.indexOf('!buytf') == -1) {
- if(message == '!buy' ){ Message(source, "Try !buy [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buy(source, inputs);
- }
- }
- else { Message(source, "Try !buy [amount]"); }
- }
- else if (message.indexOf('!buytf') > -1 && config.enableTF) {
- if(message == '!buytf' ){ Message(source, "Try !buytf [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buytf(source, inputs);
- }
- }
- else { Message(source, "Try !buytf [amount]"); }
- } else if(message.indexOf('!buygems') > -1){
- if(message == '!buygems' ){ Message(source, "Try !buygems [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buygems(source, inputs);
- }
- }
- else { Message(source, "Try !buygems [amount]"); }
- } else if(message.indexOf('!sell') > -1 && message.indexOf('!sellcheck') == -1 && message.indexOf('!sellgems') == -1 && message.indexOf('!selltf') == -1){
- if(message == '!sell' ){ Message(source, "Try !sell [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- sell(source, inputs);
- }
- }
- else { Message(source, "Try !sell [amount]"); }
- } else if(message.indexOf('!sellgems') > -1){
- if(message == '!sellgems' ){ Message(source, "Try !sellgems [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- sellgems(source, inputs);
- }
- }
- else { Message(source, "Try !sellgems [amount]"); }
- } else if(message.indexOf('!selltf') > -1 && config.enableTF){
- if(message == '!selltf' ){ Message(source, "Try !selltf [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- selltf(source, inputs);
- }
- }
- else { Message(source, "Try !selltf [amount]"); }
- } else if(message.indexOf('!buyonegems') > -1){
- if(message == '!buyonegems' ){ Message(source, "Try !buyonegems [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buyonegems(source, inputs);
- }
- }
- else { Message(source, "Try !buygems [amount]"); }
- } else if(message.indexOf('!buyone') > -1 && message.indexOf('!buyonegems') == -1 && message.indexOf('!buyonetf') == -1){
- if(message == '!buyone' ){ Message(source, "Try !buyone [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buyone(source, inputs);
- }
- }
- else { Message(source, "Try !buyone [amount]"); }
- } else if(message.indexOf('!buyonetf') > -1 && config.enableTF){
- if(message == '!buyonetf' ){ Message(source, "Try !buyonetf [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buyonetf(source, inputs);
- }
- }
- else { Message(source, "Try !buyonetf [amount]"); }
- } else if(message.indexOf('!buyany') > -1){
- if(message == '!buyany' ){ Message(source, "Try !buyany [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- Message(source, "Hey, thanks!");
- buyany(source, inputs);
- }
- }
- else { Message(source, "Try !buyany [amount]"); }
- }
- else if (message == '!prices') {
- Message(source, 'The current prices are:');
- Message(source, keySets+' set(s) for '+keyPrice+' CS:GO Key(s)');
- if(config.enableTF){Message(source, tfkeySets+' set(s) for '+tfkeyPrice+' TF Key(s)');}
- Message(source, GemPrice+' Gems for '+GemSet+' set(s)');
- Message(source, 'Also, we are buying '+keyBuySets+' set(s) for '+keyBuyPrice+' CS:GO Key(s)');
- if(config.enableTF){Message(source, +tfkeyBuySets+' set(s) for '+tfkeyBuyPrice+' TF Key(s)');}
- Message(source, +GemBuySet+' set(s) for '+GemBuyPrice+' Gems');
- Message(source, 'Type !help for more information!');
- } else if (message == '!sellcheck') {
- sellcheck(source);
- }
- else if (message.indexOf('!level') > -1) {
- if(message == '!level' ){ Message(source, "Try !level [amount]"); return; }
- let inputs=parseInt(message.split(" ")[1]);
- if(isNaN(inputs) == false){
- if(inputs < 1) {
- Message(source, "The amount value should be higher than 0");
- } else if(inputs > config.maxLevelComm){
- Message(source, "I'm not allowed to calculate level above than "+config.maxLevelComm+" :/");
- Message(source, "Sorry but can you try a lower level?");
- } else {
- level(source, inputs);
- }
- }
- else { Message(source, "Try !level 'your dream level'"); }
- }
- else if (message.indexOf('!gemswithdraw') > -1 && source == config.admin) {
- if(message == '!gemswithdraw' ){ Message(source, "Try !gemswithdraw [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0"); }
- else {
- gemswithdraw(qty);
- }
- } else {
- Message(source, "Try !gemswithdraw [amount]");
- }
- } else if (message.indexOf('!withdraw') > -1 && source == config.admin) {
- if(message == '!withdraw' ){ Message(source, "Try !withdraw [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0"); }
- else {
- withdraw(qty);
- }
- } else {
- Message(source, "Try !withdraw [amount]");
- }
- } else if (message.indexOf('!tfwithdraw') > -1 && source == config.admin && config.enableTF) {
- if(message == '!tfwithdraw' ){ Message(source, "Try !tfwithdraw [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0"); }
- else {
- tfwithdraw(qty);
- }
- } else {
- Message(source, "Try !tfwithdraw [amount]");
- }
- } else if (message.indexOf('!deposit') > -1 && source == config.admin && message.indexOf('!depositgems') == -1 && config.enableTF) {
- if(message == '!deposit' ){ Message(source, "Try !deposit [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- deposit(qty)
- }
- } else { Message(source, "Try !deposit [amount]"); }
- } else if (message.indexOf('!tfdeposit') > -1 && source == config.admin && config.enableTF) {
- if(message == '!tfdeposit'){ Message(source, "Try !tfdeposit [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- tfdeposit(qty)
- }
- } else { Message(source, "Try !tfdeposit [amount]"); }
- } else if (message.indexOf('!depositgems') > -1 && source == config.admin && config.enableTF) {
- if(message == '!depositgems' ){ Message(source, "Try !depositgems [amount]"); return; }
- let qty=parseInt(message.split(" ")[1]);
- if(isNaN(qty) == false){
- if(qty < 1) {
- Message(source, "The amount value should be higher than 0");
- } else {
- depositgems(qty);
- }
- } else { Message(source, "Try !depositgems [amount]"); }
- } else if(message.indexOf('!restart') > -1 && source == config.admin){
- Message(source, "I'll be back in a minute!");
- restart_();
- } else if(message.indexOf('!shutdown') > -1 && source == config.admin){
- Message(source, "I going down :(");
- shutdown();
- } else if(message.indexOf('!stock') > -1 && source == config.admin){
- stock();
- } else { Message(source, "Need help? Try !help"); }
- });
- client.on('friendRelationship', function(steamid, relationship) { if (relationship === 2) { addFriend(steamid); } });
- function level (target, qty){
- Message(target, "Thanks for asking! Let me calculate...");
- client._apiRequest("GET", "IPlayerService", "GetBadges", 1, {"steamid":target, "key":manager.apiKey}, function(err, r){
- if(err){logError(err.message, 'level'); return;}
- let response = r.response;
- if(qty < response.player_level){ Message(target, "You have already rearched level "+qty+"!!"); }
- else {
- let needed=Math.round( ((getLevelExp(parseInt(qty)))-parseInt(response.player_xp))/100 );
- Message(target, "You'll need "+needed+" set(s) to reach level "+qty);
- Message(target, "It'll cost "+nFormat((needed/keySets)*keyPrice)+" key(s) or "+(needed/GemSet)*GemPrice+" Gems");
- Message(target, "Type !prices to see our prices!");
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement