2019-02-14 13:29:21 +08:00
const Cheerio = require ( 'cheerio' ) ;
const SteamID = require ( 'steamid' ) ;
const XML2JS = require ( 'xml2js' ) ;
const Helpers = require ( './helpers.js' ) ;
const SteamCommunity = require ( '../index.js' ) ;
const EResult = SteamCommunity . EResult ;
2015-08-05 11:37:16 +08:00
2015-08-05 11:40:10 +08:00
SteamCommunity . prototype . getGroupMembers = function ( gid , callback , members , link , addresses , addressIdx ) {
2015-08-05 11:37:16 +08:00
members = members || [ ] ;
if ( ! link ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid != 'string' ) {
2015-08-05 11:37:16 +08:00
// It's a SteamID object
2021-07-22 16:22:29 +08:00
link = ` https://steamcommunity.com/gid/ ${ gid . toString ( ) } /memberslistxml/?xml=1 ` ;
2015-08-05 11:37:16 +08:00
} else {
try {
2019-09-24 16:38:27 +08:00
// new SteamID could throw which is why we have this funky-looking try/catch set up here
let sid = new SteamID ( gid ) ;
2015-08-05 11:37:16 +08:00
if ( sid . type == SteamID . Type . CLAN && sid . isValid ( ) ) {
2021-07-22 16:22:29 +08:00
link = ` https://steamcommunity.com/gid/ ${ sid . getSteamID64 ( ) } /memberslistxml/?xml=1 ` ;
2015-08-05 11:37:16 +08:00
} else {
2021-07-22 16:22:29 +08:00
throw new Error ( 'Doesn\'t particularly matter what this message is' ) ;
2015-08-05 11:37:16 +08:00
}
} catch ( e ) {
2021-07-22 16:22:29 +08:00
link = ` http://steamcommunity.com/groups/ ${ gid } /memberslistxml/?xml=1 ` ;
2015-08-05 11:37:16 +08:00
}
}
}
2015-08-05 11:40:10 +08:00
addressIdx = addressIdx || 0 ;
2019-09-24 16:38:27 +08:00
let options = { } ;
2015-08-05 11:40:10 +08:00
options . uri = link ;
2019-09-24 16:38:27 +08:00
if ( addresses ) {
if ( addressIdx >= addresses . length ) {
2015-08-05 11:40:10 +08:00
addressIdx = 0 ;
}
options . localAddress = addresses [ addressIdx ] ;
}
2019-09-24 16:38:27 +08:00
this . httpRequest ( options , ( err , response , body ) => {
2016-03-05 12:59:49 +08:00
if ( err ) {
callback ( err ) ;
2015-08-05 11:37:16 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
XML2JS . parseString ( body , ( err , result ) => {
2015-08-05 11:37:16 +08:00
if ( err ) {
callback ( err ) ;
return ;
}
2019-09-24 16:38:27 +08:00
members = members . concat ( result . memberList . members [ 0 ] . steamID64 . map ( sid => new SteamID ( sid ) ) ) ;
2015-08-05 11:37:16 +08:00
if ( result . memberList . nextPageLink ) {
2015-08-05 11:40:10 +08:00
addressIdx ++ ;
2019-09-24 16:38:27 +08:00
this . getGroupMembers ( gid , callback , members , result . memberList . nextPageLink [ 0 ] , addresses , addressIdx ) ;
2015-08-05 11:37:16 +08:00
} else {
callback ( null , members ) ;
}
} ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
2015-08-05 11:40:10 +08:00
SteamCommunity . prototype . getGroupMembersEx = function ( gid , addresses , callback ) {
this . getGroupMembers ( gid , callback , null , null , addresses , 0 ) ;
} ;
2015-08-05 11:37:16 +08:00
SteamCommunity . prototype . joinGroup = function ( gid , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
2016-03-05 07:26:47 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } ` ,
2021-07-22 16:22:29 +08:00
form : {
action : 'join' ,
sessionID : this . getSessionID ( )
2015-08-05 11:37:16 +08:00
}
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
SteamCommunity . prototype . leaveGroup = function ( gid , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
2021-07-22 16:22:29 +08:00
this . _myProfile ( 'home_process' , {
sessionID : this . getSessionID ( ) ,
action : 'leaveGroup' ,
groupId : gid . getSteamID64 ( )
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2015-08-05 11:37:16 +08:00
} ) ;
} ;
2016-01-17 02:39:04 +08:00
SteamCommunity . prototype . getAllGroupAnnouncements = function ( gid , time , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2016-01-16 08:06:42 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
if ( typeof time == 'function' ) {
2016-01-16 08:06:42 +08:00
callback = time ;
time = new Date ( 0 ) ; // The beginnig of time...
}
2016-03-05 07:26:47 +08:00
this . httpRequest ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /rss/ `
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
2016-03-05 12:59:49 +08:00
if ( err ) {
callback ( err ) ;
2016-01-16 08:06:42 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
XML2JS . parseString ( body , ( err , results ) => {
if ( err ) {
2016-01-16 08:06:42 +08:00
return callback ( err ) ;
}
2019-09-24 16:38:27 +08:00
if ( ! results . rss . channel [ 0 ] . item ) {
2016-01-16 08:06:42 +08:00
return callback ( null , [ ] ) ;
}
2019-09-24 16:38:27 +08:00
let announcements = results . rss . channel [ 0 ] . item . map ( ( announcement ) => {
let splitLink = announcement . link [ 0 ] . split ( '/' ) ;
2016-01-16 08:06:42 +08:00
return {
headline : announcement . title [ 0 ] ,
2019-09-24 16:38:27 +08:00
content : announcement . description [ 0 ] ,
date : new Date ( announcement . pubDate [ 0 ] ) ,
author : ( typeof announcement . author === 'undefined' ) ? null : announcement . author [ 0 ] ,
aid : splitLink [ splitLink . length - 1 ]
2021-07-29 14:55:56 +08:00
} ;
2019-09-24 16:38:27 +08:00
} ) . filter ( announcement => announcement . date > time ) ;
2016-01-16 08:06:42 +08:00
return callback ( null , announcements ) ;
} ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-08-07 07:08:45 +08:00
} ;
2016-01-16 08:06:42 +08:00
2019-10-14 10:28:53 +08:00
SteamCommunity . prototype . postGroupAnnouncement = function ( gid , headline , content , hidden , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
2021-07-22 15:37:06 +08:00
if ( typeof hidden === 'function' ) {
2019-10-14 10:28:53 +08:00
callback = hidden ;
hidden = false ;
}
2021-07-22 15:37:06 +08:00
let form = {
2021-07-22 16:22:29 +08:00
sessionID : this . getSessionID ( ) ,
action : 'post' ,
headline : headline ,
body : content ,
'languages[0][headline]' : headline ,
'languages[0][body]' : content
2019-10-14 10:28:53 +08:00
} ;
2021-07-22 15:37:06 +08:00
if ( hidden ) {
2021-07-29 14:55:56 +08:00
form . is _hidden = 'is_hidden' ;
2019-10-14 10:28:53 +08:00
}
2021-07-22 15:37:06 +08:00
2016-03-05 07:26:47 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /announcements ` ,
2019-10-14 10:28:53 +08:00
form
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
2021-07-22 16:22:29 +08:00
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
2016-01-16 01:48:57 +08:00
SteamCommunity . prototype . editGroupAnnouncement = function ( gid , aid , headline , content , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2016-01-16 01:48:57 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
let submitData = {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /announcements ` ,
2021-07-22 16:22:29 +08:00
form : {
sessionID : this . getSessionID ( ) ,
gid : aid ,
action : 'update' ,
headline : headline ,
body : content ,
'languages[0][headline]' : headline ,
'languages[0][body]' : content ,
'languages[0][updated]' : 1
2016-01-16 01:48:57 +08:00
}
2016-03-05 12:59:49 +08:00
} ;
2016-01-16 01:48:57 +08:00
2019-09-24 16:38:27 +08:00
this . httpRequestPost ( submitData , ( err , response , body ) => {
if ( ! callback ) {
2016-01-16 01:48:57 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2016-01-16 01:48:57 +08:00
} ;
2016-01-17 10:27:11 +08:00
SteamCommunity . prototype . deleteGroupAnnouncement = function ( gid , aid , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2016-01-17 10:27:11 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
let submitData = {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /announcements/delete/ ${ aid } ?sessionID= ${ this . getSessionID ( ) } `
2016-03-05 08:35:04 +08:00
} ;
2016-01-17 10:27:11 +08:00
2019-09-24 16:38:27 +08:00
this . httpRequestGet ( submitData , ( err , response , body ) => {
if ( ! callback ) {
2016-01-17 10:27:11 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2016-01-17 10:27:11 +08:00
} ;
2015-08-05 11:37:16 +08:00
SteamCommunity . prototype . scheduleGroupEvent = function ( gid , name , type , description , time , server , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
// Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion
// Passing a number for type will make it a game event for that appid
2019-09-24 16:38:27 +08:00
switch ( typeof server ) {
case 'function' :
callback = server ;
server = { ip : '' , password : '' } ;
break ;
case 'string' :
server = { ip : server , password : '' } ;
break ;
default :
2021-07-29 14:55:56 +08:00
if ( typeof server != 'object' ) {
2019-09-24 16:38:27 +08:00
server = { ip : '' , password : '' } ;
}
2015-08-05 11:37:16 +08:00
}
2019-09-24 16:38:27 +08:00
let form = {
2021-07-22 16:22:29 +08:00
sessionid : this . getSessionID ( ) ,
action : 'newEvent' ,
tzOffset : new Date ( ) . getTimezoneOffset ( ) * - 60 ,
name : name ,
type : ( typeof type == 'number' || ! isNaN ( parseInt ( type , 10 ) ) ? 'GameEvent' : type ) ,
appID : ( typeof type == 'number' || ! isNaN ( parseInt ( type , 10 ) ) ? type : '' ) ,
serverIP : server . ip ,
serverPassword : server . password ,
notes : description ,
eventQuickTime : 'now'
2015-08-05 11:37:16 +08:00
} ;
2019-09-24 16:38:27 +08:00
if ( time === null ) {
2015-08-05 11:37:16 +08:00
form . startDate = 'MM/DD/YY' ;
form . startHour = '12' ;
form . startMinute = '00' ;
form . startAMPM = 'PM' ;
form . timeChoice = 'quick' ;
} else {
form . startDate = ( time . getMonth ( ) + 1 < 10 ? '0' : '' ) + ( time . getMonth ( ) + 1 ) + '/' + ( time . getDate ( ) < 10 ? '0' : '' ) + time . getDate ( ) + '/' + time . getFullYear ( ) . toString ( ) . substring ( 2 ) ;
form . startHour = ( time . getHours ( ) === 0 ? '12' : ( time . getHours ( ) > 12 ? time . getHours ( ) - 12 : time . getHours ( ) ) ) ;
form . startMinute = ( time . getMinutes ( ) < 10 ? '0' : '' ) + time . getMinutes ( ) ;
form . startAMPM = ( time . getHours ( ) <= 12 ? 'AM' : 'PM' ) ;
2016-06-15 10:29:11 +08:00
form . timeChoice = 'specific' ;
}
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . toString ( ) } /eventEdit ` ,
2019-09-24 16:38:27 +08:00
form
} , ( err , response , body ) => {
if ( ! callback ) {
2016-06-15 10:29:11 +08:00
return ;
}
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2016-06-15 10:29:11 +08:00
} ;
2019-09-24 16:38:27 +08:00
SteamCommunity . prototype . editGroupEvent = function ( gid , id , name , type , description , time , server , callback ) {
2016-06-15 10:29:11 +08:00
if ( typeof gid === 'string' ) {
gid = new SteamID ( gid ) ;
}
// Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion
// Passing a number for type will make it a game event for that appid
2019-09-24 16:38:27 +08:00
switch ( typeof server ) {
case 'function' :
callback = server ;
server = { ip : '' , password : '' } ;
break ;
case 'string' :
server = { ip : server , password : '' } ;
break ;
default :
2021-07-29 14:55:56 +08:00
if ( typeof server != 'object' ) {
2019-09-24 16:38:27 +08:00
server = { ip : '' , password : '' } ;
}
2016-06-15 10:29:11 +08:00
}
2019-09-24 16:38:27 +08:00
let form = {
2021-07-22 16:22:29 +08:00
sessionid : this . getSessionID ( ) ,
action : 'updateEvent' ,
eventID : id ,
tzOffset : new Date ( ) . getTimezoneOffset ( ) * - 60 ,
name : name ,
type : ( typeof type == 'number' || ! isNaN ( parseInt ( type , 10 ) ) ? 'GameEvent' : type ) ,
appID : ( typeof type == 'number' || ! isNaN ( parseInt ( type , 10 ) ) ? type : '' ) ,
serverIP : server . ip ,
serverPassword : server . password ,
notes : description ,
eventQuickTime : 'now'
2016-06-15 10:29:11 +08:00
} ;
if ( time === null ) {
form . startDate = 'MM/DD/YY' ;
form . startHour = '12' ;
form . startMinute = '00' ;
form . startAMPM = 'PM' ;
form . timeChoice = 'quick' ;
} else {
form . startDate = ( time . getMonth ( ) + 1 < 10 ? '0' : '' ) + ( time . getMonth ( ) + 1 ) + '/' + ( time . getDate ( ) < 10 ? '0' : '' ) + time . getDate ( ) + '/' + time . getFullYear ( ) . toString ( ) . substring ( 2 ) ;
form . startHour = ( time . getHours ( ) === 0 ? '12' : ( time . getHours ( ) > 12 ? time . getHours ( ) - 12 : time . getHours ( ) ) ) ;
form . startMinute = ( time . getMinutes ( ) < 10 ? '0' : '' ) + time . getMinutes ( ) ;
form . startAMPM = ( time . getHours ( ) <= 12 ? 'AM' : 'PM' ) ;
2015-08-05 11:37:16 +08:00
form . timeChoice = 'specific' ;
}
2016-03-05 07:26:47 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . toString ( ) } /eventEdit ` ,
2021-07-22 16:22:29 +08:00
form
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
2016-06-22 10:39:23 +08:00
SteamCommunity . prototype . deleteGroupEvent = function ( gid , id , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2016-06-22 10:39:23 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
let form = {
2021-07-22 16:22:29 +08:00
sessionid : this . getSessionID ( ) ,
action : 'deleteEvent' ,
eventID : id
2016-06-22 10:39:23 +08:00
} ;
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . toString ( ) } /eventEdit ` ,
2019-09-24 16:38:27 +08:00
form
} , ( err , response , body ) => {
if ( ! callback ) {
2016-06-22 10:39:23 +08:00
return ;
}
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2016-06-22 10:39:23 +08:00
} ;
2015-08-05 11:37:16 +08:00
SteamCommunity . prototype . setGroupPlayerOfTheWeek = function ( gid , steamID , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
if ( typeof steamID == 'string' ) {
2015-08-05 11:37:16 +08:00
steamID = new SteamID ( steamID ) ;
}
2016-03-05 07:26:47 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /potwEdit ` ,
2021-07-22 16:22:29 +08:00
form : {
xml : 1 ,
action : 'potw' ,
memberId : steamID . getSteam3RenderedID ( ) ,
sessionid : this . getSessionID ( )
2015-08-05 11:37:16 +08:00
}
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
if ( err || response . statusCode != 200 ) {
2021-07-22 16:22:29 +08:00
callback ( err || new Error ( ` HTTP error ${ response . statusCode } ` ) ) ;
2015-08-05 11:37:16 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
XML2JS . parseString ( body , ( err , results ) => {
if ( err ) {
2015-08-05 11:37:16 +08:00
callback ( err ) ;
return ;
}
2019-09-24 16:38:27 +08:00
if ( results . response . results [ 0 ] == 'OK' ) {
2015-08-05 11:37:16 +08:00
callback ( null , new SteamID ( results . response . oldPOTW [ 0 ] ) , new SteamID ( results . response . newPOTW [ 0 ] ) ) ;
} else {
callback ( new Error ( results . response . results [ 0 ] ) ) ;
}
} ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
SteamCommunity . prototype . kickGroupMember = function ( gid , steamID , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 11:37:16 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
if ( typeof steamID == 'string' ) {
2015-08-05 11:37:16 +08:00
steamID = new SteamID ( steamID ) ;
}
2016-03-05 07:26:47 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /membersManage ` ,
2021-07-22 16:22:29 +08:00
form : {
sessionID : this . getSessionID ( ) ,
action : 'kick' ,
memberId : steamID . getSteamID64 ( ) ,
queryString : ''
2015-08-05 11:37:16 +08:00
}
2019-09-24 16:38:27 +08:00
} , ( err , response , body ) => {
if ( ! callback ) {
2015-08-05 11:37:16 +08:00
return ;
}
2016-03-05 12:59:49 +08:00
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 11:37:16 +08:00
} ;
2015-08-05 12:13:32 +08:00
SteamCommunity . prototype . getGroupHistory = function ( gid , page , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2015-08-05 12:13:32 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
if ( typeof page == 'function' ) {
2015-08-05 12:13:32 +08:00
callback = page ;
page = 1 ;
}
2021-07-22 16:22:29 +08:00
this . httpRequest ( ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /history?p= ${ page } ` , ( err , response , body ) => {
2016-03-05 12:59:49 +08:00
if ( err ) {
callback ( err ) ;
2015-08-05 12:13:32 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
let $ = Cheerio . load ( body ) ;
let output = { } ;
2015-08-05 12:13:32 +08:00
2019-09-24 16:38:27 +08:00
let paging = $ ( '.group_paging p' ) . text ( ) ;
let match = paging . match ( /(\d+) - (\d+) of (\d+)/ ) ;
2015-08-05 12:13:32 +08:00
2019-09-24 16:38:27 +08:00
if ( match ) {
2015-08-05 12:13:32 +08:00
output . first = parseInt ( match [ 1 ] , 10 ) ;
output . last = parseInt ( match [ 2 ] , 10 ) ;
output . total = parseInt ( match [ 3 ] , 10 ) ;
}
output . items = [ ] ;
2019-09-24 16:38:27 +08:00
let currentYear = ( new Date ( ) ) . getFullYear ( ) ;
let lastDate = Date . now ( ) ;
2015-08-05 12:13:32 +08:00
2019-09-24 16:38:27 +08:00
Array . prototype . forEach . call ( $ ( '.historyItem, .historyItemb' ) , ( item ) => {
let data = { } ;
2015-08-05 12:13:32 +08:00
2019-09-24 16:38:27 +08:00
let $item = $ ( item ) ;
2015-08-05 12:13:32 +08:00
data . type = $item . find ( '.historyShort' ) . text ( ) . replace ( / /g , '' ) ;
2019-09-24 16:38:27 +08:00
let users = $item . find ( '.whiteLink[data-miniprofile]' ) ;
let sid ;
if ( users [ 0 ] ) {
2015-08-05 12:13:32 +08:00
sid = new SteamID ( ) ;
sid . universe = SteamID . Universe . PUBLIC ;
sid . type = SteamID . Type . INDIVIDUAL ;
sid . instance = SteamID . Instance . DESKTOP ;
sid . accountid = $ ( users [ 0 ] ) . data ( 'miniprofile' ) ;
data . user = sid ;
}
2019-09-24 16:38:27 +08:00
if ( users [ 1 ] ) {
2015-08-05 12:13:32 +08:00
sid = new SteamID ( ) ;
sid . universe = SteamID . Universe . PUBLIC ;
sid . type = SteamID . Type . INDIVIDUAL ;
sid . instance = SteamID . Instance . DESKTOP ;
2017-08-09 02:52:12 +08:00
sid . accountid = $ ( users [ 1 ] ) . data ( 'miniprofile' ) ;
2015-08-05 12:13:32 +08:00
data . actor = sid ;
}
// Figure out the date. Of course there's no year, because Valve
2019-09-24 16:38:27 +08:00
let dateParts = $item . find ( '.historyDate' ) . text ( ) . split ( '@' ) ;
let date = dateParts [ 0 ] . trim ( ) . replace ( /(st|nd|th)$/ , '' ) . trim ( ) + ', ' + currentYear ;
let time = dateParts [ 1 ] . trim ( ) . replace ( /(am|pm)/ , ' $1' ) ;
2015-08-05 12:13:32 +08:00
2015-08-07 12:28:24 +08:00
date = new Date ( date + ' ' + time + ' UTC' ) ;
2015-08-05 12:13:32 +08:00
// If this date is in the future, or it's later than the previous one, decrement the year
2019-09-24 16:38:27 +08:00
if ( date . getTime ( ) > lastDate ) {
2015-08-05 12:13:32 +08:00
date . setFullYear ( date . getFullYear ( ) - 1 ) ;
}
data . date = date ;
output . items . push ( data ) ;
} ) ;
callback ( null , output ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2015-08-05 12:13:32 +08:00
} ;
2017-08-07 07:08:45 +08:00
2017-01-31 18:45:36 +08:00
SteamCommunity . prototype . getAllGroupComments = function ( gid , from , count , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2017-12-27 05:32:21 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
let options = {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/comment/Clan/render/ ${ gid . getSteamID64 ( ) } /-1/ ` ,
2021-07-22 16:22:29 +08:00
form : {
start : from ,
count
2017-02-08 04:35:29 +08:00
}
2017-02-02 00:27:58 +08:00
} ;
2017-01-31 18:45:36 +08:00
2019-09-24 16:38:27 +08:00
this . httpRequestPost ( options , ( err , response , body ) => {
2017-01-31 18:45:36 +08:00
if ( err ) {
callback ( err ) ;
return ;
}
2019-09-24 16:38:27 +08:00
let comments = [ ] ;
2017-01-31 18:45:36 +08:00
2019-09-24 16:38:27 +08:00
let $ = Cheerio . load ( JSON . parse ( body ) . comments _html ) ;
2017-01-31 18:45:36 +08:00
2021-07-30 12:39:46 +08:00
$ ( '.commentthread_comment_content' ) . each ( ( i , element ) => {
2019-09-24 16:38:27 +08:00
let comment = { } ;
2017-01-31 18:45:36 +08:00
2021-07-30 12:39:46 +08:00
let $element = $ ( element ) ;
let $selector = $ ( $element . find ( '.commentthread_author_link' ) ) ;
comment . authorName = $selector . find ( 'bdi' ) . text ( ) ;
comment . authorId = $selector . attr ( 'href' ) . replace ( /https?:\/\/steamcommunity.com\/(id|profiles)\// , '' ) ;
2021-07-22 16:22:29 +08:00
comment . date = Helpers . decodeSteamTime ( $ ( this ) . find ( '.commentthread_comment_timestamp' ) . text ( ) . trim ( ) ) ;
2017-01-31 18:45:36 +08:00
2021-07-30 12:39:46 +08:00
$selector = $ ( $element . find ( '.commentthread_comment_text' ) ) ;
comment . commentId = $selector . attr ( 'id' ) . replace ( 'comment_content_' , '' ) ;
comment . text = $selector . html ( ) . trim ( ) ;
2017-01-31 18:45:36 +08:00
comments . push ( comment ) ;
} ) ;
callback ( null , comments ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-02-09 01:30:47 +08:00
} ;
SteamCommunity . prototype . deleteGroupComment = function ( gid , cid , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2017-12-27 05:32:21 +08:00
gid = new SteamID ( gid ) ;
}
2017-03-16 01:08:22 +08:00
2019-09-24 16:38:27 +08:00
if ( typeof cid != 'string' ) {
2017-03-16 00:55:48 +08:00
cid = cid . toString ( ) ;
2017-02-09 01:30:47 +08:00
}
2019-09-24 16:38:27 +08:00
let options = {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/comment/Clan/delete/ ${ gid . getSteamID64 ( ) } /-1/ ` ,
2021-07-22 16:22:29 +08:00
form : {
sessionid : this . getSessionID ( ) ,
gidcomment : cid
2017-02-09 01:30:47 +08:00
}
} ;
2019-09-24 16:38:27 +08:00
this . httpRequestPost ( options , ( err , response , body ) => {
if ( ! callback ) {
2017-02-09 01:30:47 +08:00
return ;
}
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-08-21 08:13:41 +08:00
} ;
2018-10-20 14:29:52 +08:00
SteamCommunity . prototype . postGroupComment = function ( gid , message , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2018-10-20 14:29:52 +08:00
gid = new SteamID ( gid ) ;
}
2019-09-24 16:38:27 +08:00
let options = {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/comment/Clan/post/ ${ gid . getSteamID64 ( ) } /-1/ ` ,
2021-07-22 16:22:29 +08:00
form : {
comment : message ,
count : 6 ,
sessionid : this . getSessionID ( )
2018-10-20 14:29:52 +08:00
}
} ;
2019-09-24 16:38:27 +08:00
this . httpRequestPost ( options , ( err , response , body ) => {
if ( ! callback ) {
2018-10-20 14:29:52 +08:00
return ;
}
callback ( err || null ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2018-10-20 14:29:52 +08:00
} ;
2017-08-07 07:08:45 +08:00
/ * *
* Get requests to join a restricted group .
* @ param { SteamID | string } gid - The SteamID of the group you want to manage
* @ param { function } callback - First argument is null / Error , second is array of SteamID objects
* /
SteamCommunity . prototype . getGroupJoinRequests = function ( gid , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2017-08-07 07:08:45 +08:00
gid = new SteamID ( gid ) ;
}
2021-07-22 16:22:29 +08:00
this . httpRequestGet ( ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /joinRequestsManage ` , ( err , res , body ) => {
2017-08-07 07:08:45 +08:00
if ( ! body ) {
2021-07-22 16:22:29 +08:00
callback ( new Error ( 'Malformed response' ) ) ;
2017-08-07 07:08:45 +08:00
return ;
}
2019-09-24 16:38:27 +08:00
let matches = body . match ( /JoinRequests_ApproveDenyUser\(\W*['"](\d+)['"],\W0\W\)/g ) ;
2017-08-07 07:08:45 +08:00
if ( ! matches ) {
// no pending requests
callback ( null , [ ] ) ;
return ;
}
2019-09-24 16:38:27 +08:00
let requests = [ ] ;
for ( let i = 0 ; i < matches . length ; i ++ ) {
2021-07-22 16:22:29 +08:00
requests . push ( new SteamID ( '[U:1:' + matches [ i ] . match ( /JoinRequests_ApproveDenyUser\(\W*['"](\d+)['"],\W0\W\)/ ) [ 1 ] + ']' ) ) ;
2017-08-07 07:08:45 +08:00
}
callback ( null , requests ) ;
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-08-07 07:08:45 +08:00
} ;
/ * *
* Respond to one or more join requests to a restricted group .
* @ param { SteamID | string } gid - The SteamID of the group you want to manage
* @ param { SteamID | string | SteamID [ ] | string [ ] } steamIDs - The SteamIDs of the users you want to approve or deny membership for ( or a single value )
* @ param { boolean } approve - True to put them in the group , false to deny their membership
* @ param { function } callback - Takes only an Error object / null as the first argument
* /
SteamCommunity . prototype . respondToGroupJoinRequests = function ( gid , steamIDs , approve , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2017-08-07 07:08:45 +08:00
gid = new SteamID ( gid ) ;
}
2019-02-14 13:29:21 +08:00
2019-09-24 16:38:27 +08:00
let rgAccounts = ( ! Array . isArray ( steamIDs ) ? [ steamIDs ] : steamIDs ) . map ( sid => sid . toString ( ) ) ;
2017-08-07 07:08:45 +08:00
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /joinRequestsManage ` ,
2021-07-22 16:22:29 +08:00
form : {
rgAccounts : rgAccounts ,
bapprove : approve ? '1' : '0' ,
json : '1' ,
sessionID : this . getSessionID ( )
2017-08-07 07:08:45 +08:00
} ,
2021-07-22 16:22:29 +08:00
json : true
2017-08-07 07:08:45 +08:00
} , ( err , res , body ) => {
if ( ! callback ) {
return ;
}
if ( body != EResult . OK ) {
2021-07-22 16:22:29 +08:00
let err = new Error ( EResult [ body ] || ` Error ${ body } ` ) ;
2017-08-07 07:08:45 +08:00
err . eresult = body ;
callback ( err ) ;
} else {
callback ( null ) ;
}
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-08-07 07:08:45 +08:00
} ;
/ * *
* Respond to * ALL * pending group - join requests for a particular group .
* @ param { SteamID | string } gid - The SteamID of the group you want to manage
* @ param { boolean } approve - True to allow everyone who requested into the group , false to not
* @ param { function } callback - Takes only an Error object / null as the first argument
* /
SteamCommunity . prototype . respondToAllGroupJoinRequests = function ( gid , approve , callback ) {
2019-09-24 16:38:27 +08:00
if ( typeof gid == 'string' ) {
2017-08-07 07:08:45 +08:00
gid = new SteamID ( gid ) ;
}
this . httpRequestPost ( {
2023-06-27 16:31:25 +08:00
url : ` https://steamcommunity.com/gid/ ${ gid . getSteamID64 ( ) } /joinRequestsManage ` ,
2021-07-22 16:22:29 +08:00
form : {
bapprove : approve ? '1' : '0' ,
json : '1' ,
action : 'bulkrespond' ,
sessionID : this . getSessionID ( )
2017-08-07 07:08:45 +08:00
} ,
2021-07-22 16:22:29 +08:00
json : true
2017-08-07 07:08:45 +08:00
} , ( err , res , body ) => {
if ( ! callback ) {
return ;
}
if ( body != EResult . OK ) {
2021-07-22 16:22:29 +08:00
let err = new Error ( EResult [ body ] || ` Error ${ body } ` ) ;
2017-08-07 07:08:45 +08:00
err . eresult = body ;
callback ( err ) ;
} else {
callback ( null ) ;
}
2019-09-24 16:38:27 +08:00
} , 'steamcommunity' ) ;
2017-08-07 07:08:45 +08:00
} ;