mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2024-12-29 16:10:12 +08:00
Better handling for missing items in user XML
This commit is contained in:
parent
f3cf2a4361
commit
4e1453e702
@ -41,7 +41,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
if(!result.profile.steamID64 || !result.profile.onlineState) {
|
||||
if(!result.profile.steamID64) {
|
||||
callback(new Error("No valid response"));
|
||||
return;
|
||||
}
|
||||
@ -55,22 +55,26 @@ function CSteamUser(community, userData, customurl) {
|
||||
this._community = community;
|
||||
|
||||
this.steamID = new SteamID(userData.steamID64[0]);
|
||||
this.name = userData.steamID[0];
|
||||
this.onlineState = userData.onlineState[0];
|
||||
this.stateMessage = userData.stateMessage[0];
|
||||
this.privacyState = userData.privacyState[0];
|
||||
this.visibilityState = userData.visibilityState[0];
|
||||
this.avatarHash = userData.avatarIcon[0].match(/([0-9a-f]+)\.[a-z]+$/)[1];
|
||||
this.vacBanned = !!userData.vacBanned[0];
|
||||
this.tradeBanState = userData.tradeBanState[0];
|
||||
this.isLimitedAccount = !!userData.isLimitedAccount[0];
|
||||
this.customURL = userData.customURL ? userData.customURL[0] : customurl;
|
||||
this.name = processItem(userData, 'steamID');
|
||||
this.onlineState = processItem(userData, 'onlineState');
|
||||
this.stateMessage = processItem(userData, 'stateMessage');
|
||||
this.privacyState = processItem(userData, 'privacyState', 'uncreated');
|
||||
this.visibilityState = processItem(userData, 'visibilityState');
|
||||
this.avatarHash = processItem(userData, 'avatarIcon', '').match(/([0-9a-f]+)\.[a-z]+$/);
|
||||
if(this.avatarHash) {
|
||||
this.avatarHash = this.avatarHash[1];
|
||||
}
|
||||
|
||||
this.vacBanned = !!processItem(userData, 'vacBanned', false);
|
||||
this.tradeBanState = processItem(userData, 'tradeBanState', 'None');
|
||||
this.isLimitedAccount = !!processItem(userData, 'isLimitedAccount');
|
||||
this.customURL = processItem(userData, 'customURL', customurl);
|
||||
|
||||
if(this.visibilityState == 3) {
|
||||
this.memberSince = new Date(userData.memberSince[0].replace(/(\d{1,2})(st|nd|th)/, "$1"));
|
||||
this.location = userData.location[0] || null;
|
||||
this.realName = userData.realname[0] || null;
|
||||
this.summary = userData.summary[0] || null;
|
||||
this.memberSince = new Date(processItem(userData, 'memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1"));
|
||||
this.location = processItem(userData, 'location');
|
||||
this.realName = processItem(userData, 'realname');
|
||||
this.summary = processItem(userData, 'summary');
|
||||
} else {
|
||||
this.memberSince = null;
|
||||
this.location = null;
|
||||
@ -93,6 +97,14 @@ function CSteamUser(community, userData, customurl) {
|
||||
return new SteamID(group.groupID64[0]);
|
||||
});
|
||||
}
|
||||
|
||||
function processItem(name, defaultVal) {
|
||||
if(!userData[name]) {
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
return userData[name][0];
|
||||
}
|
||||
}
|
||||
|
||||
CSteamUser.getAvatarURL = function(hash, size, protocol) {
|
||||
|
Loading…
Reference in New Issue
Block a user