Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - Steam API - Auto accept friend requests

I'm trying to figure out how to automatically accept friend requests as I'm really bored I've been doing some stuff here and there on a bot I've started on.

Here's two useful links:
https://github.com/seishun/node-steam/blob/master/README.md#relationships
https://github.com/seishun/node-steam/blob/master/README.md#friends

So I've been trying to figure out how I would make it auto accept the friend requests by using those.

There's currently a pending friend request and I'm curious of how I would make it automatically accept it, or even print the current friend requests out.

Here's what my 'friend' event that you can read about @ node-steam's readme, looks like.

http://puu.sh/6XznQ.png

Under the 'friend' event it says the following:

The friends and groups properties now contain data (unless your friend/group list is empty). Listen for this if you want to accept/decline friend requests that came while you were offline, for example.

I'm curious how I would access those two properties? Sorry if this is a stupid question. Thanks in advance, I'm still learning. :3

I'm already sure I've done wrong but I've been sitting here for quite some time now and have tried to figure it out, but I can't. If there are more than one friend request, my 'friend' event wouldn't work as it would need to go through ALL existing ones, but I'm still unsure how I would do it. Edit; I just tried this:

second image

It currently have at least one friend request but it does not react on that, so I suppose the 'friend' event is wrong?

Edit 2; I needed to use 'relationships' event, not 'friends'. Now I just need to figure out how to see all the current friend requests.

I also found this enum:

Steam.EFriendRelationship = {
  None: 0,
  Blocked: 1,
  PendingInvitee: 2, // obsolete - renamed to RequestRecipient
  RequestRecipient: 2,
  Friend: 3,
  RequestInitiator: 4,
  PendingInviter: 4, // obsolete - renamed to RequestInitiator
  Ignored: 5,
  IgnoredFriend: 6,
  SuggestedFriend: 7,
  Max: 8,
};

What I'm not sure is how I would go through all the existing friend invites. Using:

console.log(Steam.EFriendRelationship.PendingInvitee);

returns '2', since that's the value of the enum. How would I get all pending invites listed up?

like image 508
prk Avatar asked Jan 11 '23 04:01

prk


1 Answers

To answer your first question...

I've actually been writing a bot with this today and came across the problem. Here's how i did it:

var Steam = require("steam");
var steam = new Steam.SteamClient()

steam.on("friend", function(steamID, relationship) {
    if (relationship == Steam.EFriendRelationship.PendingInvitee) {
        console.log("friend request received");
        steam.addFriend(steamID);
        console.log("friend request accepted");
    }
});

This is quite self-explanatory but it prints "friend request received" upon receiving a friend request, add's the friend, then prints that the friend was added.

Edit:

Here's how to add friend requests that were sent while the bot was offline;

var _ = require("underscore");

var addPendingFriends = function() {
    console.log("searching for pending friend requests...");
    _.each(steam.friends, function(relationship, steamID) {
        if (relationship == Steam.EFriendRelationship.RequestRecipient) {
            steam.addFriend(steamID);
            console.log(steamID+" was added as a friend");
        }
    });
    console.log("finished searching");
};

If I'm right, this is what you were looking for? :)

Important note: call addPendingFriends(); after webLogOn(), it seems that steam.friends isn't initiated upon loggedOn.

like image 194
nef Avatar answered Jan 15 '23 13:01

nef