Hi, someone can help me with this problem? When some trade offer that was sent by bot has set to Declined , Expired or Canceled, this is the result: This is the code:
manager.on('sentOfferChanged', function(offer, oldState) {
console.log(TagGF+'Offer '+offer.id+' changed: '+TradeOfferManager.ETradeOfferState[oldState]+' -> '+TradeOfferManager.ETradeOfferState[offer.state]+'');
if(offer.state == TradeOfferManager.ETradeOfferState.Declined || offer.state == TradeOfferManager.ETradeOfferState.Canceled || offer.state == TradeOfferManager.ETradeOfferState.Expired || offer.state == TradeOfferManager.ETradeOfferState.CanceledBySecondFactor || offer.state == TradeOfferManager.ETradeOfferState.Countered) {
console.log(TagGF+"Offer '"+offer.id+"' has been '"+TradeOfferManager.ETradeOfferState[offer.state]+"'");
if(offer.state == TradeOfferManager.ETradeOfferState.Countered) {
offer.decline(function(err) {
if (err) {
console.log(TagGF+"Unable to decline offer: " + err.message);
} else {
console.log(TagGF+"Offer Declined! (Countered Trade!)");
}
});
}
if(offer.itemsToGive.length > 0) {
offer.getExchangeDetails(function(err, status, tradeInitTime, receivedItems, sentItems) {
if(err) {
console.log(TagGF+"Couldn't get sent items (aD): " + err);
} else {
var names = sentItems.map(function(item) {
return item.name;
});
if(sentItems.length > 0) {
for(var i = 0; i < sentItems.length; i++) {
pool.query("UPDATE gf_user_items SET intrade='0' WHERE assetid='"+sentItems[i].assetid+"'", function(err) {
if(err) {
console.log(TagGF_Error+"Error Unsetting Item InTrade!");
console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
});
}
}
}
});
}
} else if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
if(offer.itemsToReceive.length > 0) {
//DEPOSIT
offer.getReceivedItems(function(err, items) {
if (err) {
console.log(TagGF+"Couldn't get received items: " + err);
} else {
var names = items.map(function(item) {
return item.name;
});
if(items.length > 0) {
console.log(TagGF+"Received: " + names.join(', '));
pool.query("SELECT * FROM gf_trades WHERE tradeoffer_id='"+offer.id+"'", function(err, res) {
if((err)||(!res[0])) {
console.log(TagGF_Error+"Error Finding EID of the User Associated to this Trade Offer ("+offer.id+")");
if(err) console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
var eid = res[0].user_eid;
console.log(TagGF+"Saving Items Info to User EID: "+eid);
for(var i = 0; i < items.length; i++) {
var price;
var itemI = items[i];
var marketName = itemI.market_hash_name;
var args = querystring.stringify({name:marketName});
//var options = {host:'csgocf.cf',path:'/_api/GF_GetCachedPrice.php?'+args};
/*var request = http_.request(options, function (res) {
var data = '';
var eid = eid;
var item = itemI;
var mN = marketName;
var assetID = item.assetid;
var imageURL = item.icon_url;
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
price = data;
console.log(TagGF+"The Price of this Skins: "+price);
});
});
request.on('error', function (e) {
price = "0.00";
console.log(TagGF_Error+"Error Getting the Price of \""+marketName+"\"");
console.log(TagGF_Error+"Explained Error: "+e)
});
request.end();*/
var item = itemI;
var mN = marketName;
var assetID = item.assetid;
var imageURL = item.icon_url;
pool.query("INSERT INTO gf_user_items (user_eid,name,assetid,imageurl,price) VALUES('"+eid+"', '"+mN+"', '"+assetID+"', '"+imageURL+"', '"+price+"')", function(err) {
if(err) {
console.log(TagGF_Error+"Error Saving Item into User!");
console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
});
var options = {host:'csgocf.cf',path:'/_api/GF_UpdatePrices.php?c'};
request.get('http://csgocf.cf/_api/GF_UpdatePrices.php?c',options,function(err,res,body){
if(err) { console.log(TagGF+Errpr+"Error Updating Skins Prices on Database!");return; }
if(res.statusCode !== 200 ) { console.log(TagGF+Errpr+"Error Updating Skins Prices on Database!");return; }
console.log(TagGF+"All Prices Updated!");
});
//DEBUG console.log(items[i]);
}
console.log(TagGF+"Trade Offer Status Updated! (OfferID:"+offer.id+"|AcceptedStatus:1)");
ToastR_EID("Trade offer accepted. ("+offer.id+")","success",eid);
UpdateInventorys(eid);
});
}
}
});
} else if(offer.itemsToGive.length > 0) {
//WITHDRAW
offer.getExchangeDetails(function(err, status, tradeInitTime, receivedItems, sentItems) {
if (err) {
console.log(TagGF+"Couldn't get sent items: " + err);
} else {
var names = sentItems.map(function(item) {
return item.name;
});
if(sentItems.length > 0) {
//console.log(TagGF+"Removing: " + names.join(', '));
pool.query("SELECT * FROM gf_trades WHERE tradeoffer_id='"+offer.id+"'", function(err, res) {
if((err)||(!res[0])) {
console.log(TagGF_Error+"Error Finding EID of the User Associated to this Trade Offer ("+offer.id+")");
if(err) console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
var eid = res[0].user_eid;
console.log(TagGF+"Removing Items Info to User EID: "+eid);
for(var i = 0; i < sentItems.length; i++) {
//DEBUG console.log(sentItems[i]);
pool.query("DELETE FROM gf_user_items WHERE assetid='"+sentItems[i].assetid+"' AND user_eid='"+eid+"'", function(err) {
if(err) {
console.log(TagGF_Error+"Error Removing Item into User!");
console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
});
}
pool.query("UPDATE gf_trades SET accepted='1' WHERE tradeoffer_id='"+offer.id+"'", function(err) {
if(err) {
console.log(TagGF_Error+"Error Updating Trade Offer Status!");
console.log(TagGF_Error+"Explained Error Message: "+err);
return;
}
console.log(TagGF+"Trade Offer Status Updated! (OfferID:"+offer.id+"|AcceptedStatus:1)");
ToastR_EID("Trade offer accepted. ("+offer.id+")","success",eid);
UpdateInventorys(eid);
});
});
}
}
});
}
}
});