我正在尝试弄清楚如何自动接受好友请求,因为我真的很无聊我一直在我已经开始使用的机器人上到处做一些事情。

这是两个有用的链接:
https://github.com/seishun/node-steam/blob/master/README.md#relationships
https://github.com/seishun/node-steam/blob/master/README.md#friends

所以我一直在试图弄清楚如何通过使用这些来让它自动接受好友请求。

目前有一个待处理的好友请求,我很好奇如何让它自动接受它,甚至打印出当前的好友请求。

这是我的“ friend ”事件,您可以阅读有关 @ node-steam 自述文件的内容。

在“ friend ”事件下,它说如下:

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.

我很好奇我将如何访问这两个属性?对不起,如果这是一个愚蠢的问题。
提前谢谢了,我还在学习中。 :3

我已经确定我做错了,但我已经坐在这里很长一段时间了,并试图弄清楚,但我做不到。如果有多个好友请求,我的“好友”事件将不起作用,因为它需要通过所有现有的,但我仍然不确定我将如何做。
编辑;我刚试过这个:

它目前至少有一个好友请求,但它没有对此使用react,所以我认为“好友”事件是错误的?

编辑 2;我需要使用“关系”事件,而不是“ friend ”。现在我只需要弄清楚如何查看所有当前的好友请求。

我还发现了这个枚举:
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,
};

我不确定的是我将如何处理所有现有的 friend 邀请。
使用:
console.log(Steam.EFriendRelationship.PendingInvitee);

返回 '​​2',因为这是枚举的值。我将如何列出所有待处理的邀请?

最佳答案

回答你的第一个问题...

我今天实际上一直在用这个写一个机器人并遇到了这个问题。
这是我如何做到的:

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");
    }
});

这是不言自明的,但它会在收到好友请求时打印“收到好友请求”,添加好友,然后打印好友已添加。

编辑:

以下是添加机器人离线时发送的好友请求的方法;
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");
};

如果我是对的,这就是你要找的? :)

重要提示:调用 addPendingFriends();在 webLogOn() 之后,似乎 steam.friends 没有在登录时启动。

关于javascript - NodeJS - Steam API - 自动接受好友请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21804774/

10-10 00:46