Jump to content
McKay Development

Recommended Posts

Posted

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 !

Posted

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
});
Posted (edited)

 

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
Posted (edited)

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
  • 9 months later...
  • 5 months later...
Posted

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)

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...