lll Posted March 20, 2020 Report Posted March 20, 2020 I have a Bot class and an async method for logIn, are there any better way for writing this method? completeLogin(botDetails, useLoginKey) { this.user.logOn(this.details(botDetails, useLoginKey)); return new Promise((done, reject) => { const cxt = this; async function success(_, cookies) { try { await cxt.setCookies(cookies); cxt.user.off('error', failed); done(); } catch(err) { reject(err); } } function failed(err) { cxt.user.off('webSession', success); reject(err); } cxt.user.once('webSession', success); cxt.user.once('error', failed); }); } Quote
Dr. McKay Posted March 21, 2020 Report Posted March 21, 2020 That looks fine, although you aren't going to handle any scenarios where the bot gets kicked off of Steam after logon. Quote
lll Posted March 21, 2020 Author Report Posted March 21, 2020 This logic will be written in the constructor. Something like this : constructor(accountName) { this.setCookies = util.promisify(this.manager.setCookies).bind(this.manager); this.user.on('error', this.logOut); this.user.on('loginKey', loginKey => db.findOne('bot', { accountName }, { loginKey })); } Dr. McKay 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.