Jump to content
McKay Development

shizzo

Member
  • Posts

    3
  • Joined

  • Last visited

Posts posted by shizzo

  1. Okay thanks for the Information, didnt know that but seems to be logic.

    Anyway i removed that Part and still get the same message.

     

    This is the current changed and updated Code (Only removed line 53 and the part that belongs to this):

    function sendRake(param){
    	logger.info('[RAKECHECK] Calling the Sending Function');
    	connection.query('SELECT * FROM `rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
    	{
    		logger.info('[RAKECHECK] Selected the correct Table for DB');
    		if(row.length!=0) // if not empty
    		{
    			logger.info('[RAKECHECK] Selected Table is not empty, continue');
    			var assetids=(row[0].assetid).split('/'); //assetid from first row named assetid
    			logger.info('[RAKECHECK] Splitting the AssetID from our DB devided by Slash');
    			offers.getInventoryContents(730, 2, true, function (err, inventory) //getting inventory contents
    			{
    				logger.info('[RAKECHECK] getInventoryContents called!');
    				if (err){ // if we get an error
    					if(param==1){
    						client.chatMessage(config.admin1, '[SERVER] Error while loading the Bot\'s Inventory, try again later boss!');
    					}
    					logger.info('[RAKECHECK] getInventoryContents could get no Items');
    					console.log(err);
    					return;
    				}
    				else
    				{
    				// no error on getting inventory so we can continue 
    					
    					// If the inventory is empty
    					if(inventory.length == 0) {
    						logger.info('[RAKECHECK] getInventoryContents found an empty inventory!');
    						console.log("CS:GO inventory is empty");
    						return;
    					}
    					
    					// if the inventory has no error and is not empty, give me the count of items
    					console.log("Found " + inventory.length + " CS:GO items");
    					logger.info("[RAKECHECK] Found " + inventory.length + " CS:GO items");	
    					//provides the token
    					var token = row[0].token;
    					logger.info("[RAKECHECK] Token: " + token + " found!");
    					// provides the gameid
    					var gameid = row[0].id; 
    					logger.info("[RAKECHECK] Game ID: " + gameid + " found!");
    					//provides the value
    					var value = row[0].value; 	
    					logger.info("[RAKECHECK] Value: " + value + " found!");
    					// provides the partners steamid 
    					var sid = row[0].userid;
    					logger.info("[RAKECHECK] Steam ID: " + sid + " found!");
    
    					// Create the offer
    					var offer = offers.createOffer(new TradeOfferManager.SteamID(row[0].userid), '' + row[0].token + '');
    					logger.info("[RAKECHECK] createOffer: ID:" + sid + " TKN:" + row[0].token + "");
    
    						logger.info("[RAKECHECK] Confirmed: " + offer.itemsToGive.length + " Items");
    						//for each item in inventory do the following
    						inventory.forEach(function(item)
    						{
    							//for each assetid to this
    							assetids.forEach(function(asset)
    							{
    								//if the itemid is same as assetid
    								if(item.id==asset)
    								{
    									//Add my item to the trade
    									//Also tested with same result: offer.addMyItems(inventory[0]);
    									offer.addMyItem({"appid": 730, "contextid": 2, "assetid": "10387413069",}); 
    								}
    							})
    						});
    					
    					// Send the Trade with a Message
    					offer.setMessage('Rake for Game #'+gameid+' ($'+value+')');
    
    					//setTimeout(function(){	
    					
    					// sending offer
    					offer.send(function(err, status) {
    						//if we get an error, return the error to console and admin via chat
    						if (err) {
    							console.log(err);										
    							if(param==1){
    									client.chatMessage(config.admin1, '[SERVER] Error while sending the tradeoffer for the rake, try again later');
    									return;
    							}
    							return;
    						}
    						// if the status is pending we will need to accept the trade
    						
    						if (status == 'pending') {
    							console.log('[SERVER] Rake for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
    							// We need to confirm it
    							console.log(`Offer #${offer.id} sent, but requires confirmation`);
    							community.acceptConfirmationForObject(config.identitysecret, offer.id, function(err) {
    								if (err) {
    									console.log(err);
    								} else {
    									console.log("Offer confirmed");
    								}
    							});
    						}
    						// if no error and not pending, the trade seems to be accepted
    						else {
    							console.log(`Offer #${offer.id} sent successfully`);
    							connection.query('UPDATE `rakeitems` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
    							if(param==1)
    							{
    								client.chatMessage(config.admin1, '[SERVER] Successfully sent the rake for Game #'+gameid+'!');
    							}	
    						}
    					}); 		// End of send function
    								// Actually unused timeout },2000);
    				} 				// End of (else) for getting inventory with no error
    			});					// Closing getInventoryContents
    		}						// If row lenght not 0
    		else
    		{
    			// If row is empty there is no query to call
    			if(param==1)
    			{
    				client.chatMessage(config.admin1, '[SERVER] No more Rake Queries!');
    				return;
    			}
    		}
    	});	
    }
    

    And this is the core problem iam fighting:

    2017-06-27T11:10:11.654Z - info:  Error: Cannot send an empty trade offer
        at TradeOffer.send (C:\Users\USER\Desktop\NETWORK v5\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:282:23)
        at C:\Users\USER\Desktop\NETWORK v5\tradebot.js:1174:12
        at SteamCommunity.<anonymous> (C:\Users\USER\Desktop\NETWORK v5\node_modules\steamcommunity\components\users.js:431:5)
        at Request._callback (C:\Users\USER\Desktop\NETWORK v5\node_modules\steamcommunity\components\http.js:67:15)
        at Request.self.callback (C:\Users\USER\Desktop\NETWORK v5\node_modules\request\request.js:188:22)
        at emitTwo (events.js:106:13)
        at Request.emit (events.js:191:7)
        at Request.<anonymous> (C:\Users\USER\Desktop\NETWORK v5\node_modules\request\request.js:1171:10)
        at emitOne (events.js:96:13)
        at Request.emit (events.js:188:7)
    

    TradeOffer.js: 282

    And this is causing the problem.

    if (this.itemsToGive.length + this.itemsToReceive.length == 0) {
    	Helpers.makeAnError(new Error("Cannot send an empty trade offer"), callback);
    	return;
    }
    

    So when im not wrong, i create the offer, and send the offer immediately and empty because i send it before i have filled it with assetids?

    If thats correct, does anyone has an example how to solve that?

  2. Can not addMyItems to offer.send, always returns 0

     

    Actually receiving items works completely fine.

    But im struggling since 3 days about the sending offer part.

    So i started to log every activity on that part and commented every line to get things clear.

     

    I have two options of sending outgoing offers:

    • 1) if i want to send the winnings to the user
    • 2) if i want to send the rake to myself

     

    I have chosen the Rake function because its less code with same functionalities. If i get this running i also get the SendOffer running.

     

    The function will be called by /sendrake in steamchat to the bot (works also)

    function sendRake(param){
    	logger.info('[RAKECHECK] Calling the Sending Function');
    	connection.query('SELECT * FROM `rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
    	{
    		logger.info('[RAKECHECK] Selected the correct Table for DB');
    		if(row.length!=0) // if not empty
    		{
    			logger.info('[RAKECHECK] Selected Table is not empty, continue');
    			var assetids=(row[0].assetid).split('/'); //assetid from first row named assetid
    			logger.info('[RAKECHECK] Splitting the AssetID from our DB devided by Slash');
    			offers.getInventoryContents(730, 2, true, function (err, inventory) //getting inventory contents
    			{
    				logger.info('[RAKECHECK] getInventoryContents called!');
    				if (err){ // if we get an error
    					if(param==1){
    						client.chatMessage(config.admin1, '[SERVER] Error while loading the Bot\'s Inventory, try again later boss!');
    					}
    					logger.info('[RAKECHECK] getInventoryContents could get no Items');
    					console.log(err);
    					return;
    				}
    				else
    				{
    				// no error on getting inventory so we can continue 
    					
    					// If the inventory is empty
    					if(inventory.length == 0) {
    						logger.info('[RAKECHECK] getInventoryContents found an empty inventory!');
    						console.log("CS:GO inventory is empty");
    						return;
    					}
    					
    					// if the inventory has no error and is not empty, give me the count of items
    					console.log("Found " + inventory.length + " CS:GO items");
    					logger.info("[RAKECHECK] Found " + inventory.length + " CS:GO items");	
    					//provides the token
    					var token = row[0].token;
    					logger.info("[RAKECHECK] Token: " + token + " found!");
    					// provides the gameid
    					var gameid = row[0].id; 
    					logger.info("[RAKECHECK] Game ID: " + gameid + " found!");
    					//provides the value
    					var value = row[0].value; 	
    					logger.info("[RAKECHECK] Value: " + value + " found!");
    					// provides the partners steamid 
    					var sid = row[0].userid;
    					logger.info("[RAKECHECK] Steam ID: " + sid + " found!");
    
    					// Create the offer
    					var offer = offers.createOffer(new TradeOfferManager.SteamID(row[0].userid), '' + row[0].token + '');
    					logger.info("[RAKECHECK] createOffer: ID:" + sid + " TKN:" + row[0].token + "");
    					// If offer is not empty or outgoing trade contains imtems
    					if(offer.itemsToGive.length!=0)
    					{
    						logger.info("[RAKECHECK] Confirmed: " + offer.itemsToGive.length + " Items");
    						//for each item in inventory do the following
    						inventory.forEach(function(item)
    						{
    							//for each assetid to this
    							assetids.forEach(function(asset)
    							{
    								//if the itemid is same as assetid
    								if(item.id==asset)
    								{
    									//Add my item to the trade
    									//Also tested with same result: offer.addMyItems(inventory[0]);
    									offer.addMyItem({"appid": 730, "contextid": 2, "assetid": "10387413069",}); 
    								}
    							})
    						});
    					}
    					else
    					{
    						logger.info("[RAKECHECK] Items: " + offer.itemsToGive.length + " and this *Insult here* is still not working");
    						// The Tradeoffer is Empfty
    						console.log("Found " + offer.itemsToGive.length + " Items, Tradeoffer is empty");
    					}
    					
    					// Send the Trade with a Message
    					offer.setMessage('Rake for Game #'+gameid+' ($'+value+')');
    
    					//setTimeout(function(){	
    					
    					// sending offer
    					offer.send(function(err, status) {
    						//if we get an error, return the error to console and admin via chat
    						if (err) {
    							console.log(err);										
    							if(param==1){
    									client.chatMessage(config.admin1, '[SERVER] Error while sending the tradeoffer for the rake, try again later');
    									return;
    							}
    							return;
    						}
    						// if the status is pending we will need to accept the trade
    						
    						if (status == 'pending') {
    							console.log('[SERVER] Rake for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
    							// We need to confirm it
    							console.log(`Offer #${offer.id} sent, but requires confirmation`);
    							community.acceptConfirmationForObject(config.identitysecret, offer.id, function(err) {
    								if (err) {
    									console.log(err);
    								} else {
    									console.log("Offer confirmed");
    								}
    							});
    						}
    						// if no error and not pending, the trade seems to be accepted
    						else {
    							console.log(`Offer #${offer.id} sent successfully`);
    							connection.query('UPDATE `rakeitems` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
    							if(param==1)
    							{
    								client.chatMessage(config.admin1, '[SERVER] Successfully sent the rake for Game #'+gameid+'!');
    							}	
    						}
    					}); 		// End of send function
    								// Actually unused timeout },2000);
    				} 				// End of (else) for getting inventory with no error
    			});					// Closing getInventoryContents
    		}						// If row lenght not 0
    		else
    		{
    			// If row is empty there is no query to call
    			if(param==1)
    			{
    				client.chatMessage(config.admin1, '[SERVER] No more Rake Queries!');
    				return;
    			}
    		}
    	});	
    }
    

    Output after running through:

    I always have no items in my offer and i get the following console output:

    2017-06-26T11:58:45.599Z - info: [RAKECHECK] Calling the Sending Function
    2017-06-26T11:58:45.631Z - info: [RAKECHECK] Selected the correct Table for DB
    2017-06-26T11:58:45.632Z - info: [RAKECHECK] Selected Table is not empty, continue
    2017-06-26T11:58:45.632Z - info: [RAKECHECK] Splitting the AssetID from our DB devided by Slash
    2017-06-26T11:58:46.460Z - info: [RAKECHECK] getInventoryContents called!
    2017-06-26T11:58:46.460Z - info: [RAKECHECK] Found 123 CS:GO items
    2017-06-26T11:58:46.460Z - info: [RAKECHECK] Token: MzGQSP3P found!
    2017-06-26T11:58:46.460Z - info: [RAKECHECK] Game ID: 17 found!
    2017-06-26T11:58:46.460Z - info: [RAKECHECK] Value: 0.01 found!
    2017-06-26T11:58:46.461Z - info: [RAKECHECK] Steam ID: 76561197995793247 found!
    2017-06-26T11:58:46.461Z - info: [RAKECHECK] createOffer: ID:76561197995793247 TKN:MzGQSP3P
    2017-06-26T11:58:46.461Z - info: [RAKECHECK] Items: 0 and this *Insult here* is still not working
    

    I think im stucked and i just cant see the fault i made.

    I have read the documentation so often that i consider buying any other book to get something other in my mind, also tried example bots to fit with my code and, and, and... finally i hope i can get some one to help with this.

     

    Cheers.

×
×
  • Create New...