Jump to content


Photo
Question

Accepting friends request if member of group.

node.js node-steam-user

  • Please log in to reply
8 replies to this topic

#1 Seeringfate

Seeringfate

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 28 May 2017 - 03:19 PM

Hi there,

 

I'm trying to get my bot to accept friends request from members from my group.

My code is not fully working, it keep getting errors at "community.groups(steamid).

 

Here is my code:

client.on("friendRelationship", (steamid, reletionship, name) => {
	if (reletionship === 2) {
		var userGroups = community.groups(steamid)
		if (userGroups.indexOf(wantedGroupID) != -1) {
		client.addFriend(steamid);
		client.chatMessage(steamid, `Thank you for adding me!`);
		console.log(`Friends request from ${name} accepted, IdleNet member. SteamID:  ${steamid}`);
	} else {
		client.removeFriend(steamid);
		console.log(`Ignored friends request from ${name}, not in the IdleNet group. SteamID: ${steamid}`);
	}
	}
		
});

This is before my code:

const SteamUser = require('steam-user');
const SteamTotp = require("steam-totp");
const SteamCommunity = require("steamcommunity");
const TradeOfferManager = require("steam-tradeoffer-manager");

var wantedGroupID = 'groupid';

const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager({
	steam: client,
	community: community,
	language: "en"
});
const logOnOptions = {
	accountName: 'name',
	password: 'pass',
	twoFactorCode: SteamTotp.generateAuthCode("secret")
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
	console.log('Logged into Steam');
	
	client.setPersona(SteamUser.Steam.EPersonaState.Online)
	client.gamesPlayed("Testing");
});
client.on("webSession", (sessionid, cookies) => {
	manager.setCookies(cookies);
	community.setCookies(cookies);
	community.startConfirmationChecker(10000, "secret");
});

Could someone help me ?

 

Thanks !



#2 SunriseM

SunriseM

    Advanced Member

  • Member
  • PipPipPip
  • 46 posts
  • LocationVenezuela

Posted 29 May 2017 - 06:25 PM

Where did you get community.groups from? i haven't heard of it. 

 

You should use community.getGroupMembers() method. 

community.getGroupMembers("groupid", function(err, members) {
    //Check if steamid is included in members array
});


#3 Seeringfate

Seeringfate

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 30 May 2017 - 09:40 AM

 

Where did you get community.groups from? i haven't heard of it. 

 

You should use community.getGroupMembers() method. 

community.getGroupMembers("groupid", function(err, members) {
    //Check if steamid is included in members array
});

This worked, this only created a new problem:

the getGroupMembers has a Steam3ID output while my code works with SteamID64.

So I can get the array and find my string there, but how do I convert the Steam3ID to a SteamID64 ?

 

My code now:

// Accepting friends requests.
client.on("friendRelationship", (steamid, reletionship) => {
	if (reletionship === 2) {
		community.getGroupMembers('GROUPID', function(err, members) {
		if (members.indexOf(steamid) > -1) {
		client.addFriend(steamid);
		client.chatMessage(steamid, `Thank you for adding me!`);
		console.log(`Friends request accepted, is group member. SteamID:  ${steamid}`);
		} else if (err){
			console.log(err);
	} else {
		client.removeFriend(steamid);
		console.log(`Ignored friends request, not in the group. SteamID: ${steamid}`);
	}
	});
	}	
});

Thanks !


Edited by Seeringfate, 30 May 2017 - 09:41 AM.


#4 Seeringfate

Seeringfate

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 02 June 2017 - 10:48 AM

I fixed it, for people who have the same issue, here is what I did:

first I created a new array containing all accountid's from the group members:

const groupMembers = [];
community.getGroupMembers('GROUPID', function(err, members) {
	for(x = 0; x < members.length; x++) {
		groupMembers.push(members[x].accountid);		
	}
});

after that I compared it to the acountID from the getGroupMembers function:

client.on("friendRelationship", (steamid, reletionship, name) => {
	if (reletionship === 2) {
		community.getGroupMembers('GROUPID', function(err, members) {
		if (groupMembers.indexOf(steamid.accountid) > -1) {
		client.addFriend(steamid);
		client.chatMessage(steamid, `Thank you for adding me!`);
		console.log(`Friends request accepted, member. SteamID:  ${steamid}`);
		} else if (err){
			console.log(err);
	} else {
		client.removeFriend(steamid);
		console.log(`Ignored friends request, not in the group. SteamID: ${steamid}`);
	}
	});
	}	
});

:)


Edited by Seeringfate, 02 June 2017 - 10:49 AM.


#5 1Life1Chance

1Life1Chance

    Member

  • Member
  • PipPip
  • 18 posts

Posted 26 March 2018 - 01:24 PM

This way have a some problems like sometime didn't get members list or update members list



#6 1Life1Chance

1Life1Chance

    Member

  • Member
  • PipPip
  • 18 posts

Posted 31 March 2018 - 02:49 PM

Hey! Anyone know how i can clear getGroupMembers cache ? I need this becase when i launch first time function it get members but after didn't get new members.



#7 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 36 posts

Posted 10 September 2018 - 01:56 PM

I have same problem, my bot checking if user is in group with every trade, but list doesnt refresh :/



#8 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,810 posts

Posted 10 September 2018 - 03:10 PM

I have same problem, my bot checking if user is in group with every trade, but list doesnt refresh :/

 

You should use the WebAPI to check if a user is in a group.



#9 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 36 posts

Posted 10 September 2018 - 03:50 PM

ye but I guess user needs to have public/friends only profile, its easier to get group members and compare it with offer.partner, anyway this method 'getGroupMembers' depends of steam (they refreshing every 5-10 min group members - I tried to refresh .xml manually)







Also tagged with one or more of these keywords: Question, node.js, node-steam-user

2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users