mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-14 21:10:28 +08:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # .idea/encodings.xml
This commit is contained in:
commit
fbfff1398b
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
node-steamcommunity
|
13
.idea/codeStyleSettings.xml
Normal file
13
.idea/codeStyleSettings.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
</value>
|
||||
</option>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||
</component>
|
||||
</project>
|
3
.idea/copyright/profiles_settings.xml
Normal file
3
.idea/copyright/profiles_settings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
8
.idea/node-steamcommunity.iml
Normal file
8
.idea/node-steamcommunity.iml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
4
.idea/watcherTasks.xml
Normal file
4
.idea/watcherTasks.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectTasksOptions" suppressed-tasks="Babel" />
|
||||
</project>
|
@ -123,6 +123,10 @@ CSteamGroup.prototype.deleteComment = function(cid, callback) {
|
||||
this._community.deleteGroupComment(this.steamID, cid, callback);
|
||||
};
|
||||
|
||||
CSteamGroup.prototype.comment = function(message, callback) {
|
||||
this._community.postGroupComment(this.steamID, message, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get requests to join this restricted group.
|
||||
* @param {function} callback - First argument is null/Error, second is array of SteamID objects
|
||||
|
@ -5,17 +5,22 @@ SteamCommunity.ChatState = require('../resources/EChatState.js');
|
||||
SteamCommunity.PersonaState = require('../resources/EPersonaState.js');
|
||||
SteamCommunity.PersonaStateFlag = require('../resources/EPersonaStateFlag.js');
|
||||
|
||||
/**
|
||||
* @deprecated No support for new Steam chat. Use steam-user instead.
|
||||
* @param {int} interval
|
||||
* @param {string} uiMode
|
||||
*/
|
||||
SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
if(this.chatState == SteamCommunity.ChatState.LoggingOn || this.chatState == SteamCommunity.ChatState.LoggedOn) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
interval = interval || 500;
|
||||
uiMode = uiMode || "web";
|
||||
|
||||
|
||||
this.emit('debug', 'Requesting chat WebAPI token');
|
||||
this.chatState = SteamCommunity.ChatState.LoggingOn;
|
||||
|
||||
|
||||
var self = this;
|
||||
this.getWebApiOauthToken(function(err, token) {
|
||||
if(err) {
|
||||
@ -32,7 +37,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
self.emit('debug', "Cannot get oauth token: " + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self.httpRequestPost({
|
||||
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1",
|
||||
"form": {
|
||||
@ -48,7 +53,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
setTimeout(self.chatLogon.bind(self), 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(body.error != 'OK') {
|
||||
self.chatState = SteamCommunity.ChatState.LogOnFailed;
|
||||
self.emit('chatLogOnFailed', new Error(body.error), false);
|
||||
@ -56,7 +61,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
setTimeout(self.chatLogon.bind(self), 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self._chat = {
|
||||
"umqid": body.umqid,
|
||||
"message": body.message,
|
||||
@ -64,9 +69,9 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
"interval": interval,
|
||||
"uiMode": uiMode
|
||||
};
|
||||
|
||||
|
||||
self.chatFriends = {};
|
||||
|
||||
|
||||
self.chatState = SteamCommunity.ChatState.LoggedOn;
|
||||
self.emit('chatLoggedOn');
|
||||
self._chatPoll();
|
||||
@ -74,20 +79,27 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated No support for new Steam chat. Use steam-user instead.
|
||||
* @param {string|SteamID} recipient
|
||||
* @param {string} text
|
||||
* @param {string} [type]
|
||||
* @param {function} [callback]
|
||||
*/
|
||||
SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback) {
|
||||
if(this.chatState != SteamCommunity.ChatState.LoggedOn) {
|
||||
throw new Error("Chat must be logged on before messages can be sent");
|
||||
}
|
||||
|
||||
|
||||
if(typeof recipient === 'string') {
|
||||
recipient = new SteamID(recipient);
|
||||
}
|
||||
|
||||
|
||||
if(typeof type === 'function') {
|
||||
callback = type;
|
||||
type = 'saytext';
|
||||
}
|
||||
|
||||
|
||||
type = type || 'saytext';
|
||||
|
||||
var self = this;
|
||||
@ -105,12 +117,12 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(body.error != 'OK') {
|
||||
callback(new Error(body.error));
|
||||
} else {
|
||||
@ -119,6 +131,9 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated No support for new Steam chat. Use steam-user instead.
|
||||
*/
|
||||
SteamCommunity.prototype.chatLogoff = function() {
|
||||
var self = this;
|
||||
this.httpRequestPost({
|
||||
@ -141,9 +156,12 @@ SteamCommunity.prototype.chatLogoff = function() {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SteamCommunity.prototype._chatPoll = function() {
|
||||
this.emit('debug', 'Doing chat poll');
|
||||
|
||||
|
||||
var self = this;
|
||||
this.httpRequestPost({
|
||||
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Poll/v1",
|
||||
@ -161,9 +179,9 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
if (self.chatState == SteamCommunity.ChatState.Offline) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self._chat.timer = setTimeout(self._chatPoll.bind(self), self._chat.interval);
|
||||
|
||||
|
||||
if(err || response.statusCode != 200) {
|
||||
self.emit('debug', 'Error in chat poll: ' + (err ? err.message : "HTTP error " + response.statusCode));
|
||||
if (err.message == "Not Logged On") {
|
||||
@ -172,7 +190,7 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!body || body.error != 'OK') {
|
||||
self.emit('debug', 'Error in chat poll: ' + (body && body.error ? body.error : "Malformed response"));
|
||||
if (body && body.error && body.error == "Not Logged On") {
|
||||
@ -181,29 +199,29 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self._chat.message = body.messagelast;
|
||||
|
||||
|
||||
(body.messages || []).forEach(function(message) {
|
||||
var sender = new SteamID();
|
||||
sender.universe = SteamID.Universe.PUBLIC;
|
||||
sender.type = SteamID.Type.INDIVIDUAL;
|
||||
sender.instance = SteamID.Instance.DESKTOP;
|
||||
sender.accountid = message.accountid_from;
|
||||
|
||||
|
||||
switch(message.type) {
|
||||
case 'personastate':
|
||||
self._chatUpdatePersona(sender);
|
||||
break;
|
||||
|
||||
|
||||
case 'saytext':
|
||||
self.emit('chatMessage', sender, message.text);
|
||||
break;
|
||||
|
||||
|
||||
case 'typing':
|
||||
self.emit('chatTyping', sender);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
self.emit('debug', 'Unhandled chat message type: ' + message.type);
|
||||
}
|
||||
@ -211,6 +229,9 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SteamCommunity.prototype._relogWebChat = function() {
|
||||
this.emit('debug', "Relogging web chat");
|
||||
clearTimeout(this._chat.timer);
|
||||
@ -218,6 +239,10 @@ SteamCommunity.prototype._relogWebChat = function() {
|
||||
this.chatLogon(this._chat.interval, this._chat.uiMode);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {SteamID} steamID
|
||||
* @private
|
||||
*/
|
||||
SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
|
||||
if (!this.chatFriends || this.chatState == SteamCommunity.ChatState.Offline) {
|
||||
return; // we no longer care
|
||||
@ -240,7 +265,7 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var persona = {
|
||||
"steamID": steamID,
|
||||
"personaName": body.m_strName,
|
||||
@ -255,4 +280,4 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
|
||||
self.emit('chatPersonaState', steamID, persona);
|
||||
self.chatFriends[steamID.getSteamID64()] = persona;
|
||||
}, "steamcommunity");
|
||||
};
|
||||
};
|
||||
|
@ -591,6 +591,30 @@ SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.postGroupComment = function(gid, message, callback) {
|
||||
if (typeof gid === 'string') {
|
||||
gid = new SteamID(gid);
|
||||
}
|
||||
|
||||
var options = {
|
||||
"uri": "https://steamcommunity.com/comment/Clan/post/" + gid.getSteamID64() + "/-1/",
|
||||
"form": {
|
||||
"comment": message,
|
||||
"count": 6,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
};
|
||||
|
||||
var self = this;
|
||||
this.httpRequestPost(options, function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err || null);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get requests to join a restricted group.
|
||||
* @param {SteamID|string} gid - The SteamID of the group you want to manage
|
||||
|
@ -14,7 +14,7 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
||||
return callback(new Error("Access Denied"));
|
||||
}
|
||||
|
||||
|
||||
if(body.match(/You must have a validated email address to create a Steam Web API key./)) {
|
||||
return callback(new Error("You must have a validated email address to create a Steam Web API key."));
|
||||
}
|
||||
@ -44,6 +44,10 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated No longer works if not logged in via mobile login. Will be removed in a future release.
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
|
||||
var self = this;
|
||||
|
||||
|
38
index.js
38
index.js
@ -5,7 +5,7 @@ const Request = require('request');
|
||||
const RSA = require('node-bignumber').Key;
|
||||
const SteamID = require('steamid');
|
||||
|
||||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
|
||||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
|
||||
|
||||
require('util').inherits(SteamCommunity, require('events').EventEmitter);
|
||||
|
||||
@ -13,7 +13,7 @@ module.exports = SteamCommunity;
|
||||
|
||||
SteamCommunity.SteamID = SteamID;
|
||||
SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js');
|
||||
SteamCommunity.EResult = require('./resources/EResult.js')
|
||||
SteamCommunity.EResult = require('./resources/EResult.js');
|
||||
|
||||
|
||||
function SteamCommunity(options) {
|
||||
@ -249,6 +249,40 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a token that can be used to log onto Steam using steam-user.
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getClientLogonToken = function(callback) {
|
||||
this.httpRequestGet({
|
||||
"uri": "https://steamcommunity.com/chat/clientjstoken",
|
||||
"json": true
|
||||
}, (err, res, body) => {
|
||||
if (err || res.statusCode != 200) {
|
||||
callback(err ? err : new Error('HTTP error ' + res.statusCode));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.logged_in) {
|
||||
let e = new Error('Not Logged In');
|
||||
callback(e);
|
||||
this._notifySessionExpired(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.steamid || !body.account_name || !body.token) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
"steamID": new SteamID(body.steamid),
|
||||
"accountName": body.account_name,
|
||||
"webLogonToken": body.token
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._setCookie = function(cookie, secure) {
|
||||
var protocol = secure ? "https" : "http";
|
||||
cookie.secure = !!secure;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "steamcommunity",
|
||||
"version": "3.38.0",
|
||||
"version": "3.39.0",
|
||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||
"keywords": [
|
||||
"steam",
|
||||
|
Loading…
Reference in New Issue
Block a user