Hi!
I’m trying to build a simple STEAM bot for my Meteor application but I hit a roadblock as I can’t figure out how to correctly use Meteor.wrapAsync in order to correctly display the results on the front.
My code looks like this:
1. SERVER
import SteamUser from 'steam-user';
import SteamTotp from 'steam-totp';
import SteamCommunity from 'steamcommunity';
import TradeOfferManager from 'steam-tradeoffer-manager';
tradeBot1 = Meteor.settings.SteamTradeBot1;
// Vars
const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager({
steam: client,
community: community,
language: 'en'
});
const logOnOptionsBot1 = {
accountName: tradeBot1.username,
password: tradeBot1.password,
twoFactorCode: SteamTotp.generateAuthCode(tradeBot1.sharedSecret)
};
// Bot login
client.logOn(logOnOptionsBot1);
// After login set bot as online
client.on('loggedOn', Meteor.bindEnvironment(function(){
console.log('Steam Trade Bot #1 online.');
client.setPersona(SteamUser.Steam.EPersonaState.Online);
}));
// Set cookies
client.on('webSession', Meteor.bindEnvironment(function(sessionid, cookies){
manager.setCookies(cookies);
community.setCookies(cookies);
}));
Meteor.methods({
"sendTradeOffer": function(tradeUrl, winId, uid){
try {
var assetId = "1111111111";
var appid = "730";
var itemName = "itemnamexxxxxxx";
// Create new offer
// https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOfferManager
const offer = manager.createOffer(tradeUrl);
// Add item to offer
offer.addMyItem({
'assetid': assetId,
'appid': appid,
'contextid': 2,
'amount': 1
});
// Set custom message
offer.setMessage(`Congrats! You got "${itemName}"! Ref: "` + winId + `"`);
// Send offer
offer.send(Meteor.bindEnvironment(function(err, status){
if (err) {
console.log(err);
return err;
} else {
console.log(`Sent offer. Status: ${status}. Waiting for auto confirmation ...`);
// Set a 5 second delay before confirmation
Meteor.setTimeout(function(){
community.acceptConfirmationForObject(tradeBot1.indentitySecret, offer.id, Meteor.bindEnvironment(function(err){
if (err) {
console.log(err);
return err;
} else {
console.log("Offer confirmed.");
console.log("Sent Steam item with ID: " + assetId);
// Update data in mongo
// .....
// Return something to the front ???
var outcome = {
message: "Trade offer sent!"
}
return outcome;
}
}));
}, 5000);
}
}));
} catch(error){
console.log(error);
return error;
}
}
});
2. FRONT
'submit form#send-trade': function(event, t){
event.preventDefault();
var tradeUrl = $("#user-trade-url").val();
var winId = "winidxxxxxxx";
var uid = "uidxxxxxxx";
Meteor.call("sendTradeOffer", tradeUrl, winId, uid, function(error, result){
if (error){
console.log(error);
} else {
console.log(result);
}
});
}
What this should do is:
- Bot login - working
- Set bot status to online after login - working
- User enters their tradeUrl on the front - working
- Meteor method sendTradeOffer is executed - working
- Offer is sent and confirmed - working
- Return error or result in the front - not working
Console.logs on server works just fine but I can’t return anything to the front, it’s always undefined.
I’ve searched around quite a bit this past couple of days and from my understanding I should be using Meteor.wrapAsync to correctly return either an error or a result but I simply can’t wrap my head around it. How would Meteor.wrapAsync would apply in my case?
Any help is much appreciated.
Many thanks!