简体   繁体   English

NodeJS - Steam API - 自动接受好友请求

[英]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#relationships
https://github.com/seishun/node-steam/blob/master/README.md#friends 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. 这是我关于@ node-steam自述文件的“朋友”活动,看起来像。

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 :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: 我刚试过这个:

第二张图片

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; 编辑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. 返回'2',因为这是枚举的值。 How would I get all pending invites listed up? 如何列出所有挂起的邀请?

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(); 重要说明:调用addPendingFriends(); after webLogOn(), it seems that steam.friends isn't initiated upon loggedOn. 在webLogOn()之后,似乎steam.friends不是在loggedOn上启动的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM