Jump to content
McKay Development

lunar

Member
  • Posts

    10
  • Joined

  • Last visited

Posts posted by lunar

  1. I commented out everything to where it was working previously and it still gives me that console error, i even console.log everything and nothing is being logged in the console, just sends me a message on steam when it initiates the offer and then crashes with the error. 

     

    here is my entire buy function that gets called when you type "!buy number" into the bot

     

    function buy(steamID, amount){
        if(isNaN(amount) || amount === undefined){
            client.chatMessage(steamID, "Please enter a valid number");
        }
        else{
            var keyCount = 0;
            var i = 0;
            client.chatMessage(steamID, "Creating Offer, please wait!");
            //Check Players inventory for the keys, and make sure we have enough sets to supply
            var offer = manager.createOffer(steamID);
            offer.setMessage("Price: " + amount + " Keys. Sets: " + amount * config.buyRate);
            console.log('offer created');

            manager.getInventoryContents(753, 6, function(err, myItems){
                if(err){
                    console.log(err);
                    return;
                }
                offer.getPartnerInventoryContents(440, 2, function(err, theirItems){
                    if(err){
                        console.log(err);
                        return;
                    }
                    var keys = [];
                    var cardApps = [];
                    var totalBuying = 0;
                    getBadge.get('GetBadges', 1, { steamid: steamID }, function(statusCode, response) {
                        console.log('Got Badges');
                        if(cardApps.length <= config.buyRate * amount){
                            console.log('app list is less than the buyrate');
                            for(var i = 0; i < myItems.length; ++i){ // loop through our inventory
                                console.log('going through items');
                                if(myItems[i].type.includes('Trading Card')){ // if the item is a trading card
                                    console.log('we have a trading card');
                                    var id = myItems[i].market_hash_name; //set id as the market hash name
                                    id = id.replace(/[^0-9]/g,''); // remove the card name so we get app id
                                    if(statusCode == 200){
                                        console.log('we found badges');
                                        for(var j = 0; j < response.response.badges.length; ++j){
                                            console.log('browsing badge');
                                            if(!cardApps.includes(id)){ // check if we don't already have it
                                            console.log('we dont have this appid already');
                                                if(response.response.badges[j].level < 5){
                                                    var counter = 0;
                                                    counter = 5 - response.response.badges[j].level;
                                                    cardApps.push({app: id, amountToAdd: counter}); // add to array if we dont have it already
                                                    console.log('added a specific amount of times');
                                                }
                                                else if(!response.response.badges[j].appid.includes(id)){
                                                    cardApps.push({app: id, amountToAdd: 5});
                                                    console.log('added 5 times');
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    });
                    
                    //Adding the Users Items
                    for(var i = 0; i < theirItems.length; ++i){
                        if(theirItems[i].market_hash_name == config.keysAccepted && keys.length < amount){
                            console.log("Adding Their Item");
                            keys.push(theirItems[i].id);
                            offer.addTheirItem({id: theirItems[i].id, appid: 440, contextid: 2});
                            console.log("Length of keys "+keys.length);
                            console.log(keys);
                            ++keyCount;
                        }
                    }
                    //Adding our Items
                    for(var i = 0; i < cardApps.length; ++i){ //Loop through all the appid's we have
                        console.log('going through the app id');
                        steamMarket.searchCommunity(cardApps[i]).then(function(item){ //searches steam market for the appid
                            console.log('searched the market for the app id');
                            var itemCount = 0;
                            var cards = [];
                            for(var j = 0; j < item.length; ++j){ //loop through each item
                                console.log('going through items on market');
                                if(item[j].type.includes('Trading Card') && item[j].rarity.includes('Normal')){ //if they are a normal trading card
                                    console.log('going through items on market');
                                    ++itemCount;
                                    var ata = 0;
                                    if(ata <= cardApps[i].amountToAdd){
                                        console.log('going through the amount of sets we need to add');
                                        for (let y = 0; y < myItems.length; ++y) { //loop through all our items
                                            console.log('for our items look through em');
                                            if(myItems[y].market_hash_name == myItems[j].hash_name){ //if our item matches the one we are currently looking at
                                                console.log('we have a matching item');
                                                cards.push({id: myItems[y].id, appid: 753, contextid: 6}); // add to item array
                                                ++ata;
                                                console.log('added the item to list');
                                            }
                                        }
                                    }
                                    
                                }
                                if(cards.length == itemCount){
                                    console.log('added to our offer');
                                    offer.addMyItems(cards);
                                    cardApps.splice(i, 1);
                                    console.log('removed the card app from the list.');
                                }
                            }
                        }, console.error);
                    }
                    if(keyCount < amount){
                        console.log("count: "+keyCount);
                        client.chatMessage(steamID, "You don't have enough keys for me to send this trade.");
                        return;
                    }
                    else if(totalBuying < (amount * config.buyRate)){
                        console.log("card sets: " + totalBuying);
                        client.chatMessage(steamID, "I currently do not have enough card sets to trade you.");
                        return;
                    }
                    else{
                        offer.send(function(err, status){
                            if(err){
                                console.log(err);
                                client.chatMessage(steamID, "An Error has Occured while sending offer.");
                            }
                            if(status == "pending"){
                                client.chatMessage(steamID, "Confirming Offer!");
                            }
                            if(status == "sent"){
                                client.chatMessage(steamID, "Offer Sent!");
                            }
                        });
                    }
                });
            });
            
            
            
            
        }
    }
  2. i'm getting the callback is not a function in the steamcommunity/user.js:484 file I have no idea what line of code of mine is causing this, I am trying to make a level bot and get all the sets in our inventory and add as many sets until the amount is reached which is the buyRate * how many keys the user wants to use.

     

    error 

    D:\Documents\Google Drive\Node\SteamBot\node_modules\steamcommunity\components\users.js:484
                                    callback(null, inventory, currency, body.total_inventory_count);
                                    ^
    
    TypeError: callback is not a function
        at SteamCommunity.<anonymous> (D:\Documents\Google Drive\Node\SteamBot\node_modules\steamcommunity\components\users.js:484:5)
        at Request._callback (D:\Documents\Google Drive\Node\SteamBot\node_modules\steamcommunity\components\http.js:67:15)
        at Request.self.callback (D:\Documents\Google Drive\Node\SteamBot\node_modules\request\request.js:185:22)
        at Request.emit (events.js:182:13)
        at Request.<anonymous> (D:\Documents\Google Drive\Node\SteamBot\node_modules\request\request.js:1161:10)
        at Request.emit (events.js:182:13)
        at IncomingMessage.<anonymous> (D:\Documents\Google Drive\Node\SteamBot\node_modules\request\request.js:1083:12)
        at Object.onceWrapper (events.js:273:13)
        at IncomingMessage.emit (events.js:187:15)
        at endReadableNT (_stream_readable.js:1086:12)
    

    and here is the code that is possibly causing the error ( I am also using https://www.npmjs.com/package/steam-market-search for the market search as I couldn't get the one in steamcommunity to work)

    for(var i = 0; i < cardApps.length; ++i){ //Loop through all the appid's we have
    					steamMarket.searchCommunity(cardApps[i]).then(function(item){ //searches steam market for the appid
    						var itemCount = 0;
    						var cards = [];
    						for(var j = 0; j < item.length; ++j){ //loop through each item
    							if(item[j].type.includes('Trading Card') && item[j].rarity.includes('Normal')){ //if they are a normal trading card
    								++itemCount;
    								var ata = 0;
    								if(ata <= cardApps[i].amountToAdd){
    									for (let y = 0; y < myItems.length; ++y) { //loop through all our items
    										if(myItems[y].market_hash_name == myItems[j].hash_name){ //if our item matches the one we are currently looking at
    											cards.push({id: myItems[y].id, appid: 753, contextid: 6}); // add to item array
    											++ata;
    										}
    									}
    								}
    								
    							}
    							if(cards.length == itemCount){
    								offer.addMyItems(cards);
    								cardApps.splice(i, 1);
    							}
    						}
    					}, console.error);
    				}
    
  3. I am trying to only get defined number of keys in a trade, but instead it adds all the items as they share the same id (item is a TF2 Mann co. key)

    here is my current code for the trade offer, (the steam id in create offer is a mates steamid as I can't test with my own account due to vac)

    function buy(steamID, amount){
    	if(isNaN(amount) || amount === undefined){
    		client.chatMessage(steamID, "Please enter a valid number");
    	}
    	else{
    		var count = 0;
    		var i = 0; 
    		client.chatMessage(steamID, "Creating Offer, please wait!");
    		//Check Players inventory for the keys, and make sure we have enough sets to supply
    		var offer = manager.createOffer('76561198008100070');
    		offer.setMessage("Price: " + amount + " Keys. Sets: " + amount * config.buyRate);
    		offer.getPartnerInventoryContents(440, 2, function(err, inventory, currencies){
    			if(err){
    				console.log(err);
    			}
    			/*for	(var j = 0; j < amount; ++j){
    				if(inventory[i].market_hash_name == config.keysAccepted){
    					++count;
    					console.log("Adding Item");
    					offer.addTheirItem({id: inventory[i].id, appid: 440, contextid: 2});
    				}
    			}*/
    			inventory.forEach(function(val){
    				if(val.market_hash_name == config.keysAccepted){
    					console.log("Adding Item");
    					offer.addTheirItem({id: val.instanceid, appid: 440, contextid: 2});
    					++count;
    				}
    			});
    			if(count < amount){
    				console.log("count: "+count);
    				client.chatMessage(steamID, "You don't have enough keys for me to send this trade.");
    			}
    			else{
    				offer.send(function(err, status){
    					if(err){
    						console.log(err);
    						client.chatMessage(steamID, "An Error has Occured while sending offer.");
    					}
    					if(status == "pending"){
    						client.chatMessage(steamID, "Confirming Offer!");
    					}
    					if(status == "sent"){
    						client.chatMessage(steamID, "Offer Sent!");
    					}
    				});
    			}
    		});
    	}
    }
    
  4. I'm having trouble getting the element from the json in the response. 
    do I get the element I want via response.elementIWantHere or response[elementIWantHere]?

    as I have tried both and neither work.

    This is my code so far.

     

    api.get("IPlayerService", "GetBadges", 1, steamid=steamID, function(err, response){
                    if(err){
                        console.log(err);
                    }
                    console.log("level: " + results[steamID] + " xp: " + response.player_xp);
                    client.chatMessage(steamID, "You have " + response.player_xp + " xp and are level " + level);
                });

    Response currently just gives me undefined as the value

    and I get a internal server error

     

    edit: Ended up using seishun's node-steam-web-api for it as it worked first try.

  5. i am trying to get the current xp of a user and the xp required to achieve a level but i don't know how to see how much xp they currently have? is there something built into steam-user or should i use another module?

    here is my code for the command

    function level(steamID, level){
      client.getSteamLevels([steamID], function(results){
        console.log("level: " + results[steamID] + "xp: " + results[steamID].xp); // just gives me undefined for the result for xp
        if(level === undefined){
          level = results[steamID];
        }

        if(level >= results[steamID]){
          client.chatMessage(steamID, "You would need " + /*xp required here*/ + "more xp for level " + level);
        }
        else{
          client.chatMessage(steamID, "Please enter a higher number");
        }
        
      });
    }

     

×
×
  • Create New...