Zorenko Posted April 15, 2019 Report Posted April 15, 2019 I have code SteamCommunity.prototype.uploadAvatar = function(image, format, callback) { if(typeof format === 'function') { callback = format; format = null; } // are we logged in? if (!this.steamID) { callback(new Error("Not Logged In")); return; } var self = this; if(image instanceof Buffer) { doUpload(image); } else if(image.match(/^https?:\/\//)) { this.httpRequestGet({ "uri": image, "encoding": null }, function(err, response, body) { if(err || response.statusCode != 200) { if(callback) { callback(err ? new Error(err.message + " downloading image") : new Error("HTTP error " + response.statusCode + " downloading image")); } return; } if(!format) { format = response.headers['content-type']; } doUpload(body); }, "steamcommunity"); } else { if(!format) { format = image.match(/\.([^\.]+)$/); if(format) { format = format[1]; } } FS.readFile(image, function(err, file) { if(err) { if(callback) { callback(err); } return; } doUpload(file); }) } function doUpload(buffer) { if(!format) { if(callback) { callback(new Error("Unknown image format")); } return; } if(format.match(/^image\//)) { format = format.substring(6); } var filename = ''; var contentType = ''; switch(format.toLowerCase()) { case 'jpg': case 'jpeg': filename = 'avatar.jpg'; contentType = 'image/jpeg'; break; case 'png': filename = 'avatar.png'; contentType = 'image/png'; break; case 'gif': filename = 'avatar.gif'; contentType = 'image/gif'; break; default: if(callback) { callback(new Error("Unknown or invalid image format")); } return; } self.httpRequestPost({ "uri": "https://steamcommunity.com/actions/FileUploader", "formData": { "MAX_FILE_SIZE": buffer.length, "type": "player_avatar_image", "sId": self.steamID.getSteamID64(), "sessionid": self.getSessionID(), "doSub": 1, "json": 1, "avatar": { "value": buffer, "options": { "filename": filename, "contentType": contentType } } }, "json": true }, function(err, response, body) { if(err) { if(callback) { callback(err); } return; } if(body && !body.success && body.message) { if(callback) { callback(new Error(body.message)); } return; } if(response.statusCode != 200) { if(callback) { callback(new Error("HTTP error " + response.statusCode)); } return; } if(!body || !body.success) { if(callback) { callback(new Error("Malformed response")); } return; } if(callback) { callback(null, body.images.full); } }, "steamcommunity"); } }; How to choose a photo and upload it? Quote
Zorenko Posted April 15, 2019 Author Report Posted April 15, 2019 (edited) steam.login(logOnOptions, function(err, sessionID, cookies, steamguard) { if (err) { console.log("[Bot] There was an error logging in! Error details: " + err.message); process.exit(1); //terminates program } else { console.log("[Bot] Successfully logged in as " + logOnOptions.accountName); steam.chatLogon(); community.uploadAvatar('https://trinixy.ru/pics5/20180508/uncommon_01.jpg'); manager.setCookies(cookies, function(err) { if (err) { console.log(err); process.exit(1); } }); } steam.startConfirmationChecker(20000, identitySecret); //Auto-confirmation enabled! }); Error: C:\Users\a\Desktop\d>node Donation-Bot.js [Bot] Successfully logged in as john200214 C:\Users\a\node_modules\steamcommunity\components\profile.js:254 callback(new Error("Not Logged In")); ^ TypeError: callback is not a function at SteamCommunity.uploadAvatar (C:\Users\a\node_modules\steamcommunity\components\profile.js:254:3) at C:\Users\a\Desktop\d\Donation-Bot.js:29:13 at SteamCommunity.<anonymous> (C:\Users\a\node_modules\steamcommunity\index.js:202:5) at Request._callback (C:\Users\a\node_modules\steamcommunity\components\http.js:67:15) at Request.self.callback (C:\Users\a\node_modules\request\request.js:185:22) at Request.emit (events.js:189:13) at Request.<anonymous> (C:\Users\a\node_modules\request\request.js:1161:10) at Request.emit (events.js:189:13) at Gunzip.<anonymous> (C:\Users\a\node_modules\request\request.js:1083:12) at Object.onceWrapper (events.js:277:13) C:\Users\a\Desktop\d>pause Edited April 15, 2019 by Zorenko Zorenko 1 Quote
Dr. McKay Posted April 15, 2019 Report Posted April 15, 2019 You probably want to use steam.uploadAvatar and not community.uploadAvatar. Also, attach a callback. Also also, don't use the auto-confirmation checker. Zorenko 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.